From 28064ce621fe1847d6d06ea3c7b8b33f7fd93746 Mon Sep 17 00:00:00 2001 From: Alexander Deider Date: Tue, 17 May 2016 15:18:17 +0600 Subject: [PATCH 1/2] fix(gen): gulpfile.js generation fixes Fixes for a bunch of issues with gulpfile.js with @bumprat code https://github.com/yeoman/generator-angular/issues/1299 --- templates/common/root/_gulpfile.js | 102 +++++++++++++++++++---------- 1 file changed, 66 insertions(+), 36 deletions(-) diff --git a/templates/common/root/_gulpfile.js b/templates/common/root/_gulpfile.js index 8e6783ee9..68b7d11b0 100644 --- a/templates/common/root/_gulpfile.js +++ b/templates/common/root/_gulpfile.js @@ -11,28 +11,32 @@ var runSequence = require('run-sequence'); var yeoman = { app: require('./bower.json').appPath || 'app', - dist: 'dist' + dist: 'dist', + temp: '.tmp', + test: 'test' }; +var jsx = '<% if (coffee) { %>coffee<% } else { %>js<% } %>'; +var cssx = '<% if (sass) { %>scss<% } else { %>css<% } %>'; + var paths = { - scripts: [yeoman.app + '/scripts/**/*.<% if (coffee) { %>coffee<% } else { %>js<% } %>'], - styles: [yeoman.app + '/styles/**/*.<% if (sass) { %>scss<% } else { %>css<% } %>'], - test: ['test/spec/**/*.<% if (coffee) { %>coffee<% } else { %>js<% } %>'], + scripts: [yeoman.app + '/scripts/**/*.' + jsx], + styles: [yeoman.app + '/styles/**/*.' + cssx], + test: ['test/spec/**/*.' + jsx], testRequire: [ yeoman.app + '/bower_components/angular/angular.js', yeoman.app + '/bower_components/angular-mocks/angular-mocks.js', yeoman.app + '/bower_components/angular-resource/angular-resource.js', yeoman.app + '/bower_components/angular-cookies/angular-cookies.js', yeoman.app + '/bower_components/angular-sanitize/angular-sanitize.js', - yeoman.app + '/bower_components/angular-route/angular-route.js',<% if (coffee) { %> - 'test/mock/**/*.coffee', - 'test/spec/**/*.coffee'<% } else { %> - 'test/mock/**/*.js', - 'test/spec/**/*.js'<% } %> + yeoman.app + '/bower_components/angular-route/angular-route.js', + 'test/mock/**/*.' + jsx, + 'test/spec/**/*.' + jsx ], karma: 'karma.conf.js', views: { main: yeoman.app + '/index.html', + bowermain: yeoman.temp + '/index.html', files: [yeoman.app + '/views/**/*.html'] } }; @@ -44,7 +48,7 @@ var paths = { var lintScripts = lazypipe()<% if (coffee) { %> .pipe($.coffeelint) .pipe($.coffeelint.reporter);<% } else { %> - .pipe($.jshint, '.jshintrc') + .pipe($.jshint/*, '.jshintrc'*/) .pipe($.jshint.reporter, 'jshint-stylish');<% } %> var styles = lazypipe()<% if (sass) { %> @@ -52,13 +56,21 @@ var styles = lazypipe()<% if (sass) { %> outputStyle: 'expanded', precision: 10 })<% } %> - .pipe($.autoprefixer, 'last 1 version') - .pipe(gulp.dest, '.tmp/styles'); + .pipe($.autoprefixer, {browsers: ['last 2 version']}) + .pipe(gulp.dest, yeoman.temp + '/styles'); /////////// // Tasks // /////////// +// get arguments +var argv = {}; +process.argv.forEach(function(arg, index, all){ + if (arg[0] == '-' && (index + 1 < all.length)) { + argv[arg.substr(1)] = all[index+1]; + } +}); + gulp.task('styles', function () { return gulp.src(paths.styles) .pipe(styles()); @@ -68,7 +80,7 @@ gulp.task('coffee', function() { return gulp.src(paths.scripts) .pipe(lintScripts()) .pipe($.coffee({bare: true}).on('error', $.util.log)) - .pipe(gulp.dest('.tmp/scripts')); + .pipe(gulp.dest(yeoman.temp + '/scripts')); });<% } %> gulp.task('lint:scripts', function () { @@ -77,27 +89,29 @@ gulp.task('lint:scripts', function () { }); gulp.task('clean:tmp', function (cb) { - rimraf('./.tmp', cb); + rimraf(yeoman.temp, cb); }); -gulp.task('start:client', ['start:server', <% if (coffee) { %>'coffee', <% } %>'styles'], function () { +gulp.task('start:client', ['start:server', <% if (coffee) { %>'coffee', <% } else {%> 'lint:scripts', <%} %>'styles'], function () { openURL('http://localhost:9000'); }); gulp.task('start:server', function() { $.connect.server({ - root: [yeoman.app, '.tmp'], + root: [yeoman.app, yeoman.temp], livereload: true, // Change this to '0.0.0.0' to access the server from outside. - port: 9000 + port: 9000, + middleware: serveStaticBower }); }); gulp.task('start:server:test', function() { $.connect.server({ - root: ['test', yeoman.app, '.tmp'], + root: [yeoman.test, yeoman.app, yeoman.temp], livereload: true, - port: 9001 + port: 9001, + middleware: serveStaticBower }); }); @@ -113,30 +127,34 @@ gulp.task('watch', function () { $.watch(paths.scripts) .pipe($.plumber()) - .pipe(lintScripts())<% if (coffee) { %> + .pipe(lintScripts()) + <% if (coffee) { %> .pipe($.coffee({bare: true}).on('error', $.util.log)) - .pipe(gulp.dest('.tmp/scripts'))<% } %> + .pipe(gulp.dest(yeoman.temp + '/scripts')) + <% } %> .pipe($.connect.reload()); $.watch(paths.test) - .pipe($.plumber()) - .pipe(lintScripts()); + .pipe($.plumber()); gulp.watch('bower.json', ['bower']); }); gulp.task('serve', function (cb) { runSequence('clean:tmp', + ['bower'], ['lint:scripts'], ['start:client'], 'watch', cb); }); +// gulp serve:prod -port 8080 gulp.task('serve:prod', function() { $.connect.server({ root: [yeoman.dist], - livereload: true, - port: 9000 + livereload: true + port: argv.port || 80, + middleware: serveStaticBower }); }); @@ -153,10 +171,11 @@ gulp.task('test', ['start:server:test'], function () { gulp.task('bower', function () { return gulp.src(paths.views.main) .pipe(wiredep({ - directory: yeoman.app + '/bower_components', + directory: /*yeoman.app + */'/bower_components', ignorePath: '..' })) - .pipe(gulp.dest(yeoman.app + '/views')); + // .pipe(gulp.dest(yeoman.app + '/views')); + .pipe(gulp.dest(yeoman.temp)); }); /////////// @@ -164,15 +183,15 @@ gulp.task('bower', function () { /////////// gulp.task('clean:dist', function (cb) { - rimraf('./dist', cb); + rimraf(yeoman.dist, cb); }); -gulp.task('client:build', ['html', 'styles'], function () { +gulp.task('client:build', ['bower', 'html', 'styles'], function () { var jsFilter = $.filter('**/*.js'); var cssFilter = $.filter('**/*.css'); - return gulp.src(paths.views.main) - .pipe($.useref({searchPath: [yeoman.app, '.tmp']})) + return gulp.src(paths.views.bowermain) + .pipe($.useref({searchPath: [yeoman.app, yeoman.temp]})) .pipe(jsFilter) .pipe($.ngAnnotate()) .pipe($.uglify()) @@ -180,8 +199,8 @@ gulp.task('client:build', ['html', 'styles'], function () { .pipe(cssFilter) .pipe($.minifyCss({cache: true})) .pipe(cssFilter.restore()) - .pipe($.rev()) - .pipe($.revReplace()) + // .pipe($.rev()) + // .pipe($.revReplace()) .pipe(gulp.dest(yeoman.dist)); }); @@ -205,13 +224,24 @@ gulp.task('copy:extras', function () { .pipe(gulp.dest(yeoman.dist)); }); +gulp.task('copy:favicon', function () { + return gulp.src(yeoman.app + '/favicon.ico') + .pipe(gulp.dest(yeoman.dist)); +}); + gulp.task('copy:fonts', function () { - return gulp.src(yeoman.app + '/fonts/**/*') + return gulp.src('./bower_components/bootstrap/dist/fonts/**/*') .pipe(gulp.dest(yeoman.dist + '/fonts')); }); -gulp.task('build', ['clean:dist'], function () { - runSequence(['images', 'copy:extras', 'copy:fonts', 'client:build']); +gulp.task('build', ['clean:dist', 'bower'], function () { + runSequence(['images', 'copy:extras', 'copy:fonts', 'copy:favicon', 'client:build']); }); +gulp.task('wiredep', ['bower']); gulp.task('default', ['build']); + + +function serveStaticBower(connect, opt){ + return [['/bower_components', connect.static('./bower_components')] +]} From 226ea45273fb6da0a0d513deffca9ffcb2bc4ae4 Mon Sep 17 00:00:00 2001 From: Alexander Deider Date: Wed, 18 May 2016 01:48:34 +0600 Subject: [PATCH 2/2] fix(gen) gulpfile.js fixes Some fixes after testing https://github.com/yeoman/generator-angular/issues/1299 --- templates/common/root/_gulpfile.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/templates/common/root/_gulpfile.js b/templates/common/root/_gulpfile.js index 68b7d11b0..1460d40aa 100644 --- a/templates/common/root/_gulpfile.js +++ b/templates/common/root/_gulpfile.js @@ -24,16 +24,20 @@ var paths = { styles: [yeoman.app + '/styles/**/*.' + cssx], test: ['test/spec/**/*.' + jsx], testRequire: [ - yeoman.app + '/bower_components/angular/angular.js', - yeoman.app + '/bower_components/angular-mocks/angular-mocks.js', - yeoman.app + '/bower_components/angular-resource/angular-resource.js', - yeoman.app + '/bower_components/angular-cookies/angular-cookies.js', - yeoman.app + '/bower_components/angular-sanitize/angular-sanitize.js', - yeoman.app + '/bower_components/angular-route/angular-route.js', + 'bower_components/angular/angular.js', + 'bower_components/angular-mocks/angular-mocks.js', + 'bower_components/angular-resource/angular-resource.js', + 'bower_components/angular-cookies/angular-cookies.js', + 'bower_components/angular-sanitize/angular-sanitize.js', + 'bower_components/angular-route/angular-route.js', + 'bower_components/angular-animate/angular-animate.js', + 'bower_components/angular-touch/angular-touch.js', + 'bower_components/angular-ui-sortable/sortable.js', + 'bower_components/angular-local-storage/dist/angular-local-storage.js', 'test/mock/**/*.' + jsx, 'test/spec/**/*.' + jsx ], - karma: 'karma.conf.js', + karma: yeoman.test + '/karma.conf.js', views: { main: yeoman.app + '/index.html', bowermain: yeoman.temp + '/index.html', @@ -98,7 +102,7 @@ gulp.task('start:client', ['start:server', <% if (coffee) { %>'coffee', <% } els gulp.task('start:server', function() { $.connect.server({ - root: [yeoman.app, yeoman.temp], + root: [yeoman.temp, yeoman.app], livereload: true, // Change this to '0.0.0.0' to access the server from outside. port: 9000, @@ -108,7 +112,7 @@ gulp.task('start:server', function() { gulp.task('start:server:test', function() { $.connect.server({ - root: [yeoman.test, yeoman.app, yeoman.temp], + root: [yeoman.temp, yeoman.test, yeoman.app], livereload: true, port: 9001, middleware: serveStaticBower @@ -152,7 +156,7 @@ gulp.task('serve', function (cb) { gulp.task('serve:prod', function() { $.connect.server({ root: [yeoman.dist], - livereload: true + livereload: true, port: argv.port || 80, middleware: serveStaticBower }); @@ -171,7 +175,7 @@ gulp.task('test', ['start:server:test'], function () { gulp.task('bower', function () { return gulp.src(paths.views.main) .pipe(wiredep({ - directory: /*yeoman.app + */'/bower_components', + directory: /*yeoman.app + */'./bower_components', ignorePath: '..' })) // .pipe(gulp.dest(yeoman.app + '/views'));