-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathoutput-patch-result.mts
More file actions
47 lines (38 loc) · 1.2 KB
/
output-patch-result.mts
File metadata and controls
47 lines (38 loc) · 1.2 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
import { getDefaultLogger } from '@socketsecurity/lib/logger'
import { pluralize } from '@socketsecurity/lib/words'
import { OUTPUT_JSON } from '../../constants/cli.mts'
import { failMsgWithBadge } from '../../utils/error/fail-msg-with-badge.mts'
import { serializeResultJson } from '../../utils/output/result-json.mjs'
import type { CResult, OutputKind } from '../../types.mts'
const logger = getDefaultLogger()
export async function outputPatchResult(
result: CResult<{ patched: string[] }>,
outputKind: OutputKind,
) {
if (!result.ok) {
process.exitCode = result.code ?? 1
}
if (outputKind === OUTPUT_JSON) {
logger.log(serializeResultJson(result))
return
}
if (!result.ok) {
logger.fail(failMsgWithBadge(result.message, result.cause))
return
}
const { patched } = result.data
logger.log('')
if (patched.length) {
logger.group(
`Successfully processed patches for ${patched.length} ${pluralize('package', { count: patched.length })}:`,
)
for (const pkg of patched) {
logger.success(pkg)
}
logger.groupEnd()
} else {
logger.warn('No packages found requiring patches.')
}
logger.log('')
logger.success('Patch command completed!')
}