Giter Site home page Giter Site logo

Comments (19)

ondaplana avatar ondaplana commented on July 17, 2024 1

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.

dashed avatar dashed commented on July 17, 2024

You mean files in ./dist/?

from gulp-watch.

xixixao avatar xixixao commented on July 17, 2024

Yes.

from gulp-watch.

dashed avatar dashed commented on July 17, 2024

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.

floatdrop avatar floatdrop commented on July 17, 2024

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.

xixixao avatar xixixao commented on July 17, 2024

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.

floatdrop avatar floatdrop commented on July 17, 2024

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.

YourDeveloperFriend avatar YourDeveloperFriend commented on July 17, 2024

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.

floatdrop avatar floatdrop commented on July 17, 2024

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.

YourDeveloperFriend avatar YourDeveloperFriend commented on July 17, 2024

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.

andyyou avatar andyyou commented on July 17, 2024

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.

rur avatar rur commented on July 17, 2024

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.

YourDeveloperFriend avatar YourDeveloperFriend commented on July 17, 2024

Thanks @rur ! That fixed the issue I was having.

from gulp-watch.

meeDamian avatar meeDamian commented on July 17, 2024

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.

natew avatar natew commented on July 17, 2024

file.event seems to be undefined to me in the latest versions, what do you check to get the event type?

from gulp-watch.

eksperimental avatar eksperimental commented on July 17, 2024

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.

UltCombo avatar UltCombo commented on July 17, 2024

@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.

eksperimental avatar eksperimental commented on July 17, 2024

@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.

UltCombo avatar UltCombo commented on July 17, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.