-
-
Save krosti/78d5fb1a4eea5b44da58 to your computer and use it in GitHub Desktop.
Gulpfile with Livereload, Nodemon, and other features
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'), | |
exec = require('child_process').exec, | |
sass = require('gulp-ruby-sass'), | |
concat = require('gulp-concat'), | |
plumber = require('gulp-plumber'), | |
server = require('tiny-lr')(), | |
refresh = require('gulp-livereload'), | |
mocha = require('gulp-mocha'), | |
notify = require('gulp-notify'), | |
nodemon = require('gulp-nodemon'), | |
jshint = require('gulp-jshint'), | |
lrPort = 35728; | |
var paths = { | |
styles: ['./public/scss/**/*.scss'], | |
scripts: [ | |
'public/js/**', | |
'!public/js/admin', | |
'!public/js/admin/**' | |
], | |
jade: [ | |
'./app/views/**/*.jade' | |
], | |
server: { | |
js: ['./app/**/*.js'], | |
specs: ['./app/specs/**/*.js'] | |
} | |
}; | |
function runCommand(command) { | |
return function (cb) { | |
exec(command, function (err, stdout, stderr) { | |
console.log(stdout); | |
console.log(stderr); | |
cb(err); | |
}); | |
} | |
} | |
//Run mongo | |
gulp.task('start-mongo', runCommand('mongod')); | |
gulp.task('stop-mongo', runCommand('mongo --eval "use admin; db.shutdownServer();"')); | |
gulp.task('sass', function () { | |
gulp.src('./public/scss/*.scss') | |
.pipe(sass()) | |
.pipe(gulp.dest('./public/css')) | |
.pipe(refresh(server)); | |
}); | |
gulp.task('serve', function(){ | |
nodemon({'script': 'app.js'}); | |
}); | |
gulp.task('lint', function(){ | |
return gulp.src(paths.scripts) | |
.pipe(plumber()) | |
.pipe(jshint()) | |
.pipe(jshint.reporter('default')) | |
.pipe(notify({message: 'jshint done'})); | |
}); | |
gulp.task('scripts', function(){ | |
return gulp.src(paths.scripts) | |
.pipe(plumber()) | |
.pipe(concat('main.js')) | |
.pipe(gulp.dest('./public/dist/client/')) | |
.pipe(refresh(server)) | |
.pipe(notify({message: 'JS concated'})); | |
}); | |
gulp.task('test', function(){ | |
return gulp.src(paths.server.specs) | |
.pipe(mocha({reporter: 'spec'})) | |
.pipe(notify({message: "Specs ran"})); | |
}); | |
gulp.task('jade', function(){ | |
return gulp.src(paths.jade) | |
.pipe(refresh(server)) | |
.pipe(notify({message: 'Views refreshed'})); | |
// }); | |
}); | |
gulp.task('build', ['sass', 'scripts', 'lint']); | |
gulp.task('lr', function(){ | |
server.listen(lrPort, function(err){ | |
if(err) {return console.error(err);} | |
}); | |
}); | |
gulp.task('watch', function(){ | |
gulp.watch(paths.jade, ['jade']); | |
gulp.watch(paths.scripts, ['scripts']); | |
gulp.watch(paths.styles, ['sass']); | |
}); | |
gulp.task('default', ['test', 'build', 'lr', 'serve', 'watch']); | |
gulp.task('dev', ['start-mongo', 'test', 'build', 'lr', 'serve', 'watch']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment