-
Notifications
You must be signed in to change notification settings - Fork 0
/
watchman.js
55 lines (47 loc) · 1.15 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import path from 'path'
import { spawn } from 'child_process'
import { rmdirSync } from 'fs'
import chokidar from 'chokidar'
const dirOfInterest = path.join(path.resolve(), 'src')
function performBuild () {
try {
rmdirSync('./build', { recursive: true })
console.clear()
const child = spawn('yarn', ['build', '--color'])
child.stdout.on('data', function (data) {
process.stdout.write(data.toString())
})
child.stderr.on('data', function (data) {
process.stdout.write(data.toString())
})
} catch (error) {
console.error(error)
}
}
function watch () {
performBuild()
const watcher = chokidar.watch(dirOfInterest, {
ignored: '**/*.html',
ignoreInitial: true,
persistent: true,
followSymlinks: true,
interval: 100,
awaitWriteFinish: {
stabilityThreshold: 2000,
pollInterval: 100
}
})
watcher
.on('add', function (path) {
performBuild()
})
.on('change', function (path) {
performBuild()
})
.on('unlink', function (path) {
performBuild()
})
.on('error', error => console.log(`Watcher error: ${error}`))
return watcher
}
watch()