status/dashboard/watcher.js
Romein van Buren de2b8cdba8
Dashboard watcher
Signed-off-by: Romein van Buren <romein@vburen.nl>
2022-07-08 15:18:40 +02:00

33 lines
781 B
JavaScript

'use strict';
const chokidar = require('chokidar');
const dashboard = require('./index');
let watcher;
const handler = async () => {
console.log('status dashboard watcher triggered, rebuilding...');
await dashboard.cleanup();
await dashboard.build();
process.send({ command: 'reload' });
};
process.on('message', message => {
switch (message.command) {
case 'start':
if (message.path) {
watcher = chokidar.watch(message.path, {
ignored: [ /node_modules/, /build/ ],
});
watcher.on('add', handler);
watcher.on('change', handler);
watcher.on('unlink', handler);
}
break;
default:
console.log(`Status dashboard watcher received unknown command ${message.command}`);
break;
}
});