-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathbuild-js.mjs
More file actions
54 lines (46 loc) · 1.3 KB
/
build-js.mjs
File metadata and controls
54 lines (46 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* @fileoverview Build script for CLI JavaScript bundle.
* Orchestrates extraction, building, and validation.
*/
import { copyFileSync } from 'node:fs'
import { getDefaultLogger } from '@socketsecurity/lib/logger'
import { spawn } from '@socketsecurity/lib/spawn'
const logger = getDefaultLogger()
async function main() {
try {
// Step 1: Build with esbuild.
logger.step('Building CLI bundle')
const buildResult = await spawn(
'node',
['--max-old-space-size=8192', '.config/esbuild.build.mjs', 'cli'],
{ stdio: 'inherit' },
)
if (!buildResult) {
logger.error('Failed to start CLI build')
process.exitCode = 1
return
}
if (buildResult.code !== 0) {
process.exitCode = buildResult.code
return
}
// Step 3: Copy bundle to dist/.
copyFileSync('build/cli.js', 'dist/cli.js')
// Step 4: Validate bundle.
logger.step('Validating bundle')
const validateResult = await spawn(
'node',
['scripts/validate-bundle.mjs'],
{ stdio: 'inherit' },
)
if (validateResult.code !== 0) {
process.exitCode = validateResult.code
return
}
logger.success('Build completed successfully')
} catch (error) {
logger.error(`Build failed: ${error.message}`)
process.exitCode = 1
}
}
main()