forked from neo4j-documentation/knowledge-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch.js
35 lines (29 loc) · 852 Bytes
/
watch.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
const chokidar = require('chokidar')
const browserSync = require("browser-sync")
const generator = require('@antora/site-generator-default')
const Lock = require('./lock.js')
const processorLock = new Lock()
const antoraArgs = ['--playbook', 'local-antora-playbook.yml']
browserSync({server: "./public"})
const watcher = chokidar.watch(['articles/modules/ROOT/**'],
{
ignored: /(^|[\/\\])\../, // ignore dotfiles
persistent: true
}
)
async function process() {
try {
const hasQueuedEvents = await processorLock.acquire()
if (!hasQueuedEvents) {
await generator(antoraArgs, process.env)
browserSync.reload("*")
}
} catch (err) {
console.error(err)
} finally {
processorLock.release()
}
}
watcher.on('change', async _ => await process())
watcher.on('unlink', async _ => await process())
process()