This commit is contained in:
73
scripts/admin-web-build.mjs
Normal file
73
scripts/admin-web-build.mjs
Normal file
@@ -0,0 +1,73 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user