-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathcli.ts
More file actions
executable file
·111 lines (105 loc) · 3.72 KB
/
cli.ts
File metadata and controls
executable file
·111 lines (105 loc) · 3.72 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
#!/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 colors from 'yoctocolors-cjs'
import { actionCommand } from './commands/action'
import { analyticsCommand } from './commands/analytics/analytics-command'
import { auditLogCommand } from './commands/audit-log'
import { cdxgenCommand } from './commands/cdxgen'
import { dependenciesCommand } from './commands/dependencies'
import { diffScanCommand } from './commands/diff-scan'
import { fixCommand } from './commands/fix'
import { infoCommand } from './commands/info'
import { loginCommand } from './commands/login'
import { logoutCommand } from './commands/logout'
import { manifestCommand } from './commands/manifest'
import { npmCommand } from './commands/npm'
import { npxCommand } from './commands/npx'
import { optimizeCommand } from './commands/optimize'
import { organizationCommand } from './commands/organization'
import { rawNpmCommand } from './commands/raw-npm'
import { rawNpxCommand } from './commands/raw-npx'
import { reportCommand } from './commands/report'
import { reposCommand } from './commands/repos'
import { scanCommand } from './commands/scan'
import { threatFeedCommand } from './commands/threat-feed'
import { wrapperCommand } from './commands/wrapper'
import constants from './constants'
import { AuthError, InputError } from './utils/errors'
import { logSymbols } from './utils/logging'
import { meowWithSubcommands } from './utils/meow-with-subcommands'
const { rootPkgJsonPath } = constants
// TODO: Add autocompletion using https://socket.dev/npm/package/omelette
void (async () => {
await updateNotifier({
name: 'socket',
version: require(rootPkgJsonPath).version,
ttl: 86_400_000 /* 24 hours in milliseconds */
})
try {
await meowWithSubcommands(
{
action: actionCommand,
cdxgen: cdxgenCommand,
fix: fixCommand,
info: infoCommand,
login: loginCommand,
logout: logoutCommand,
npm: npmCommand,
npx: npxCommand,
optimize: optimizeCommand,
organization: organizationCommand,
'raw-npm': rawNpmCommand,
'raw-npx': rawNpxCommand,
report: reportCommand,
wrapper: wrapperCommand,
scan: scanCommand,
'audit-log': auditLogCommand,
repos: reposCommand,
dependencies: dependenciesCommand,
analytics: analyticsCommand,
'diff-scan': diffScanCommand,
'threat-feed': threatFeedCommand,
manifest: manifestCommand
},
{
aliases: {
ci: {
description: 'Alias for "report create --view --strict"',
argv: ['report', 'create', '--view', '--strict']
}
},
argv: process.argv.slice(2),
name: 'socket',
importMeta: { url: `${pathToFileURL(__filename)}` } as ImportMeta
}
)
} catch (err) {
let errorBody: string | undefined
let errorTitle: string
let errorMessage = ''
if (err instanceof AuthError) {
errorTitle = 'Authentication error'
errorMessage = err.message
} else if (err instanceof InputError) {
errorTitle = 'Invalid input'
errorMessage = err.message
errorBody = err.body
} else if (err instanceof Error) {
errorTitle = 'Unexpected error'
errorMessage = messageWithCauses(err)
errorBody = stackWithCauses(err)
} else {
errorTitle = 'Unexpected error with no details'
}
console.error(
`${logSymbols.error} ${colors.bgRed(colors.white(errorTitle + ':'))} ${errorMessage}`
)
if (errorBody) {
console.error(`\n${errorBody}`)
}
process.exit(1)
}
})()