_____ ______ ___________ _______ __ /_________ /_ ___ __/_________ | /| / / __ `/ __/ ___/_ __ \________ /_ __ ___/__ |/ |/ // /_/ // /_ / /__ _ / / //_____/ __/ _(__ )____/|__/ \__,_/ \__/ \___/ /_/ /_/ /_/ /____/
Watches your files and folders and gets out of the way
Watching files in a directory is as simple as instantiating a watcher and handling
events emitted when files get created, changed, or deleted.
Var Watcher = require'watchfs'Watcher;var watcher =paths: 'path-to-my-dir' 'path-to-my-file' 'etc'filters:return /\.js/testname;;watcheron'create'console.log'file ' + name + ' created';;watcheron'change'console.log'file ' + name + ' changed';;watcheron'delete'console.log'file ' + name + ' deleted';;watcherstartconsole.log'watcher started';;
The following options can be specified when creating a Watcher object
This could be a string or an array containing paths to files or directories.
Any directories specified will be watched recursively unless limited by filtering.
var watcher1 =paths: '/work/my-project';var watcher2 =paths: '/work/my-other-project' '/work/my-file';
Filters can be used to limit which files or directories are being watched.
filters should be an object containing two functions
Both functions will be called when traversing the file system with the full path of each
file or directory encountered.
The example below will watch the specified folder and will recurse only one folder below
var watcher =paths: '/work/my-project'filters:return /^\/work\/my-project?$/testfullPath;;
In the next example we're watching only js files and we're skipping .git and node_modules folders
var watcher =paths: '/work/my-project'filters:var skip = /|/testfullPath;return !skip;return /\.js/testfullPath;;
createfired when a file is created
changefired when a file is changed
deletefired when a file is deleted
anyfires when any of the above events fire
watcheron'create'console.log'file ' + name + ' created';;watcheron'any'console.log'file ' + name + ' ' + type + 'd';;