Skip to content

Commit 3d663c5

Browse files
authored
Minor code shuffle in run-cdxgen (#551)
1 parent ddd50ff commit 3d663c5

2 files changed

Lines changed: 32 additions & 32 deletions

File tree

src/commands/cdxgen/cmd-cdxgen.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import yargsParse from 'yargs-parser'
44
import { logger } from '@socketsecurity/registry/lib/logger'
55
import { pluralize } from '@socketsecurity/registry/lib/words'
66

7-
import { runCycloneDX } from './run-cyclonedx.mts'
7+
import { runCdxgen } from './run-cdxgen.mts'
88
import constants from '../../constants.mts'
99
import { isHelpFlag } from '../../utils/cmd.mts'
1010
import { meowOrExit } from '../../utils/meow-with-subcommands.mts'
@@ -289,5 +289,5 @@ async function run(
289289
}
290290
}
291291

292-
await runCycloneDX(yargv)
292+
await runCdxgen(yargv)
293293
}
Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,36 @@ const nodejsPlatformTypes = new Set([
2121
'typescript'
2222
])
2323

24-
export async function runCycloneDX(yargvWithYes: any) {
24+
function argvToArray(argv: {
25+
[key: string]: boolean | null | number | string | Array<string | number>
26+
}): string[] {
27+
if (argv['help']) {
28+
return ['--help']
29+
}
30+
const result = []
31+
for (const { 0: key, 1: value } of Object.entries(argv)) {
32+
if (key === '_' || key === '--') {
33+
continue
34+
}
35+
if (key === 'babel' || key === 'install-deps' || key === 'validate') {
36+
// cdxgen documents no-babel, no-install-deps, and no-validate flags so
37+
// use them when relevant.
38+
result.push(`--${value ? key : `no-${key}`}`)
39+
} else if (value === true) {
40+
result.push(`--${key}`)
41+
} else if (typeof value === 'string') {
42+
result.push(`--${key}`, String(value))
43+
} else if (Array.isArray(value)) {
44+
result.push(`--${key}`, ...value.map(String))
45+
}
46+
}
47+
if (argv['--']) {
48+
result.push('--', ...(argv as any)['--'])
49+
}
50+
return result
51+
}
52+
53+
export async function runCdxgen(yargvWithYes: any) {
2554
let cleanupPackageLock = false
2655
const { yes, ...yargv } = { __proto__: null, ...yargvWithYes } as any
2756
const yesArgs = yes ? ['--yes'] : []
@@ -64,32 +93,3 @@ export async function runCycloneDX(yargvWithYes: any) {
6493
logger.log(colors.cyanBright(`${yargv.output} created!`))
6594
}
6695
}
67-
68-
function argvToArray(argv: {
69-
[key: string]: boolean | null | number | string | Array<string | number>
70-
}): string[] {
71-
if (argv['help']) {
72-
return ['--help']
73-
}
74-
const result = []
75-
for (const { 0: key, 1: value } of Object.entries(argv)) {
76-
if (key === '_' || key === '--') {
77-
continue
78-
}
79-
if (key === 'babel' || key === 'install-deps' || key === 'validate') {
80-
// cdxgen documents no-babel, no-install-deps, and no-validate flags so
81-
// use them when relevant.
82-
result.push(`--${value ? key : `no-${key}`}`)
83-
} else if (value === true) {
84-
result.push(`--${key}`)
85-
} else if (typeof value === 'string') {
86-
result.push(`--${key}`, String(value))
87-
} else if (Array.isArray(value)) {
88-
result.push(`--${key}`, ...value.map(String))
89-
}
90-
}
91-
if (argv['--']) {
92-
result.push('--', ...(argv as any)['--'])
93-
}
94-
return result
95-
}

0 commit comments

Comments
 (0)