Nessuna descrizione

index.js 972B

123456789101112131415161718192021222324252627282930313233343536373839
  1. var gaze = require('gaze');
  2. var EventEmitter = require('events').EventEmitter;
  3. module.exports = function(glob, opts, cb) {
  4. var out = new EventEmitter();
  5. if (typeof opts === 'function') {
  6. cb = opts;
  7. opts = {};
  8. }
  9. var watcher = gaze(glob, opts, function(err, rwatcher){
  10. if (err) out.emit('error', err);
  11. rwatcher.on('all', function(evt, path, old){
  12. var outEvt = {type: evt, path: path};
  13. if(old) outEvt.old = old;
  14. out.emit('change', outEvt);
  15. if(cb) cb(outEvt);
  16. });
  17. });
  18. watcher.on('end', out.emit.bind(out, 'end'));
  19. watcher.on('error', out.emit.bind(out, 'error'));
  20. watcher.on('ready', out.emit.bind(out, 'ready'));
  21. watcher.on('nomatch', out.emit.bind(out, 'nomatch'));
  22. out.end = function(){
  23. return watcher.close();
  24. };
  25. out.add = function(){
  26. return watcher.add.apply(watcher, arguments);
  27. };
  28. out.remove = function(){
  29. return watcher.remove();
  30. };
  31. out._watcher = watcher;
  32. return out;
  33. };