swordsman
v0.1.4
Published
Sharp file watch interface for Facebook Watchman
Downloads
2
Readme
Swordsman ⚔️
Swordsman is a file watch interface for Facebook Watchman. The goal is to provide an easy to use API to leverage all the power of Watchman in NodeJS. It is heavily inspired by sane, but focused exclusively on Watchman.
Install
npm install swordsman
Usage
import { Stats } from 'fs'
import * as swordsman from 'swordsman'
const watcher = new sworsdman.Watcher('/path/to/watch')
watcher.on('ready', () => { console.log('ready') })
watcher.on('add', (path: string, stats: Stats) => { console.log('file added', path, stats) })
watcher.on('change', (path: string, stats: Stats) => { console.log('file changed', path, stats) })
watcher.on('delete', (path: string) => { console.log('file deleted', path) })
watcher.close().then(() => { console.log('watcher closed') })
By default, every files and directories are reported. To filter the watched files, use the Watchman query language. For example, to watch only .js
files:
const watcher = new sworsdman.Watcher(
'/path/to/watch',
{
expression: [
'allof',
[ 'type', 'f' ],
[ 'suffix', 'js' ]
]
}
)
Options
You can provide options
object as a third parameter to the swordsman.Watcher
constructor.
watchmanBinaryPath
(string
): Path to the Watchman binary.reportExistingFiles
(boolean
, defaultfalse
): Whether to send an ADD event for existing files on watch initialization.