Improved compilation

This commit is contained in:
Martin Schröder 2015-05-22 14:03:03 +02:00 committed by Martin Schröder
parent 65eb4701ca
commit 3665175c8b
4 changed files with 107 additions and 10 deletions

View file

@ -94,7 +94,81 @@ module.exports = function(grunt){
else next();
});
console.log(files);
});
grunt.registerTask("compile", "Compile all files into a single file", function(){
var libfiles = [
"htdocs/lib/js/async.js",
"htdocs/lib/js/js-schema.min.js",
"htdocs/lib/js/require.js",
"htdocs/lib/js/jquery.min.js",
"htdocs/lib/js/angular.min.js",
"htdocs/lib/js/angular-ui.min.js",
"htdocs/lib/js/angular-ui-router.min.js",
"htdocs/lib/js/angular-gettext.min.js",
"htdocs/lib/js/bootstrap-select.min.js",
"htdocs/lib/js/select.min.js",
"htdocs/lib/js/angular-animate.min.js",
"htdocs/lib/js/angular-ui-bootstrap-luci.min.js",
"htdocs/lib/js/jquery-jsonrpc.js",
"htdocs/lib/js/translations.js",
"htdocs/lib/js/bootstrap.min.js",
"htdocs/lib/js/angular-ui-switch.min.js",
"htdocs/lib/js/angular-modal-service.min.js",
"htdocs/lib/js/angular-checklist-model.js"
];
var appfiles = [
"htdocs/js/rpc.js",
"htdocs/js/uci.js",
"htdocs/js/juci.js",
"htdocs/js/app.js",
"htdocs/js/localStorage.js",
"htdocs/js/config.js",
"htdocs/js/navigation.js",
"htdocs/js/status.js",
"htdocs/js/tr.js",
"htdocs/js/theme.js",
"htdocs/js/timeout.js"
];
var otherfiles = grunt.file.expand(["./htdocs/plugins/**/*.js", "./htdocs/themes/vodafone/**/*.js"]).filter(function(x){
return !x.match(/.*\/test-.*\.js/) && !x.match(/.*\.test\.js/);
});
var htmlfiles = grunt.file.expand(["htdocs/**/*.html"]);
var all = libfiles.concat(appfiles).concat(otherfiles);
var templates = {};
htmlfiles.map(function(name){
templates[name.replace("htdocs/", "")] = String(fs.readFileSync(name));
});
fs.writeFileSync("htdocs/__all.js", "var JUCI_COMPILED = 1; var JUCI_TEMPLATES = "+JSON.stringify(templates)+";"+all.map(function(name){ return fs.readFileSync(name); }).join("\n")); // REALLY?
//fs.writeFileSync("htdocs/__templates.js", JSON.stringify(templates));
});
grunt.registerTask('default', ['nggettext_extract', 'nggettext_compile', "extract_titles", "compile_pot"]);
}
/*
LIBFILES=(htdocs/lib/js/async.js htdocs/lib/js/js-schema.min.js htdocs/lib/js/require.js htdocs/lib/js/jquery.min.js htdocs/lib/js/angular.min.js htdocs/lib/js/angular-ui.min.js htdocs/lib/js/angular-ui-router.min.js htdocs/lib/js/angular-gettext.min.js htdocs/lib/js/bootstrap-select.min.js htdocs/lib/js/select.min.js htdocs/lib/js/angular-animate.min.js htdocs/lib/js/angular-ui-bootstrap-luci.min.js htdocs/lib/js/jquery-jsonrpc.js htdocs/lib/js/translations.js htdocs/lib/js/bootstrap.min.js htdocs/lib/js/angular-ui-switch.min.js htdocs/lib/js/angular-modal-service.min.js htdocs/lib/js/angular-checklist-model.js)
PLUGINFILES=$(find htdocs/plugins -type f -name "*js" | grep -v "test-" | grep -v ".test.js" | grep -v ".notest.js")
THEMEFILES=$(find htdocs/themes -type f -name "*js" | grep -v "test-" | grep -v ".test.js" | grep -v ".notest.js")
COREFILES=(htdocs/js/rpc.js htdocs/js/uci.js htdocs/js/juci.js htdocs/js/app.js htdocs/js/localStorage.js htdocs/js/config.js htdocs/js/navigation.js htdocs/js/status.js htdocs/js/session.js htdocs/js/tr.js htdocs/js/theme.js htdocs/js/timeout.js)
FILES=("${LIBFILES[@]}" "${COREFILES[@]}" "${PLUGINFILES[@]}" "${THEMEFILES[@]}");
echo "var JUCI_COMPILED = 1;" > htdocs/__all.js
for file in ${FILES[@]}; do
echo "FILE: $file";
echo ";" >> htdocs/__all.js;
cat $file >> htdocs/__all.js;
done;
HTMLFILES=$(find htdocs -type f -name "*html"|grep -v "index.html" | grep -v "__all.html")
echo "" > htdocs/__all.html
for file in ${HTMLFILES[@]}; do
file=$(echo $file | sed 's/htdocs\///gi')
echo "HTML: $file";
echo "<script type='text/ng-template' id='/$file'>" >> htdocs/__all.html;
cat htdocs/$file >> htdocs/__all.html;
echo '</script>' >> htdocs/__all.html;
done;
*/

View file

@ -1,12 +1,16 @@
LIBFILES=(htdocs/lib/js/async.js htdocs/lib/js/js-schema.min.js htdocs/lib/js/require.js htdocs/lib/js/jquery.min.js htdocs/lib/js/angular.min.js htdocs/lib/js/angular-ui.min.js htdocs/lib/js/angular-ui-router.min.js htdocs/lib/js/angular-gettext.min.js htdocs/lib/js/bootstrap-select.min.js htdocs/lib/js/select.min.js htdocs/lib/js/angular-animate.min.js htdocs/lib/js/angular-ui-bootstrap-luci.min.js htdocs/lib/js/jquery-jsonrpc.js htdocs/lib/js/translations.js htdocs/lib/js/bootstrap.min.js htdocs/lib/js/angular-ui-switch.min.js htdocs/lib/js/angular-modal-service.min.js htdocs/lib/js/angular-checklist-model.js)
PLUGINFILES=$(find htdocs/plugins -type f -name "*js" | grep -v "test-")
THEMEFILES=$(find htdocs/themes -type f -name "*js" | grep -v "test-")
PLUGINFILES=$(find htdocs/plugins -type f -name "*js" | grep -v "test-" | grep -v ".test.js" | grep -v ".notest.js")
THEMEFILES=$(find htdocs/themes -type f -name "*js" | grep -v "test-" | grep -v ".test.js" | grep -v ".notest.js")
COREFILES=(htdocs/js/rpc.js htdocs/js/uci.js htdocs/js/juci.js htdocs/js/app.js htdocs/js/localStorage.js htdocs/js/config.js htdocs/js/navigation.js htdocs/js/status.js htdocs/js/session.js htdocs/js/tr.js htdocs/js/theme.js htdocs/js/timeout.js)
FILES=("${LIBFILES[@]}" "${COREFILES[@]}" "${PLUGINFILES[@]}" "${THEMEFILES[@]}");
echo "var JUCI_COMPILED = 1;" > htdocs/__all.js
for file in ${FILES[@]}; do
echo "FILE: $file";
echo "\"$file\","
done;
for file in ${FILES[@]}; do
#echo "FILE: $file";
echo ";" >> htdocs/__all.js;
cat $file >> htdocs/__all.js;
done;

View file

@ -22,8 +22,8 @@
<div style="margin-bottom: 40px"></div>
<!--<script src="__all.js"></script>-->
<script src="lib/js/async.js"></script>
<script src="__all.js"></script>
<!--<script src="lib/js/async.js"></script>
<script src="lib/js/require.js"></script>
<script src="lib/js/jquery.min.js"></script>
<script src="lib/js/angular.min.js"></script>
@ -51,6 +51,6 @@
<script src="js/status.js"></script>
<script src="js/tr.js"></script>
<script src="js/theme.js"></script>
<script src="js/timeout.js"></script>
<script src="js/timeout.js"></script>-->
</body>
</html>

View file

@ -1,7 +1,7 @@
//! Author: Martin K. Schröder <mkschreder.uk@gmail.com>
// TODO: make this automatic
var JUCI_COMPILED = 0;
//var JUCI_COMPILED = 0;
$.jsonRPC.setup({
endPoint: '/ubus',
@ -41,7 +41,7 @@ Object.assign = Object.assign || function (target, source) {
return to;
};
JUCI.app.config(function ($stateProvider, $locationProvider, $compileProvider, $urlRouterProvider, $controllerProvider, $provide) {
JUCI.app.config(function ($stateProvider, $locationProvider, $compileProvider, $urlRouterProvider, $controllerProvider, $templateCacheProvider, $provide) {
console.log("CONF");
//$locationProvider.otherwise({ redirectTo: "/" });
$locationProvider.hashPrefix('!');
@ -91,12 +91,31 @@ JUCI.app.config(function ($stateProvider, $locationProvider, $compileProvider, $
}
},
});
$urlRouterProvider.otherwise("404");
})
.run(function($rootScope, $state, gettextCatalog, $tr, gettext, $rpc, $config, $location, $navigation){
.run(function($templateCache){
var _get = $templateCache.get;
var _put = $templateCache.put;
$templateCache.get = function(name){
name = name.replace(/\/\//g, "/").replace(/^\//, "");
//console.log("Get template '"+name+"'");
return _get.call($templateCache, name);
}
$templateCache.put = function(name, value){
name = name.replace(/\/\//g, "/").replace(/^\//, "");
//console.log("Put template '"+name+"'");
return _put.call($templateCache, name, value);
}
})
.run(function($rootScope, $state, gettextCatalog, $tr, gettext, $rpc, $config, $location, $navigation, $templateCache){
console.log("RUN");
if(JUCI_TEMPLATES !== undefined){
Object.keys(JUCI_TEMPLATES).map(function(x){
$templateCache.put(x, JUCI_TEMPLATES[x]);
});
}
// TODO: maybe use some other way to gather errors than root scope?
$rootScope.errors = [];
$rootScope.$on("error", function(ev, data){