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
@davidrenne What was the other solution? This solution doesn't work for me either.