Created
December 6, 2014 03:47
-
-
Save rmcc13/7257cea0676bfa33cc6f to your computer and use it in GitHub Desktop.
gulpfile with tasks to lint itself and restart gulp process on change
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'); | |
var jshint = require('gulp-jshint'); | |
var jshintStylish = require('jshint-stylish'); | |
/* required for restarting gulp task */ | |
var spawn = require('child_process').spawn; | |
/* used to track if a gulp process is already running */ | |
var p; | |
/* task to restart gulp process */ | |
gulp.task('restart-me', function() { | |
/* if p is defined, a gulp process is already | |
running, kill current process befor starting | |
a new one */ | |
if (p) { p.kill(); } | |
/* start new gulp process */ | |
p = spawn('gulp', ['dev'], {stdio: 'inherit'}); | |
}); | |
/* task to lint this file */ | |
gulp.task('lint-me', function() { | |
gulp.src('./gulpfile.js') | |
.pipe(jshint()) | |
.pipe(jshint.reporter(jshintStylish)); | |
}); | |
/* watch this file, on change, lint then restart gulp */ | |
gulp.task('watch-me', function() { | |
gulp.watch('./gulpfile.js', ['lint-me', 'restart-me']); | |
}); | |
/* dev tasks */ | |
gulp.task('dev', ['watch-me']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment