-
Notifications
You must be signed in to change notification settings - Fork 6
/
watch-site.js
54 lines (49 loc) · 1.3 KB
/
watch-site.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
const chokidar = require('chokidar')
const bs = require('browser-sync').create()
const generator = require('@antora/site-generator')
const Lock = require('./lock.js')
const processorLock = new Lock()
const antoraArgs = ['--playbook', 'site.yml']
const watcher = chokidar.watch([
`src/docs/**`,
], {
ignored: [
/(^|[\/\\])\../, // ignore dotfiles
],
persistent: true,
// avoid issues with Intellij IDEA temporary files (used to automatically save changes)
// [Error: ENOENT: no such file or directory, lstat '/path/to/.../file.adoc~' in /path/to/... (ref: antora-local-dev <worktree> | path: modules/...)] {
// errno: -2,
// code: 'ENOENT',
// syscall: 'lstat',
// path: '/path/to/.../file.adoc~'
// }
awaitWriteFinish: {
stabilityThreshold: 100,
pollInterval: 50
}
})
async function generate(_) {
try {
const hasQueuedEvents = await processorLock.acquire()
if (!hasQueuedEvents) {
await generator(antoraArgs, process.env)
bs.reload({
notify: false
})
}
} catch (err) {
console.error(err)
} finally {
processorLock.release()
}
}
watcher.on('change', async e => await generate(e))
watcher.on('unlink', async e => await generate(e))
;(async () => {
await generate()
bs.init({
notify: false,
server: './public'
})
})()