Skip to content

suggested improvements to gulpfile.js #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions 19-mean-workflow/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var ngAnnotate = require('gulp-ng-annotate');
var nodemon = require('gulp-nodemon');
var stylish = require('jshint-stylish');

// define a task called css
gulp.task('css', function() {
Expand All @@ -19,13 +20,26 @@ gulp.task('css', function() {
.pipe(gulp.dest('public/assets/css'));
});

// task for linting js files
gulp.task('js', function() {
return gulp.src(['server.js', 'public/app/*.js', 'public/app/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'));
// define a task for linting just server-side js files using the node option
// using node:true suppresses warnings that do not apply to node/express js
gulp.task('jssvr', function() {
return gulp.src(['server.js'])
.pipe(jshint({node: true}))
.pipe(jshint.reporter(stylish));
});

// define a task for linting client-side js files using browser option
// using browser: true suppresses warnings that do not apply in the browser
gulp.task('jsclient', function() {
return gulp.src(['public/app/*.js', 'public/app/**/*.js'])
.pipe(jshint({browser: true}))
.pipe(jshint.reporter(stylish));
});


// task for linting all js files by calling both server and client lint js tasks
gulp.task('js', ['jsvr', 'jsclient']);

// task to lint, minify, and concat frontend files
gulp.task('scripts', function() {
return gulp.src(['public/app/*.js', 'public/app/**/*.js'])
Expand Down Expand Up @@ -55,16 +69,14 @@ gulp.task('watch', function() {
gulp.watch(['server.js', 'public/app/*.js', 'public/app/**/*.js'], ['js', 'angular']);
});

// nodemon restarts app after any change to file types in the ext: element
// nodemon will call the tasks in the tasks: array on every restart
gulp.task('nodemon', function() {
nodemon({
script: 'server.js',
ext: 'js less html'
})
.on('start', ['watch'])
.on('change', ['watch'])
.on('restart', function() {
console.log('Restarted!');
});
script: './bin/www',
ext: 'js less html',
tasks: ['js','angular','styles']
});
});

gulp.task('default', ['nodemon']);