Open nimo23 opened 9 years ago
Wouldn't your watch
task have to take care of this? Once the file is deleted, there is nothing to compare.
+1 Is very important remove deleted files :/
Could someone provide some code or an example that better reproduces the issue?
It is true that the plugin doesn't "consider" deleted files. There is no state retained by the plugin at all. Every time you run it, it compares source file times to destination file times. The act of deleting a file isn't communicated in any way to the plugin.
For example... I want to use this plugin to compress only the new images using gulp-imagemin (instead of all images), but What happen with the deleted images (in the origin)? I want to delete these automatically
See my example: https://github.com/jdnichollsc/Ionic-Starter-Template/blob/master/gulpfile.js I don't want to delete all the images in the destination, what do you think? :)
Can gulp-newer works with subdirectories?
The gulp-newer
plugin only limits which source files are included in a pipeline. It is not the job of this plugin to delete files.
If you delete a source file and you want the corresponding destination file to be delete it, you'd need to delete it manually, clean, or use a plugin that deletes selectively. I haven't used it, but gulp-deleted
looks like it does the latter.
yes, is correct :)
@nimo23 See my example! :dancers: https://github.com/tschaub/gulp-newer/issues/33#issuecomment-201163329
The issue is this
Let us assume, our css directory has three files
|-project |-css |-a.css |-b.css |-c.css
And, let our destination look like so:
|-build |-css |-concatenated.css
Notice that concatenated.css is,
a.css + b.css + c.css
let our task be defined like so: Task "optimizeCss"
gulp.src(css/**/*.css) .pipe(newer('build/css/concatenated.css')) .pipe(concat('concatenated.css')) .pipe(gulp.dest('build/css'))
Now, let us consider watching the css directory like so:
$.watch(['css/**/*'], ['optimizeCss']);
Run #1: No files are added or modified. SO,No files are newer than concatenated.css, so everything remains same
Run #2: Let us edit a.css Now, since a.css has a timestamp lesser than concatenated.css, all the three files are concatenated again. SO FAR SOOOOO GOOD!
Run #3: Let us DELETE c.css
Now, the source folder which is project/css, contains only
SO, CONCATENATED.CSS = A.CSS + B.CSS
IS that correct??
BUT BUT BUT,
when the Newer task is triggered on deletion of c.css,
the result is
CONCATENATED.CSS = A+B+C
BUT hello! C is no longer there!!!!!!!
then why does the gulp-newer pipe it? It shouldnt
Edit: gulp-newer doesn't pipe anything down the pipline
Well, I figured the problem is because, when you delete a file,
and no other files are changed, gulp-newer doesn't pipe anything at all
hence, your destination remains unedited to incorporate the deletion
Any workaround for this?
To borrow inspiration from the gulp-remember usage example, would something like the following work?
gulp.task('watch', function () {
var watcher = gulp.watch(scriptsGlob, ['scripts']); // watch the same files in our scripts task
watcher.on('change', function (event) {
if (event.type === 'deleted') {
// Handled deleted file (delete the dest file maybe?)
}
});
});
For example, having these files in src-directory :
and this in target-directory:
Changing the content of "a.css" or putting a new file in src-directory ("c.css") will trigger gulp-newer to make a new "min.css". However, when deleting "a.css", then gulp-newer does not treat it as a change, hence "min.css" will have the content of "a.css" after running the task, even "a.css" does not exist anymore.
Would be nice, if gulp-newer is able to consider deleted files in src-dir.