From 3665175c8bf20bedd27f423b1331e1e73480a97c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Schr=C3=B6der?= Date: Fri, 22 May 2015 14:03:03 +0200 Subject: [PATCH] Improved compilation --- luciexpress/Gruntfile.js | 74 +++++++++++++++++++++++++++++++++++ luciexpress/compile.sh | 10 +++-- luciexpress/htdocs/index.html | 6 +-- luciexpress/htdocs/js/app.js | 27 +++++++++++-- 4 files changed, 107 insertions(+), 10 deletions(-) diff --git a/luciexpress/Gruntfile.js b/luciexpress/Gruntfile.js index a1979120a..95db80927 100644 --- a/luciexpress/Gruntfile.js +++ b/luciexpress/Gruntfile.js @@ -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 "' >> htdocs/__all.html; +done; +*/ diff --git a/luciexpress/compile.sh b/luciexpress/compile.sh index 2a91dbb6e..3783532f0 100644 --- a/luciexpress/compile.sh +++ b/luciexpress/compile.sh @@ -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; diff --git a/luciexpress/htdocs/index.html b/luciexpress/htdocs/index.html index a2edb925b..4c3ee6809 100644 --- a/luciexpress/htdocs/index.html +++ b/luciexpress/htdocs/index.html @@ -22,8 +22,8 @@
- - + + diff --git a/luciexpress/htdocs/js/app.js b/luciexpress/htdocs/js/app.js index 5242a0b13..4b25f5574 100644 --- a/luciexpress/htdocs/js/app.js +++ b/luciexpress/htdocs/js/app.js @@ -1,7 +1,7 @@ //! Author: Martin K. Schröder // 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){