Comments (19)
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'));
});
from gulp-watch.
You mean files in ./dist/
?
from gulp-watch.
Yes.
from gulp-watch.
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.
from gulp-watch.
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.
from gulp-watch.
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.
from gulp-watch.
event
property landed in 0.5.4
- https://github.com/floatdrop/gulp-watch#filtering-custom-event, sorry for such delay. very busy, much work.
from gulp-watch.
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'? */);
from gulp-watch.
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?
from gulp-watch.
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 :/
from gulp-watch.
I am not ensure your problem is the same with me, but I provide a soulation as follow
https://gist.github.com/AndyYou/f35a308e469348df4cc7
from gulp-watch.
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());
from gulp-watch.
Thanks @rur ! That fixed the issue I was having.
from gulp-watch.
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
from gulp-watch.
file.event seems to be undefined to me in the latest versions, what do you check to get the event type?
from gulp-watch.
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?
from gulp-watch.
@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
from gulp-watch.
@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?
from gulp-watch.
@eksperimental That's possibly an inconsistency in Chokidar or in a lower level (Node.js core/libuv/drivers/OS). The folks over at Chokidar may be able to provide more help.
from gulp-watch.
Related Issues (20)
- With plug-in tasks hang
- Watched unexpected filepath
- Update anymatch version in package.json HOT 4
- Watched unexpected filepath
- Watched unexpected filepath
- Watched unexpected filepath
- Watched unexpected filepath
- subfolders no longer updating the main style.scss file
- Watched unexpected filepath
- How to deal with changed files? HOT 2
- watch is not working correctly
- chokidar version 3 HOT 4
- Watched unexpected filepath
- Watched unexpected filepath HOT 1
- please publish the latest version to npm
- chokidar version is too low
- Watched unexpected filepath
- Watched unexpected filepath HOT 1
- Watched unexpected filepath
- Watched unexpected filepath
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gulp-watch.