-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathcli.ts
More file actions
executable file
·118 lines (111 loc) · 4.18 KB
/
cli.ts
File metadata and controls
executable file
·118 lines (111 loc) · 4.18 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env node
import process from 'node:process'
import { pathToFileURL } from 'node:url'
import { messageWithCauses, stackWithCauses } from 'pony-cause'
import updateNotifier from 'tiny-updater'
import { debugLog } from '@socketsecurity/registry/lib/debug'
import { logger } from '@socketsecurity/registry/lib/logger'
import { cmdAnalytics } from './commands/analytics/cmd-analytics'
import { cmdAuditLog } from './commands/audit-log/cmd-audit-log'
import { cmdCdxgen } from './commands/cdxgen/cmd-cdxgen'
import { cmdConfig } from './commands/config/cmd-config'
import { cmdScanCreate } from './commands/dependencies/cmd-dependencies'
import { cmdDiffScan } from './commands/diff-scan/cmd-diff-scan'
import { cmdFix } from './commands/fix/cmd-fix'
import { cmdInfo } from './commands/info/cmd-info'
import { cmdLogin } from './commands/login/cmd-login'
import { cmdLogout } from './commands/logout/cmd-logout'
import { cmdManifest } from './commands/manifest/cmd-manifest'
import { cmdNpm } from './commands/npm/cmd-npm'
import { cmdNpx } from './commands/npx/cmd-npx'
import { cmdOops } from './commands/oops/cmd-oops'
import { cmdOptimize } from './commands/optimize/cmd-optimize'
import { cmdOrganization } from './commands/organization/cmd-organization'
import { cmdPackage } from './commands/package/cmd-package'
import { cmdRawNpm } from './commands/raw-npm/cmd-raw-npm'
import { cmdRawNpx } from './commands/raw-npx/cmd-raw-npx'
import { cmdReport } from './commands/report/cmd-report'
import { cmdRepos } from './commands/repos/cmd-repos'
import { cmdScan } from './commands/scan/cmd-scan'
import { cmdThreatFeed } from './commands/threat-feed/cmd-threat-feed'
import { cmdWrapper } from './commands/wrapper/cmd-wrapper'
import constants from './constants'
import { AuthError, InputError, captureException } from './utils/errors'
import { failMsgWithBadge } from './utils/fail-msg-with-badge'
import { meowWithSubcommands } from './utils/meow-with-subcommands'
const { SOCKET_CLI_BIN_NAME } = constants
// TODO: Add autocompletion using https://socket.dev/npm/package/omelette
void (async () => {
await updateNotifier({
name: SOCKET_CLI_BIN_NAME,
// The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
version: process.env['INLINED_SOCKET_CLI_VERSION']!,
ttl: 86_400_000 /* 24 hours in milliseconds */
})
try {
await meowWithSubcommands(
{
cdxgen: cmdCdxgen,
config: cmdConfig,
fix: cmdFix,
info: cmdInfo,
login: cmdLogin,
logout: cmdLogout,
npm: cmdNpm,
npx: cmdNpx,
oops: cmdOops,
optimize: cmdOptimize,
organization: cmdOrganization,
package: cmdPackage,
'raw-npm': cmdRawNpm,
'raw-npx': cmdRawNpx,
report: cmdReport,
wrapper: cmdWrapper,
scan: cmdScan,
'audit-log': cmdAuditLog,
repos: cmdRepos,
dependencies: cmdScanCreate,
analytics: cmdAnalytics,
'diff-scan': cmdDiffScan,
'threat-feed': cmdThreatFeed,
manifest: cmdManifest
},
{
aliases: {
ci: {
description: 'Alias for "report create --view --strict"',
argv: ['report', 'create', '--view', '--strict']
}
},
argv: process.argv.slice(2),
name: SOCKET_CLI_BIN_NAME,
importMeta: { url: `${pathToFileURL(__filename)}` } as ImportMeta
}
)
} catch (e) {
process.exitCode = 1
let errorBody: string | undefined
let errorTitle: string
let errorMessage = ''
if (e instanceof AuthError) {
errorTitle = 'Authentication error'
errorMessage = e.message
} else if (e instanceof InputError) {
errorTitle = 'Invalid input'
errorMessage = e.message
errorBody = e.body
} else if (e instanceof Error) {
errorTitle = 'Unexpected error'
errorMessage = messageWithCauses(e)
errorBody = stackWithCauses(e)
} else {
errorTitle = 'Unexpected error with no details'
}
logger.error('\n') // Any-spinner-newline
logger.fail(failMsgWithBadge(errorTitle, errorMessage))
if (errorBody) {
debugLog(`${errorBody}`)
}
await captureException(e)
}
})()