mirror of
https://github.com/smartyellow/status.git
synced 2025-07-19 20:58:02 +00:00
31
dashboard/index.js
Normal file
31
dashboard/index.js
Normal file
@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
const { build: viteBuild } = require('vite');
|
||||
const fs = require('fs').promises;
|
||||
const { svelte } = require('@sveltejs/vite-plugin-svelte');
|
||||
|
||||
const path = __dirname + '/../gui/dashboard';
|
||||
|
||||
const build = (prefix = '') => viteBuild({
|
||||
root: path,
|
||||
base: `${prefix}/statusdashboard/asset/`,
|
||||
plugins: [ svelte() ],
|
||||
build: {
|
||||
rollupOptions: {
|
||||
output: {
|
||||
assetFileNames: '[hash].[ext]',
|
||||
entryFileNames: '[hash].js',
|
||||
chunkFileNames: '[hash].js',
|
||||
},
|
||||
},
|
||||
outDir: path + '/build',
|
||||
},
|
||||
});
|
||||
|
||||
const cleanup = () => fs.rm(path + '/build', {
|
||||
recursive: true,
|
||||
force: true,
|
||||
});
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user