42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
const { spawnSync } = require('node:child_process');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const clientRoot = path.resolve(__dirname, '..');
|
|
const embeddedRoot = path.join(clientRoot, 'embedded/sgrobot-digital');
|
|
const outputRoot = path.join(clientRoot, 'public/sgrobot-digital');
|
|
|
|
function run(command, args, options = {}) {
|
|
const result = spawnSync(command, args, {
|
|
cwd: options.cwd,
|
|
stdio: 'inherit',
|
|
shell: false,
|
|
});
|
|
if (result.status !== 0) {
|
|
process.exit(result.status || 1);
|
|
}
|
|
}
|
|
|
|
function main() {
|
|
const packageJson = path.join(embeddedRoot, 'package.json');
|
|
const nodeModules = path.join(embeddedRoot, 'node_modules');
|
|
if (!fs.existsSync(packageJson)) {
|
|
throw new Error(`Missing embedded package: ${packageJson}`);
|
|
}
|
|
if (!fs.existsSync(nodeModules)) {
|
|
console.error('Missing embedded dependencies.');
|
|
console.error(`Run: npm --prefix ${path.relative(clientRoot, embeddedRoot)} install`);
|
|
process.exit(1);
|
|
}
|
|
|
|
run('npm', ['run', 'build'], { cwd: embeddedRoot });
|
|
|
|
if (!fs.existsSync(path.join(outputRoot, 'index.html'))) {
|
|
throw new Error(`Build did not produce ${path.join(outputRoot, 'index.html')}`);
|
|
}
|
|
}
|
|
|
|
main();
|