chore(scripts): add parallel build scripts

Replace sequential `npm run build --workspaces --if-present` with
concurrent execution via a reusable `parallelTask` utility. Full
`npm run build` now runs cleanup then all 7 build tasks in parallel.
This commit is contained in:
Simon
2026-04-15 17:44:37 +08:00
parent cc27ff9305
commit 9af3a3f73e
4 changed files with 187 additions and 2 deletions

45
scripts/build.js Normal file
View File

@@ -0,0 +1,45 @@
#!/usr/bin/env node
/**
* Full build pipeline. Equivalent to:
* npm run cleanup && npm run build --workspaces --if-present
* && npm run build:website -w @page-agent/website
* && npm run zip -w @page-agent/ext
*
* 1. cleanup
* 2. build everything in parallel (libs + website + extension)
*/
import chalk from 'chalk'
import { execSync } from 'child_process'
import { readFileSync } from 'fs'
import { dirname, join } from 'path'
import { fileURLToPath } from 'url'
import { parallelTask } from './parallel-task.js'
const rootDir = join(dirname(fileURLToPath(import.meta.url)), '..')
const rootPkg = JSON.parse(readFileSync(join(rootDir, 'package.json'), 'utf-8'))
// Step 1: cleanup
console.log(chalk.bgBlue.white.bold(' ▸ cleanup '))
execSync('npm run cleanup', { cwd: rootDir, stdio: 'inherit' })
// Step 2: build all in parallel
console.log(chalk.bgBlue.white.bold(' ▸ build '))
const tasks = rootPkg.workspaces
.map((ws) => {
const dir = join(rootDir, ws)
const pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf-8'))
return pkg.scripts?.build ? { label: pkg.name, command: 'npm run build', cwd: dir } : null
})
.filter(Boolean)
tasks.push(
{
label: '@page-agent/website',
command: 'npm run build:website',
cwd: join(rootDir, 'packages/website'),
},
{ label: '@page-agent/ext', command: 'npm run zip', cwd: join(rootDir, 'packages/extension') }
)
await parallelTask(tasks, { timeoutMs: 120_000 })