mirror of
https://github.com/smartyellow/status.git
synced 2025-01-18 13:37:59 +00:00
Dashboard watcher
Signed-off-by: Romein van Buren <romein@vburen.nl>
This commit is contained in:
parent
6241de18fe
commit
de2b8cdba8
@ -1,11 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const { build: viteBuild } = require('vite');
|
||||
const { svelte } = require('@sveltejs/vite-plugin-svelte');
|
||||
const fs = require('fs').promises;
|
||||
const { svelte } = require('@sveltejs/vite-plugin-svelte');
|
||||
|
||||
const path = __dirname + '/../gui/dashboard';
|
||||
|
||||
const build = (prefix = '') => viteBuild({
|
||||
root: __dirname + '/gui/dashboard/',
|
||||
root: path,
|
||||
base: `${prefix}/statusdashboard/asset/`,
|
||||
plugins: [ svelte() ],
|
||||
build: {
|
||||
@ -16,14 +18,14 @@ const build = (prefix = '') => viteBuild({
|
||||
chunkFileNames: '[hash].js',
|
||||
},
|
||||
},
|
||||
outDir: __dirname + '/gui/dashboard/build',
|
||||
outDir: path + '/build',
|
||||
},
|
||||
});
|
||||
|
||||
const cleanup = () => fs.rm(__dirname + '/gui/dashboard/build', {
|
||||
const cleanup = () => fs.rm(path + '/build', {
|
||||
recursive: true,
|
||||
force: true,
|
||||
});
|
||||
|
||||
module.exports = { build, cleanup };
|
||||
module.exports = { build, cleanup, path };
|
||||
build();
|
32
dashboard/watcher.js
Normal file
32
dashboard/watcher.js
Normal file
@ -0,0 +1,32 @@
|
||||
'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;
|
||||
}
|
||||
});
|
4
index.js
4
index.js
@ -127,6 +127,10 @@ module.exports = {
|
||||
|
||||
await dashboard.cleanup();
|
||||
await dashboard.build(server.settings.prefix);
|
||||
|
||||
const dashWatcher = fork(__dirname + '/dashboard/watcher.js');
|
||||
dashWatcher.send({ command: 'start', path: dashboard.path });
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
|
@ -22,8 +22,9 @@
|
||||
"url": "https://github.com/smartyellow/status/issues"
|
||||
},
|
||||
"homepage": "https://github.com/smartyellow/status#readme",
|
||||
"devDependencies": {
|
||||
"dependencies": {
|
||||
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.49",
|
||||
"chokidar": "^3.5.3",
|
||||
"svelte": "^3.49.0",
|
||||
"vite": "^2.9.13"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user