From 449a3648260ff0ac832a76667cd8476095660e04 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Thu, 20 Aug 2015 04:41:31 +0200 Subject: [PATCH] showcase: build application, gulp task --- angularjs/showcase/gulp.config.js | 16 ++++++--- angularjs/showcase/gulpfile.js | 71 +++++++++++++++++++++++++++++++++++++-- angularjs/showcase/package.json | 15 ++++++++- 3 files changed, 94 insertions(+), 8 deletions(-) diff --git a/angularjs/showcase/gulp.config.js b/angularjs/showcase/gulp.config.js index e851048..8d237ee 100644 --- a/angularjs/showcase/gulp.config.js +++ b/angularjs/showcase/gulp.config.js @@ -17,10 +17,6 @@ module.exports = function() { app + '**/*.js', '!' + app + '**/*.spec.js' ], - jsFilesWithSpecs: [ - app + '**/*.module.js', - app + '**/*.js' - ], jsFilesStubs: [ main + 'stubs/**/*.js' ], @@ -28,7 +24,17 @@ module.exports = function() { jshintConfigurationFile: '.jshintrc', jscsConfigurationFile: '.jscsrc', - karmaConf: 'karma.conf.js' + karmaConf: 'karma.conf.js', + + /** + * build files + */ + build: { + app: 'app.js', + lib: 'lib.js', + directory: './dist/', + } + }; config.getWiredepOptions = function() { diff --git a/angularjs/showcase/gulpfile.js b/angularjs/showcase/gulpfile.js index 1a2f903..0db7134 100644 --- a/angularjs/showcase/gulpfile.js +++ b/angularjs/showcase/gulpfile.js @@ -67,7 +67,6 @@ gulp.task('wiredepkarma', function() { log('Wiring bower dependencies into karma.conf.js'); var wiredep = require('wiredep').stream; - var jsFiles = args.stubs ? [].concat(config.jsFilesWithoutSpecs, config.jsFilesStubs) : config.jsFilesWithoutSpecs; return gulp.src(config.karmaConf) .pipe(wiredep(config.getWiredepKarmaOptions())) @@ -106,11 +105,79 @@ gulp.task('autotest', ['wiredepkarma'], function(done) { }); /** + * Builds application. + * + * @returns {stream} The stream. + */ +gulp.task('build', ['wiredep', 'test'], function() { + log('Building application.'); + + var assets = plugins.useref.assets({searchPath: './'}); + // Filters are named for the gulp-useref path + var cssFilter = plugins.filter('**/*.css'); + var jsAppFilter = plugins.filter('**/' + config.build.app); + var jslibFilter = plugins.filter('**/' + config.build.lib); + + return gulp.src(config.index) + // Gather all assets from the html with useref + .pipe(assets) + // Get the css + .pipe(cssFilter) + .pipe(plugins.minifyCss()) + .pipe(cssFilter.restore()) + // Get the custom javascript + .pipe(jsAppFilter) + .pipe(plugins.ngAnnotate({add: true})) + .pipe(plugins.uglify({ + compress: { + //jscs:disable + drop_console: true, // jshint ignore:line + drop_debugger: true // jshint ignore:line + //jscs:enable + } + })) + .pipe(getHeader()) + .pipe(jsAppFilter.restore()) + // Get the vendor javascript + .pipe(jslibFilter) + .pipe(plugins.uglify()) + .pipe(jslibFilter.restore()) + // Take inventory of the file names for future rev numbers + .pipe(plugins.rev()) + // Apply the concat and file replacement with useref + .pipe(assets.restore()) + .pipe(plugins.useref()) + // Replace the file names in the html with rev numbers + .pipe(plugins.revReplace()) + .pipe(gulp.dest(config.build.directory)); + + /** + * Format and return the header for files + * + * @return {stream} The stream. + */ + function getHeader() { + var pkg = require('./package.json'); + var banner = ['/**', + ' * <%= pkg.name %> - <%= pkg.description %>', + ' * @authors <%= pkg.authors %>', + ' * @version v<%= pkg.version %>', + ' * @link <%= pkg.homepage %>', + ' * @license <%= pkg.license %>', + ' */', + '' + ].join('\n'); + return plugins.header(banner, {pkg: pkg}); + } + +}); + +/** * Inject files in a sorted sequence at a specified inject label. * * @param {Array} source Source files (glob patterns) * @param {string=} label The label name to be used by gulp-inject. - * @returns {Stream} The stream. + * @returns {stream} The stream. */ function inject(source, label) { var options = {relative: false}; diff --git a/angularjs/showcase/package.json b/angularjs/showcase/package.json index 9e922b0..433247d 100644 --- a/angularjs/showcase/package.json +++ b/angularjs/showcase/package.json @@ -2,20 +2,34 @@ "name": "showcase", "version": "0.0.1", "description": "My showcase module", + "author": { + "name": "Gustavo Martin Morcuende", + "email": "noemail@noemail.invalid", + "url": "http://gumartinm.name" + }, + "homepage": "http://gumartinm.name", + "license": "Apache License, Version 2.0", "devDependencies": { "express": "~4.13.3", "express-http-proxy": "~0.6.0", "gulp": "~3.9.0", "gulp-angular-filesort": "~1.1.1", + "gulp-filter": "~3.0.0", + "gulp-header": "~1.2.2", "gulp-if": "~1.2.5", "gulp-inject": "~1.5.0", "gulp-jscs": "~2.0.0", "gulp-jshint": "~1.11.2", "gulp-load-plugins": "~1.0.0-rc.1", + "gulp-minify-css": "~1.2.0", + "gulp-ng-annotate": "~1.1.0", "gulp-nodemon": "~2.0.3", "gulp-order": "~1.1.1", "gulp-print": "~1.1.0", + "gulp-rev": "~5.1.0", + "gulp-rev-replace": "~0.4.2", "gulp-task-listing": "~1.0.1", + "gulp-uglify": "~1.2.0", "gulp-useref": "~1.3.0", "gulp-util": "~3.0.6", "jshint-stylish": "~2.0.1", @@ -30,7 +44,6 @@ "yargs": "~3.19.0" }, "scripts": { - "pretest": "wiredep -s karma.conf.js --dependencies --devDependencies", "test": "gulp test", "postinstall": "bower install --force-latest" } -- 2.1.4