Last active
December 15, 2016 23:37
-
-
Save spiralx/aee491b29663a12688ef to your computer and use it in GitHub Desktop.
Gulp - suspend watcher during task execution
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'); | |
function doGitCheckout(callback) { | |
console.log('doing checkout...'); | |
setTimeout(function() { | |
console.log('done checkout...'); | |
callback(); | |
}, 1000); | |
} | |
var watcher; | |
gulp.task('watch:start', function() { | |
if (!watcher) { | |
watcher = gulp.watch('dist/**/*', ['build']); | |
console.log('started watcher'); | |
} | |
}); | |
gulp.task('watch:stop', function() { | |
if (watcher) { | |
watcher.end(); | |
watcher = null; | |
console.log('stopped watcher'); | |
} | |
}); | |
gulp.task('git:checkout', ['watch:stop'], function(cb) { | |
console.log('isWatching = ' + !!watcher); | |
// Start the Git checkout... | |
doGitCheckout(function() { | |
// The Git checkout is finished! | |
gulp.start('watch:start', function() { | |
cb(); | |
}); | |
}); | |
}); | |
gulp.task('default', ['watch:start', 'git:checkout']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This looked promising for my use case, but my use case uses gulp.watch() which is a long running process and I tried tweaking this example to stop my process and it only seemed to work once no matter what I did. Oh well I found another solution to get my process to not fight with gulp running and killing processes when it detected file changes.