74 lines
1.8 KiB
JavaScript
74 lines
1.8 KiB
JavaScript
import {spawnSync} from 'node:child_process';
|
|
import {dirname, resolve} from 'node:path';
|
|
import {fileURLToPath} from 'node:url';
|
|
|
|
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
|
const repoRoot = resolve(scriptDir, '..');
|
|
const adminWebDir = resolve(repoRoot, 'apps/admin-web');
|
|
const adminTsconfigPath = resolve(adminWebDir, 'tsconfig.json');
|
|
const adminViteConfigPath = resolve(adminWebDir, 'vite.config.ts');
|
|
const tscBinPath = resolve(repoRoot, 'node_modules/typescript/bin/tsc');
|
|
const viteCliPath = resolve(scriptDir, 'vite-cli.mjs');
|
|
|
|
const command = process.argv[2] ?? 'build';
|
|
const extraArgs = process.argv.slice(3);
|
|
|
|
function usage() {
|
|
console.error('用法: node scripts/admin-web-build.mjs <typecheck|build> [vite-build-args...]');
|
|
}
|
|
|
|
function runNodeScript(label, args) {
|
|
console.log(`[admin-web] ${label}`);
|
|
const result = spawnSync(process.execPath, args, {
|
|
cwd: repoRoot,
|
|
encoding: 'utf8',
|
|
});
|
|
|
|
if (result.stdout) {
|
|
process.stdout.write(result.stdout);
|
|
}
|
|
|
|
if (result.stderr) {
|
|
process.stderr.write(result.stderr);
|
|
}
|
|
|
|
if (result.error) {
|
|
console.error(`[admin-web] ${label} failed to start: ${result.error.message}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
if (result.signal) {
|
|
console.error(`[admin-web] ${label} was terminated by signal ${result.signal}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
if ((result.status ?? 0) !== 0) {
|
|
process.exit(result.status ?? 1);
|
|
}
|
|
}
|
|
|
|
function runTypecheck() {
|
|
runNodeScript('typecheck', [
|
|
tscBinPath,
|
|
'--noEmit',
|
|
'-p',
|
|
adminTsconfigPath,
|
|
]);
|
|
}
|
|
|
|
if (command === 'typecheck') {
|
|
runTypecheck();
|
|
} else if (command === 'build') {
|
|
runTypecheck();
|
|
runNodeScript('vite build', [
|
|
viteCliPath,
|
|
'build',
|
|
'--config',
|
|
adminViteConfigPath,
|
|
...extraArgs,
|
|
]);
|
|
} else {
|
|
usage();
|
|
process.exit(1);
|
|
}
|