Skip to content

Instantly share code, notes, and snippets.

@spiralx
Last active December 15, 2016 23:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spiralx/aee491b29663a12688ef to your computer and use it in GitHub Desktop.
Save spiralx/aee491b29663a12688ef to your computer and use it in GitHub Desktop.
Gulp - suspend watcher during task execution
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']);
@kevinbeal
Copy link

@davidrenne What was the other solution? This solution doesn't work for me either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment