Skip to content

Commit 8b6157b

Browse files
committed
refactor: implement unified build command pattern
Replace separate build:* commands with single build command that accepts --target flag for routing to different packages. Usage: - pnpm run build (defaults to CLI) - pnpm run build -- --target all - pnpm run build -- --target node - pnpm run build -- --target sea - pnpm run build -- --target socket All other flags are passed through to the target package build script.
1 parent b135e46 commit 8b6157b

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,7 @@
177177
},
178178
"private": true,
179179
"scripts": {
180-
"build": "pnpm --filter @socketsecurity/cli run build --",
181-
"build:all": "pnpm --filter \"./packages/**\" run build",
182-
"build:cli": "pnpm run build --",
183-
"build:node": "pnpm --filter @socketbin/custom-node run build --",
184-
"build:sea": "pnpm --filter @socketbin/sea run build --",
185-
"build:socket": "pnpm --filter socket run build --",
180+
"build": "node scripts/build.mjs",
186181
"check": "pnpm --filter @socketsecurity/cli run check --",
187182
"check-ci": "pnpm run check -- --ci",
188183
"clean": "pnpm --filter \"./packages/**\" run clean",

scripts/build.mjs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Unified build script router.
5+
* Routes build commands to appropriate packages based on --target flag.
6+
*/
7+
8+
import { spawnSync } from 'node:child_process'
9+
import process from 'node:process'
10+
11+
const TARGET_PACKAGES = {
12+
__proto__: null,
13+
all: './packages/**',
14+
cli: '@socketsecurity/cli',
15+
node: '@socketbin/custom-node',
16+
sea: '@socketbin/sea',
17+
socket: 'socket'
18+
}
19+
20+
const args = process.argv.slice(2)
21+
let target = 'cli'
22+
const buildArgs = []
23+
24+
for (let i = 0; i < args.length; i++) {
25+
const arg = args[i]
26+
if (arg === '--target' && i + 1 < args.length) {
27+
target = args[++i]
28+
} else {
29+
buildArgs.push(arg)
30+
}
31+
}
32+
33+
const packageFilter = TARGET_PACKAGES[target]
34+
if (!packageFilter) {
35+
console.error(`Unknown build target: ${target}`)
36+
console.error(`Available targets: ${Object.keys(TARGET_PACKAGES).join(', ')}`)
37+
process.exit(1)
38+
}
39+
40+
const pnpmArgs = [
41+
'--filter',
42+
packageFilter,
43+
'run',
44+
'build',
45+
...buildArgs
46+
]
47+
48+
const result = spawnSync('pnpm', pnpmArgs, {
49+
encoding: 'utf8',
50+
shell: false,
51+
stdio: 'inherit'
52+
})
53+
54+
process.exit(result.status ?? 1)

0 commit comments

Comments
 (0)