Skip to content

Instantly share code, notes, and snippets.

@dotfold
Created February 23, 2013 00:45
Show Gist options
  • Save dotfold/5017713 to your computer and use it in GitHub Desktop.
Save dotfold/5017713 to your computer and use it in GitHub Desktop.
exports.watch = function(patterns, excludes, fileList, watchEvents) {
var options = {
ignorePermissionErrors: true,
ignored: createIgnore(excludes)
};
var chokidarWatcher = new chokidar.FSWatcher(options);
watchPatterns(patterns, chokidarWatcher);
var bind = function(fn) {
return function(path) {
return fn.call(fileList, helper.normalizeWinPath(path));
};
};
var watchEventToHandler = {
'add': bind.call(null, fileList.addFile),
'change': bind.call(null, fileList.changeFile),
'unlink': bind.call(null, fileList.removeFile)
};
// register events
watchEvents.forEach(function(eventName) {
chokidarWatcher.on(eventName, watchEventToHandler[eventName]);
});
// register events
// chokidarWatcher.on(constant.FILE_ADD, bind(fileList.addFile))
// .on(constant.FILE_CHANGE, bind(fileList.changeFile))
// .on(constant.FILE_UNLINK, bind(fileList.removeFile));
return chokidarWatcher;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment