chore: add watch scripts.

This commit is contained in:
jaywcjlove
2022-09-29 23:09:45 +08:00
parent 5094fac68a
commit a612c2b971
4 changed files with 28 additions and 7 deletions

19
scripts/watch.mjs Normal file
View File

@ -0,0 +1,19 @@
import path from 'path';
import chokidar from 'chokidar';
import { getStat } from 'recursive-readdir-files';
import { run, DOCS, createHTML } from './index.mjs';
;(async () => {
await run();
const homeMdPath = path.relative(process.cwd(), 'README.md')
const watcher = chokidar.watch([DOCS, homeMdPath], {
ignored: /(^|[\/\\])\../, // ignore dotfiles
persistent: true
});
watcher.on('change', async (path) => {
const stats = await getStat(path)
createHTML([stats]);
})
.on('error', error => console.log(`Watcher error: ${error}`))
})();