Closed xixixao closed 10 years ago
You mean files in ./dist/
?
Yes.
This doesn't require change in gulp core.
gulp-watch would need to somehow communicate that an event occurred via a callback. It uses gaze internally to watch these events. At the moment, it just seems to log it to console.
I could add event
property to vinyl-fs
object. This will allow to track events after watch emitted something. For the rest functionality you could write a gulp-plugin
that will track files and delete (somehow) moved files.
So I would have to remember the compiled files, since plugins don't produce correct file names and then remove them if needed. I guess that'd work.
event
property landed in 0.5.4
- https://github.com/floatdrop/gulp-watch#filtering-custom-event, sorry for such delay. very busy, much work.
So what can I do to get gulp watch to delete the files?
watch({glob: 'server/**/*.coffee'})
.pipe(plumber())
.pipe(coffeelint())
.pipe(coffeelint.reporter())
.pipe(coffee({bare: true}))
.pipe(gulp.dest('build'));
is giving me the error: Arguments to path.join must be strings
I tried filtering as recommended, but I'm not sure what to do with the deleted files:
var deletedFilter = filter(function(file) { return file.event === 'deleted'; });
watch({glob: 'server/**/*.coffee'})
.pipe(deletedFilter)
.pipe(plumber())
.pipe(coffeelint())
.pipe(coffeelint.reporter())
.pipe(coffee({bare: true}))
.pipe(gulp.dest('build'));
deletedFilter.restore({end: true})
.pipe(/* delete corresponding files in 'build'? */);
Hi @YourDeveloperFriend! Thanks for reporting.
First, could you write, what you want to achieve? It is not clear to my. If you append deletedFilter
to pipeline - then you will pass deleted files to coffeelint - which is clearly not what you want (maybe you should use !== 'deleted'
in filter function).
Also can you write a stacktrace of an Arguments to path.join must be strings
error?
Sorry, I wrote out deletedFilter wrong:
deletedFilter = function(file) { return file.event !== 'deleted' };
I'll give you more information next week, super busy right now :/
I am not ensure your problem is the same with me, but I provide a soulation as follow
I got this to work by adding a 'dest' to the deleted file stream like so:
var clean = require('gulp-clean');
deletedFilter.restore({end: true})
.pipe(gulp.dest('build'))
.pipe(clean());
Thanks @rur ! That fixed the issue I was having.
That worked for me too. Since gulp-clean
is deprecated and solution here is spread across several posts, here's a tl;dr:
npm i gulp-filter del vinyl-paths --save-dev
del = require 'del'
vinylPaths = require 'vinyl-paths'
filter = require 'gulp-filter' # skip that if you use `gulp-load-plugins`
deletedFilter = filter (file) -> file.event isnt 'deleted'
watch 'app/**/*.coffee'
.pipe deletedFilter
# some other pipes
.pipe gulp.dest 'dist'
deletedFilter.restore end: true
.pipe gulp.dest 'dist'
.pipe vinylPaths (file, cb) ->
del file.replace(/.coffee$/, '.js{,.map}'), cb # vinyl only provides .coffee file paths, so we need to do mapping ourselves
file.event seems to be undefined to me in the latest versions, what do you check to get the event type?
That worked for me:
var watch = require('gulp-watch');
var filter = require('gulp-filter');
var vinylPaths = require('vinyl-paths');
var del = require('del');
gulp.task('watch-src', function() {
var notDeletedFilter = filter(
function(file) {
return file.event !== 'unlink' && file.event !== 'unlinkDir';
},
{restore: true}
);
notDeletedFilter.restore
.pipe(gulp.dest('www'))
.pipe(vinylPaths(function(file, cb) {
del(file, cb);
}));
watch('src/client/**/*', {events: ['add', 'change', 'unlink', 'unlinkDir']})
.pipe(notDeletedFilter)
.pipe(gulp.dest('www'));
});
Hi @ondaplana, this doesn't seem to work for unliked directories and renamed directories leave the old copy intact and create a copy of the new renamed folder. any ideas how to solve this?
@eksperimental You will have to handle the file.event === 'unlink'
case in your own code. This is how I've been doing it in my workflow: https://github.com/JSRocksHQ/slush-es20xx/blob/2de00c70dc52f990e7256f6cfb8019fc6665b6ac/tpl/env/node/gulpfile.js#L126-L130
@UltCombo well, after testing it for a while, renaming a dir never creates the "unlink" event. it behaves differently that when a file is renamed. which creates "add" and "unlink". any way to solve this?
It would be cool if output files of renamed or removed files got deleted (maybe automatically?). Would this be possible to implement with current gulp?
Edit: This of course is not simple, as the output name must be known, possibly requiring something from every gulp-plugin (I haven't gone through the API). If this requires changes in gulp I'll elevate the issue.
Edit2: For example, https://github.com/wearefractal/gulp-coffee/blob/master/index.js#L9 is just passing the file on, if it is null, without changing the extension.