-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathoutput-cmd-json.mts
More file actions
38 lines (30 loc) · 1.12 KB
/
output-cmd-json.mts
File metadata and controls
38 lines (30 loc) · 1.12 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
import fs from 'node:fs'
import path from 'node:path'
import { safeReadFileSync, safeStatsSync } from '@socketsecurity/lib/fs'
import { getDefaultLogger } from '@socketsecurity/lib/logger'
import { REDACTED } from '../../constants/cli.mts'
import { VITEST } from '../../env/vitest.mts'
import { SOCKET_JSON } from '../../constants/socket.mts'
import { tildify } from '../../utils/fs/home-path.mjs'
const logger = getDefaultLogger()
export async function outputCmdJson(cwd: string) {
logger.info('Target cwd:', VITEST ? REDACTED : tildify(cwd))
const sockJsonPath = path.join(cwd, SOCKET_JSON)
const tildeSockJsonPath = VITEST ? REDACTED : tildify(sockJsonPath)
if (!fs.existsSync(sockJsonPath)) {
logger.fail(`Not found: ${tildeSockJsonPath}`)
process.exitCode = 1
return
}
if (!safeStatsSync(sockJsonPath)?.isFile()) {
logger.fail(
`This is not a regular file (maybe a directory?): ${tildeSockJsonPath}`,
)
process.exitCode = 1
return
}
logger.success(`This is the contents of ${tildeSockJsonPath}:`)
logger.error('')
const data = safeReadFileSync(sockJsonPath)
logger.log(data)
}