The default watcher class. Uses fs.watch under the hood, and takes the same options as sane(dir, options).
sane.WatchmanWatcher(dir, options)
The watchman watcher class. Takes the same options as sane(dir, options).
sane.Watchexec(dir, options)
The watchexec watcher class. Takes the same options as sane(dir, options).
sane.PollWatcher(dir, options)
The polling watcher class. Takes the same options as sane(dir, options) with the addition of:
interval: indicates how often the files should be polled. (passed to fs.watchFile)
sane.{Node|Watchman|Watchexec|Poll}Watcher#close
Stops watching.
sane.{Node|Watchman|Watchexec|Poll}Watcher events
Emits the following events:
All events are passed the file/dir path relative to the root directory
ready when the program is ready to detect events in the directory
change when a file changes
add when a file or directory has been added
delete when a file or directory has been deleted
CLI
This module includes a simple command line interface, which you can install with npm install sane -g.
Usage: sane <command> [...directory] [--glob=<filePattern>] [--poll] [--watchman] [--watchman-path=<watchmanBinaryPath>] [--dot] [--wait=<seconds>]OPTIONS: --glob=<filePattern> A single string glob pattern or an array of them. --ignored=<filePattern> A glob, regex, function, or array of any combination. --poll, -p Use polling mode. --watchman, -w Use watchman (if available). --watchman-path=<watchmanBinaryPath> Sets a custom path for watchman binary (if using this mode). --dot, -d Enables watching files/directories that start with a dot. --wait=<seconds> Duration, in seconds, that watching will be disabled after running <command>. Setting this option will throttle calls to <command> for the specified duration. --quiet, -q Disables sane's console output --changes-only, -o Runs <command> only when a change occur. Skips running <command> at startup
It will watch the given directory and run the given every time a file changes.
CLI example usage
sane 'echo "A command ran"'
sane 'echo "A command ran"' --glob='**/*.css'
sane 'echo "A command ran"' site/assets/css --glob='**/*.css'
sane 'echo "A command ran"' --glob='**/*.css' --ignored='**/ignore.css'
sane 'echo "A command ran"' --wait=3
sane 'echo "A command ran"' -p
License
MIT
Credits
The CLI was originally based on the watch CLI. Watch is licensed under the Apache License Version 2.0.