Skip to content

Commit d6e3a7d

Browse files
committed
Add unified build script with selective build flags
Replaces individual build:js, build:types, and build:externals scripts with a single build script that supports --js, --types, and --externals flags. Running without flags executes full build (clean + all steps + fix:exports). With flags, only specified build steps run without clean or fix:exports.
1 parent 8a1fd9b commit d6e3a7d

File tree

2 files changed

+108
-6
lines changed

2 files changed

+108
-6
lines changed

package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -715,19 +715,14 @@
715715
},
716716
"sideEffects": false,
717717
"scripts": {
718-
"build": "pnpm run clean && pnpm run build:js && pnpm run build:types && pnpm run build:externals && pnpm run fix:exports",
719-
"build:js": "node scripts/build-js.mjs",
720-
"build:types": "tsgo --project tsconfig.dts.json --declaration --emitDeclarationOnly",
721-
"build:externals": "node scripts/build-externals.mjs",
718+
"build": "node scripts/build.mjs",
722719
"build:watch": "node scripts/build-js.mjs --watch",
723720
"check": "node scripts/check.mjs",
724721
"claude": "node scripts/claude.mjs",
725722
"clean": "del-cli dist '**/*.tsbuildinfo'",
726723
"cover": "node scripts/cover.mjs",
727724
"dev": "pnpm run build:watch",
728725
"fix": "node scripts/fix.mjs",
729-
"fix:exports": "node scripts/fix-commonjs-exports.mjs",
730-
"fix:imports": "node scripts/fix-default-imports.mjs",
731726
"lint": "biome check .",
732727
"lint-ci": "pnpm run lint",
733728
"prepare": "husky",

scripts/build.mjs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/**
2+
* @fileoverview Build script with selective build step flags.
3+
*/
4+
5+
import { spawn } from 'node:child_process'
6+
import path from 'node:path'
7+
import { fileURLToPath } from 'node:url'
8+
9+
import { printError, printHeader } from './utils/cli-helpers.mjs'
10+
11+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
12+
const rootPath = path.join(__dirname, '..')
13+
14+
/**
15+
* Run a command and return a promise that resolves when it completes.
16+
*/
17+
function runCommand(command, args, label) {
18+
return new Promise((resolve, reject) => {
19+
printHeader(label)
20+
const child = spawn(command, args, {
21+
stdio: 'inherit',
22+
cwd: rootPath,
23+
...(process.platform === 'win32' && { shell: true }),
24+
})
25+
26+
child.on('exit', code => {
27+
if (code === 0) {
28+
resolve()
29+
} else {
30+
reject(new Error(`${label} exited with code ${code}`))
31+
}
32+
})
33+
34+
child.on('error', error => {
35+
printError(`${label} failed: ${error.message}`)
36+
reject(error)
37+
})
38+
})
39+
}
40+
41+
// Parse command line flags
42+
const args = process.argv.slice(2)
43+
const flags = {
44+
js: args.includes('--js'),
45+
types: args.includes('--types'),
46+
externals: args.includes('--externals'),
47+
}
48+
49+
// If no flags specified, run all steps
50+
const runAll = !flags.js && !flags.types && !flags.externals
51+
52+
// Run build steps
53+
async function main() {
54+
try {
55+
// Clean first if running full build
56+
if (runAll) {
57+
await runCommand(
58+
'pnpm',
59+
['run', 'clean'],
60+
'Cleaning Build Artifacts',
61+
)
62+
}
63+
64+
// Build JS
65+
if (runAll || flags.js) {
66+
await runCommand(
67+
'node',
68+
[path.join(__dirname, 'build-js.mjs')],
69+
'Building JavaScript',
70+
)
71+
}
72+
73+
// Build types
74+
if (runAll || flags.types) {
75+
await runCommand(
76+
'pnpm',
77+
['exec', 'tsgo', '--project', 'tsconfig.dts.json', '--declaration', '--emitDeclarationOnly'],
78+
'Building Types',
79+
)
80+
}
81+
82+
// Build externals
83+
if (runAll || flags.externals) {
84+
await runCommand(
85+
'node',
86+
[path.join(__dirname, 'build-externals.mjs')],
87+
'Building Externals',
88+
)
89+
}
90+
91+
// Fix exports at the end if running full build
92+
if (runAll) {
93+
await runCommand(
94+
'pnpm',
95+
['run', 'fix:exports'],
96+
'Fixing CommonJS Exports',
97+
)
98+
}
99+
100+
process.exitCode = 0
101+
} catch (error) {
102+
printError(`Build script failed: ${error.message}`)
103+
process.exitCode = 1
104+
}
105+
}
106+
107+
main()

0 commit comments

Comments
 (0)