A library that can watch a directory and recompile files if they change. Can be used to build watcher applications such as less-watcher or coffee-watcher.
A library that can watch a directory and recompile files if they change. Can be used to build watcher scripts such as less-watcher or coffee-watcher.
To install watcher_lib via npm simply do:
sudo npm install watcher_lib
To see how it's used check following projects:
Sample usage (code from less-watcher):
# Use `watcher-lib`, a library that abstracts away most of the implementation details.# This library also makes it possible to implement any watchers (see coffee-watcher for an example).watcher_lib = require './watcher-lib/watcher-lib'# Searches through a directory structure for *.less files using `find`.# For each .less file it runs `compileIfNeeded` to compile the file if it's modified.=watcher_libfindFiles'*.less'dircompileIfNeeded# Keeps a track of modified times for .less files in a in-memory object,# if a .less file is modified it recompiles it using compileLessScript.## When starting the script all files will be recompiled.WATCHED_FILES ==watcher_libcompileIfNeededWATCHED_FILESfilecompileLessScript# Compiles a file using `lessc`.## Compilation errors are printed out to stdout.== filereplace/\.less/'.less.$1.css'watcher_libcompileFile"lessc "filefnGetOutputFile# Starts a poller that polls each second in a directory that's# either by default the current working directory or a directory that's passed through process arguments.watcher_libstartDirectoryPollprocessargv0or '.'findLessFiles