Which event is emitted after the initial run?
franbenz opened this issue · comments
Hi, does anybody knows if there is an event emitted by gulp-watch after all the initially watched files were added? I was expecting the ready event to be what I needed, but I'm getting a 'ready' event before all 'add' events.
The ready
event is re-emitted from Chokidar, it basically means that file system watchers have been installed in all matching paths and subdirectories, and it is ready to detect changes.
I believe there's currently no event for the specific case you have asked, but I believe you can simulate it using gulp.src
and the end
event:
const watch = require('gulp-watch');
const streamify = require('stream-array');
// Paths to watch
const paths = [/*...*/];
// A function that individually compiles each file in the `src` stream
function compile(src) {
return src
.pipe(/*...*/);
}
// Inside a task or something...
compile(gulp.src(paths)).on('end', () => {
console.log('Compiled all initial files');
// Now you can use gulp-watch with `ignoreInitial: true`
watch(paths, blob => {
compile(streamify(blob));
});
});
If you actually require a new event for your use case, perhaps make a feature request in the Chokidar repository? There's no way for gulp-watch to detect when that would happen as far as I can see.
I have the same problem, but the above solution does not solve my problem very well, because some files may be added or deleted later.