2022-07-08 15:17:17 +00:00
|
|
|
'use strict';
|
|
|
|
|
2022-07-09 11:10:08 +00:00
|
|
|
const { minify: minifyCSS } = require('csso');
|
2022-07-08 15:17:17 +00:00
|
|
|
const { rollup } = require('rollup');
|
2022-07-09 10:46:59 +00:00
|
|
|
const commonjs = require('@rollup/plugin-commonjs');
|
2022-07-09 11:10:08 +00:00
|
|
|
const css = require('rollup-plugin-css-only');
|
2022-07-11 09:20:44 +00:00
|
|
|
const replace = require('@rollup/plugin-replace');
|
2022-07-09 11:10:08 +00:00
|
|
|
const { default: resolve } = require('@rollup/plugin-node-resolve');
|
|
|
|
const svelte = require('rollup-plugin-svelte');
|
|
|
|
const { terser } = require('rollup-plugin-terser');
|
2022-07-08 15:17:17 +00:00
|
|
|
|
2022-07-11 12:21:57 +00:00
|
|
|
async function build({ server, settings }) {
|
2022-07-11 09:20:44 +00:00
|
|
|
const serverDomain = server.settings.domain || 'localhost';
|
|
|
|
const serverPort = server.settings.port || 80;
|
|
|
|
const serverBase = `${serverDomain}:${serverPort}`;
|
2022-07-09 11:10:08 +00:00
|
|
|
let cssOutput = '';
|
2022-07-08 15:17:17 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
const bundle = await rollup({
|
2022-07-11 13:00:05 +00:00
|
|
|
input: __dirname + '/../../gui/dashboard/index.js',
|
2022-07-09 10:46:59 +00:00
|
|
|
plugins: [
|
2022-07-09 11:10:08 +00:00
|
|
|
// Svelte
|
2022-07-09 10:46:59 +00:00
|
|
|
svelte({
|
|
|
|
compilerOptions: {
|
|
|
|
dev: false,
|
|
|
|
generate: 'dom',
|
2022-07-08 15:17:17 +00:00
|
|
|
},
|
2022-07-09 10:46:59 +00:00
|
|
|
}),
|
2022-07-09 11:10:08 +00:00
|
|
|
|
|
|
|
// Extract CSS
|
|
|
|
css({
|
|
|
|
output: style => cssOutput = minifyCSS(style),
|
|
|
|
}),
|
|
|
|
|
|
|
|
// Resolve dependencies
|
2022-07-09 10:46:59 +00:00
|
|
|
resolve({
|
|
|
|
browser: true,
|
|
|
|
dedupe: [ 'svelte' ],
|
|
|
|
}),
|
2022-07-09 11:10:08 +00:00
|
|
|
|
|
|
|
// CommonJS functions
|
2022-07-09 10:46:59 +00:00
|
|
|
commonjs(),
|
2022-07-09 11:10:08 +00:00
|
|
|
|
|
|
|
// Minify
|
2022-07-09 10:46:59 +00:00
|
|
|
terser(),
|
2022-07-11 09:20:44 +00:00
|
|
|
|
|
|
|
// Replace env vars
|
|
|
|
replace({
|
|
|
|
preventAssignment: false,
|
|
|
|
values: {
|
|
|
|
'__SERVER__': serverBase,
|
2022-07-11 12:21:57 +00:00
|
|
|
'__CLUSTERS__': JSON.stringify(settings.clusters),
|
2022-07-11 09:20:44 +00:00
|
|
|
},
|
|
|
|
}),
|
2022-07-09 10:46:59 +00:00
|
|
|
],
|
2022-07-08 15:17:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const { output } = await bundle.generate({
|
|
|
|
sourcemap: true,
|
|
|
|
format: 'iife',
|
|
|
|
name: 'app',
|
|
|
|
file: 'public/build/bundle.js',
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
2022-07-11 12:21:57 +00:00
|
|
|
map: output[0].map.toUrl(),
|
2022-07-08 15:17:17 +00:00
|
|
|
code: output[0].code,
|
2022-07-09 10:46:59 +00:00
|
|
|
css: cssOutput.css,
|
2022-07-08 15:17:17 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
console.error('Error while building status dashboard: ', error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = build;
|