-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwatch.js
36 lines (30 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
36
const chokidar = require('chokidar')
const browserSync = require('browser-sync')
const generateSite = require('@antora/site-generator')
require('./lib/blog-converter.js')
const Lock = require('./lock.js')
const processorLock = new Lock()
const antoraArgs = ['--playbook', 'site.yml']
browserSync({server: "./public"})
const watcher = chokidar.watch(['blog/modules/ROOT/**'],
{
ignored: /(^|[\/\\])\../, // ignore dotfiles
persistent: true
}
)
async function process() {
try {
const hasQueuedEvents = await processorLock.acquire()
if (!hasQueuedEvents) {
await generateSite(antoraArgs)
browserSync.reload("*")
}
} catch (err) {
console.error(err)
} finally {
processorLock.release()
}
}
watcher.on('change', async _ => await process())
watcher.on('unlink', async _ => await process())
process()