Skip to content

Instantly share code, notes, and snippets.

@krosti
Forked from Hendrixer/Gulpfile.js
Last active August 31, 2015 19:26
Show Gist options
  • Save krosti/78d5fb1a4eea5b44da58 to your computer and use it in GitHub Desktop.
Save krosti/78d5fb1a4eea5b44da58 to your computer and use it in GitHub Desktop.
Gulpfile with Livereload, Nodemon, and other features
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