-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWatchman.js
37 lines (36 loc) · 1.18 KB
/
Watchman.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const watchman = require('fb-watchman')
class Watchman {
constructor() {
this.client = new watchman.Client()
}
command(...args) {
return new Promise((resolve, reject) => {
this.client.command(args, (err, resp) => {
if (err) reject(err)
else resolve(resp)
})
})
}
async setup_watches(dirname) {
const { warning, watch, relative_path } = await this.command("watch-project", dirname)
if (warning) {
console.warn('[watchman]', warning);
}
console.log('[watchman] watch established on:', watch, 'relative_path:', relative_path);
Object.assign(this, { watch, relative_path })
this.clock = await this.command("clock", watch)
}
async subscribe(name, expression) {
const sub = {
expression,
fields: ["name", "size", "mtime_ms", "exists", "type"],
since: this.clock
}
if (this.relative_path) sub.relative_root = this.relative_path
await this.command('subscribe', this.watch, name, sub)
}
on(x, y) {
return this.client.on(x, y)
}
}
module.exports.Watchman = Watchman