refactor(server): use util.parseArgs for declarative CLI arg parsing in compile.ts
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { rm } from 'node:fs/promises'
|
||||
import process from 'node:process'
|
||||
import { parseArgs } from 'node:util'
|
||||
|
||||
const ENTRYPOINT = '.output/server/index.mjs'
|
||||
const OUTDIR = 'out'
|
||||
@@ -23,16 +23,20 @@ const HOST_MAP: Record<string, Target> = {
|
||||
'linux-arm64': 'bun-linux-arm64',
|
||||
}
|
||||
|
||||
const { values } = parseArgs({
|
||||
options: { target: { type: 'string' } },
|
||||
strict: true,
|
||||
allowPositionals: false,
|
||||
})
|
||||
|
||||
const resolveTarget = (): Target => {
|
||||
const idx = process.argv.indexOf('--target')
|
||||
if (idx !== -1) {
|
||||
const value = process.argv[idx + 1]
|
||||
if (!isTarget(value)) {
|
||||
if (values.target !== undefined) {
|
||||
if (!isTarget(values.target)) {
|
||||
throw new Error(
|
||||
`Invalid target: ${value}\nAllowed: ${Object.keys(TARGETS).join(', ')}`,
|
||||
`Invalid target: ${values.target}\nAllowed: ${Object.keys(TARGETS).join(', ')}`,
|
||||
)
|
||||
}
|
||||
return value
|
||||
return values.target
|
||||
}
|
||||
|
||||
const key = `${process.platform}-${process.arch}`
|
||||
|
||||
Reference in New Issue
Block a user