diff options
| author | PliablePixels <pliablepixels@gmail.com> | 2015-06-26 20:25:01 -0400 |
|---|---|---|
| committer | PliablePixels <pliablepixels@gmail.com> | 2015-06-26 20:25:01 -0400 |
| commit | 2c837a6adbbdbb5f062e1ad86c98738084d31fb2 (patch) | |
| tree | 33e4c6292095ed61ba29791c15ab649f3b33699a | |
| parent | 544413f2d6de83e085d4489a1b9ccbaac3fa192d (diff) | |
Added uglify/minify as part of build process (Note: console log is enabled - remember to disable it in release mode)
| -rw-r--r-- | gulpfile.js | 18 | ||||
| -rwxr-xr-x | hooks/after_prepare/uglify.js | 92 | ||||
| -rwxr-xr-x | hooks/before_prepare/02_jshint.js | 73 | ||||
| -rw-r--r-- | ionic.project | 2 | ||||
| -rw-r--r-- | package.json | 1 | ||||
| -rw-r--r-- | www/index.html | 1 | ||||
| -rw-r--r-- | www/js/MonitorCtrl.js | 4 | ||||
| -rw-r--r-- | www/js/app.js | 1 | ||||
| -rw-r--r-- | www/templates/help.html | 8 |
9 files changed, 192 insertions, 8 deletions
diff --git a/gulpfile.js b/gulpfile.js index 3efdfc0a..3a2770d3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -6,9 +6,11 @@ var sass = require('gulp-sass'); var minifyCss = require('gulp-minify-css'); var rename = require('gulp-rename'); var sh = require('shelljs'); +var templateCache = require('gulp-angular-templatecache'); var paths = { - sass: ['./scss/**/*.scss'] + sass: ['./scss/**/*.scss'], +templatecache: ['./www/templates/**/*.html'] }; gulp.task('default', ['sass']); @@ -50,3 +52,17 @@ gulp.task('git-check', function(done) { } done(); }); + +gulp.task('templatecache', function (done) { + gulp.src('./www/templates/**/*.html') + .pipe(templateCache({standalone:true})) + .pipe(gulp.dest('./www/js')) + .on('end', done); + }); + + gulp.task('default', ['sass', 'templatecache']); + + gulp.task('watch', function() { + gulp.watch(paths.sass, ['sass']); + gulp.watch(paths.templatecache, ['templatecache']); + }); diff --git a/hooks/after_prepare/uglify.js b/hooks/after_prepare/uglify.js new file mode 100755 index 00000000..b90e285f --- /dev/null +++ b/hooks/after_prepare/uglify.js @@ -0,0 +1,92 @@ +#!/usr/bin/env node + +var fs = require('fs'); +var path = require('path'); +var UglifyJS = require('uglify-js'); +var CleanCSS = require('clean-css'); +var ngAnnotate = require('ng-annotate'); +var cssMinifier = new CleanCSS({ + noAdvanced: true, // disable advanced optimizations - selector & property merging, reduction, etc. + keepSpecialComments: 0 // remove all css comments ('*' to keep all, 1 to keep first comment only) +}); + +var rootDir = process.argv[2]; +var platformPath = path.join(rootDir, 'platforms'); +var platform = process.env.CORDOVA_PLATFORMS; +var cliCommand = process.env.CORDOVA_CMDLINE; + +// hook configuration +var isRelease = true; // by default this hook is always enabled, see the line below on how to execute it only for release +//var isRelease = (cliCommand.indexOf('--release') > -1); +var recursiveFolderSearch = true; // set this to false to manually indicate the folders to process +var foldersToProcess = [ // add other www folders in here if needed (ex. js/controllers) + 'js', + 'css' +]; + +if (!isRelease) { + return; +} + +console.log('cordova-uglify will always run by default, uncomment the line checking for the release flag otherwise'); + +switch (platform) { + case 'android': + platformPath = path.join(platformPath, platform, 'assets', 'www'); + break; + case 'ios': case 'browser': + platformPath = path.join(platformPath, platform, 'www'); + break; + default: + console.log('this hook only supports android, ios, and browser currently'); + return; +} + +foldersToProcess.forEach(function(folder) { + processFiles(path.join(platformPath, folder)); +}); + +function processFiles(dir) { + fs.readdir(dir, function (err, list) { + if (err) { + console.log('processFiles err: ' + err); + return; + } + list.forEach(function(file) { + file = path.join(dir, file); + fs.stat(file, function(err, stat) { + if (recursiveFolderSearch && stat.isDirectory()) { + processFiles(file); + } else{ + compress(file); + } + }); + }); + }); +} + +function compress(file) { + var ext = path.extname(file); + switch(ext) { + case '.js': + console.log('uglifying js file ' + file); + var res = ngAnnotate(String(fs.readFileSync(file)), { add: true }); + var result = UglifyJS.minify(res.src, { + compress: { // pass false here if you only want to minify (no obfuscate) + drop_console: false // remove console.* statements (log, warn, etc.) + }, + fromString: true + }); + fs.writeFileSync(file, result.code, 'utf8'); // overwrite the original unminified file + break; + case '.css': + console.log('minifying css file ' + file); + var source = fs.readFileSync(file, 'utf8'); + var result = cssMinifier.minify(source); + fs.writeFileSync(file, result, 'utf8'); // overwrite the original unminified file + break; + default: + console.log('encountered a ' + ext + ' file, not compressing it'); + break; + } +} diff --git a/hooks/before_prepare/02_jshint.js b/hooks/before_prepare/02_jshint.js new file mode 100755 index 00000000..fff7775d --- /dev/null +++ b/hooks/before_prepare/02_jshint.js @@ -0,0 +1,73 @@ +#!/usr/bin/env node + +var fs = require('fs'); +var path = require('path'); +var jshint = require('jshint').JSHINT; +var async = require('async'); + +var foldersToProcess = [ + 'js' +]; + +foldersToProcess.forEach(function(folder) { + processFiles("www/" + folder); +}); + +function processFiles(dir, callback) { + var errorCount = 0; + fs.readdir(dir, function(err, list) { + if (err) { + console.log('processFiles err: ' + err); + return; + } + async.eachSeries(list, function(file, innercallback) { + file = dir + '/' + file; + fs.stat(file, function(err, stat) { + if(!stat.isDirectory()) { + if(path.extname(file) === ".js") { + lintFile(file, function(hasError) { + if(hasError) { + errorCount++; + } + innercallback(); + }); + } else { + innercallback(); + } + } else { + innercallback(); + } + }); + }, function(error) { + if(errorCount > 0) { + process.exit(1); + } + }); + }); +} + +function lintFile(file, callback) { + console.log("Linting " + file); + fs.readFile(file, function(err, data) { + if(err) { + console.log('Error: ' + err); + return; + } + if(jshint(data.toString())) { + console.log('File ' + file + ' has no errors.'); + console.log('-----------------------------------------'); + callback(false); + } else { + console.log('Errors in file ' + file); + var out = jshint.data(), + errors = out.errors; + for(var j = 0; j < errors.length; j++) { + console.log(errors[j].line + ':' + errors[j].character + ' -> ' + errors[j].reason + ' -> ' + +errors[j].evidence); + } + console.log('-----------------------------------------'); + callback(true); + } + }); +} + diff --git a/ionic.project b/ionic.project index f6c258f8..3ee75daf 100644 --- a/ionic.project +++ b/ionic.project @@ -8,4 +8,4 @@ "version": "12.41.296.5" } ] -}
\ No newline at end of file +} diff --git a/package.json b/package.json index 5b886bb8..fbb50113 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ }, "devDependencies": { "bower": "^1.3.3", + "gulp-angular-templatecache": "^1.6.0", "gulp-util": "^2.2.14", "shelljs": "^0.3.0" }, diff --git a/www/index.html b/www/index.html index 1db134e8..65f0e1cd 100644 --- a/www/index.html +++ b/www/index.html @@ -35,6 +35,7 @@ <!-- your app's js --> + <script src="js/templates.js"></script> <script src="js/app.js"></script> <script src="js/controllers.js"></script> diff --git a/www/js/MonitorCtrl.js b/www/js/MonitorCtrl.js index 2ae91b69..ee9605fc 100644 --- a/www/js/MonitorCtrl.js +++ b/www/js/MonitorCtrl.js @@ -285,8 +285,8 @@ angular.module('zmApp.controllers').controller('zmApp.MonitorCtrl', ['$ionicPopu // The status is provided by zmdc.pl // "not running", "pending", "running since", "Unable to connect" - - for (var i = 0; i < $scope.monitors.length; i++) { + var i; + for ( i = 0; i < $scope.monitors.length; i++) { (function (j) { $scope.monitors[j].Monitor.isRunningText = "..."; $scope.monitors[j].Monitor.isRunning = "..."; diff --git a/www/js/app.js b/www/js/app.js index 4c157eda..ffff0c68 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -7,7 +7,6 @@ angular.module('zmApp', [ 'ionic', 'zmApp.controllers', - //'cordovaHTTP' ]) //------------------------------------------------------------------ diff --git a/www/templates/help.html b/www/templates/help.html index 011f577c..9a979d6b 100644 --- a/www/templates/help.html +++ b/www/templates/help.html @@ -8,13 +8,15 @@ <ion-content class="padding"> <div class="list"> + + <ion-item class="item-text-wrap"> <h2><b> What do I enter for ZM Portal URL, Base path to cgi-bin and ZM API URL?</b> </h2> <ul> - <li>ZM Portal URL: The URL using which you can access ZM (example http://myserver.ddns.net/zm)</li> - <li>CGI base path: The URL using which your cgi-bin directory is accessible (example http://myserver.ddns.net/). You don't have to enter cgi-bin explictly</li> - <li>API Url: The URL using which your API directory is accessible (example: http://myserver.ddns.net/zm/api)</li> + <li>- ZM Portal URL: The URL using which you can access ZM (example http://myserver.ddns.net/zm)</li> + <li>- CGI base path: The URL using which your cgi-bin directory is accessible (example http://myserver.ddns.net/). You don't have to enter cgi-bin explictly</li> + <li>- API Url: The URL using which your API directory is accessible (example: http://myserver.ddns.net/zm/api)</li> </ul> </ion-item> |
