From 1dc7894365732084a6e106763e97811c7a55c8c8 Mon Sep 17 00:00:00 2001 From: Sean Kennedy Date: Fri, 20 Nov 2015 15:09:44 -0500 Subject: [PATCH] consistent handling of dev tasks so that clean and copy actions don't bother each other --- gulpfile.js | 74 +++++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 9387a255..9591d3c0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -13,9 +13,10 @@ var declare = require('gulp-declare'); var watch = require('gulp-watch'); var connect = require('gulp-connect'); var header = require('gulp-header'); -var pkg = require('./package.json'); var order = require('gulp-order'); var jshint = require('gulp-jshint'); +var pkg = require('./package.json'); + var banner = ['/**', ' * <%= pkg.name %> - <%= pkg.description %>', ' * @version v<%= pkg.version %>', @@ -34,21 +35,6 @@ gulp.task('clean', function() { .on('error', log); }); -/** - * Processes Handlebars templates - */ -function templates() { - return gulp - .src(['./src/main/template/**/*']) - .pipe(handlebars()) - .pipe(wrap('Handlebars.template(<%= contents %>)')) - .pipe(declare({ - namespace: 'Handlebars.templates', - noRedeclare: true, // Avoid duplicate declarations - })) - .on('error', log); -} - /** * JShint all *.js files */ @@ -62,15 +48,21 @@ gulp.task('lint', function () { * Build a distribution */ gulp.task('dist', ['clean', 'lint'], _dist); -gulp.task('dev-dist', ['lint', 'copy'], _dist); - function _dist() { return es.merge( gulp.src([ './src/main/javascript/**/*.js', './node_modules/swagger-client/browser/swagger-client.js' ]), - templates() + gulp + .src(['./src/main/template/**/*']) + .pipe(handlebars()) + .pipe(wrap('Handlebars.template(<%= contents %>)')) + .pipe(declare({ + namespace: 'Handlebars.templates', + noRedeclare: true, // Avoid duplicate declarations + })) + .on('error', log) ) .pipe(order(['scripts.js', 'templates.js'])) .pipe(concat('swagger-ui.js')) @@ -84,12 +76,13 @@ function _dist() { .pipe(gulp.dest('./dist')) .pipe(connect.reload()); } +gulp.task('dev-dist', ['lint', 'dev-copy'], _dist); /** * Processes less files into CSS files */ -gulp.task('less', ['clean'], function() { - +gulp.task('less', ['clean'], _less); +function _less() { return gulp .src([ './src/main/less/screen.less', @@ -101,14 +94,14 @@ gulp.task('less', ['clean'], function() { .on('error', log) .pipe(gulp.dest('./src/main/html/css/')) .pipe(connect.reload()); -}); - +} +gulp.task('dev-less', _less); /** * Copy lib and html folders */ -gulp.task('copy', ['less'], function() { - +gulp.task('copy', ['less'], _copy); +function _copy() { // copy JavaScript files inside lib folder gulp .src(['./lib/**/*.{js,map}']) @@ -126,21 +119,29 @@ gulp.task('copy', ['less'], function() { .src(['./src/main/html/**/*']) .pipe(gulp.dest('./dist')) .on('error', log); +} +gulp.task('dev-copy', ['dev-less', 'copy-local-specs'], _copy); - // copy the test specs - gulp - .src(['./test/specs/**/*']) - .pipe(gulp.dest('./dist/specs')) - .on('error', log); +gulp.task('copy-local-specs', function () { + // copy the test specs + return gulp + .src(['./test/specs/**/*']) + .pipe(gulp.dest('./dist/specs')) + .on('error', log); }); /** * Watch for changes and recompile */ -gulp.task('watch', function() { - return watch(['./src/**/*.{js,less,handlebars}', './test/specs/**/*.{json,yaml}'], function() { - gulp.start('dev-dist'); - }); +gulp.task('watch', ['copy-local-specs'], function() { + return watch([ + './src/**/*.{js,less,handlebars}', + './src/main/html/*.html', + './test/specs/**/*.{json,yaml}' + ], + function() { + gulp.start('dev-dist'); + }); }); /** @@ -157,7 +158,8 @@ function log(error) { console.error(error.toString && error.toString()); } - gulp.task('default', ['dist', 'copy']); gulp.task('serve', ['connect', 'watch']); -gulp.task('dev', ['default', 'serve']); +gulp.task('dev', ['default'], function () { + gulp.start('serve'); +});