Bachir Soussi Chiadmi cefd1c2ad0 updated sys and created publi | 6 years ago | |
---|---|---|
.. | ||
lib | 7 years ago | |
LICENSE-MIT | 7 years ago | |
README.md | 7 years ago | |
package.json | 6 years ago |
A globbing fs.watch wrapper built from the best parts of other fine watch libs.
Compatible with Node.js 0.10/0.8, Windows, OSX and Linux.
Install the module with: npm install gaze
or place into your package.json
and run npm install
.
var gaze = require('gaze');
// Watch all .js files/dirs in process.cwd()
gaze('**/*.js', function(err, watcher) {
// Files have all started watching
// watcher === this
// Get all watched files
console.log(this.watched());
// On file changed
this.on('changed', function(filepath) {
console.log(filepath + ' was changed');
});
// On file added
this.on('added', function(filepath) {
console.log(filepath + ' was added');
});
// On file deleted
this.on('deleted', function(filepath) {
console.log(filepath + ' was deleted');
});
// On changed/added/deleted
this.on('all', function(event, filepath) {
console.log(filepath + ' was ' + event);
});
// Get watched files with relative paths
console.log(this.relative());
});
// Also accepts an array of patterns
gaze(['stylesheets/*.css', 'images/**/*.png'], function() {
// Add more patterns later to be watched
this.add(['js/*.js']);
});
var Gaze = require('gaze').Gaze;
var gaze = new Gaze('**/*');
// Files have all started watching
gaze.on('ready', function(watcher) { });
// A file has been added/changed/deleted has occurred
gaze.on('all', function(event, filepath) { });
gaze('**/*', function() {
this.on('error', function(err) {
// Handle error here
});
});
See isaacs's minimatch for more information on glob patterns.
patterns
{String|Array} File patterns to be matchedoptions
{Object}callback
{Function}
err
{Error | null}watcher
{Object} Instance of the Gaze watcherCreate a Gaze object by instanting the gaze.Gaze
class.
var Gaze = require('gaze').Gaze;
var gaze = new Gaze(pattern, options, callback);
options
The options object passed in.
interval
{integer} Interval to pass to fs.watchFiledebounceDelay
{integer} Delay for events called in succession for the same
file/eventready(watcher)
When files have been globbed and watching has begun.all(event, filepath)
When an added
, changed
or deleted
event occurs.added(filepath)
When a file has been added to a watch directory.changed(filepath)
When a file has been changed.deleted(filepath)
When a file has been deleted.renamed(newPath, oldPath)
When a file has been renamed.end()
When the watcher is closed and watches have been removed.error(err)
When an error occurs.nomatch
When no files have been matched.emit(event, [...])
Wrapper for the EventEmitter.emit.
added
|changed
|deleted
events will also trigger the all
event.close()
Unwatch all files and reset the watch instance.add(patterns, callback)
Adds file(s) patterns to be watched.remove(filepath)
removes a file or directory from being watched. Does not
recurse directories.watched()
Returns the currently watched files.relative([dir, unixify])
Returns the currently watched files with relative paths.
dir
{string} Only return relative files for this directory.unixify
{boolean} Return paths with /
instead of \\
if on Windows.fs.watch
Wrapper?I liked parts of other fs.watch
wrappers but none had all the features I
needed. This lib combines the features I needed from other fine watch libs:
Speedy data behavior from
paulmillr's chokidar, API interface
from mikeal's watch and file globbing using
isaacs's glob which is also used by
cowboy's Grunt.
EMFILE: Too many opened files.
?This is because of your system's max opened file limit. For OSX the default is
very low (256). Increase your limit temporarily with ulimit -n 10480
, the
number being the new max limit.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.
end
before removeAllListeners.forceWatchMethod
option removed, bug fixes and watch optimizations (@rgaskill).added
events in current working dir.path.sep
. Add forceWatchMethod
option. Support renamed
events.cwd
option properlyCopyright (c) 2013 Kyle Robinson Young
Licensed under the MIT license.