-
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.77 KB
/
cli.ts
File metadata and controls
executable file
·111 lines (105 loc) · 3.77 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 { cmdAction } from './commands/action/cmd-action.ts'
import { cmdAnalytics } from './commands/analytics/cmd-analytics.ts'
import { cmdAuditLog } from './commands/audit-log/cmd-audit-log.ts'
import { cmdCdxgen } from './commands/cdxgen/cmd-cdxgen.ts'
import { cmdScanCreate } from './commands/dependencies/cmd-dependencies.ts'
import { cmdDiffScan } from './commands/diff-scan/cmd-diff-scan.ts'
import { cmdFix } from './commands/fix/cmd-fix.ts'
import { cmdInfo } from './commands/info/cmd-info.ts'
import { loginCommand } from './commands/login'
import { logoutCommand } from './commands/logout'
import { cmdManifest } from './commands/manifest/cmd-manifest.ts'
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 { cmdReport } from './commands/report/cmd-report.ts'
import { cmdRepos } from './commands/repos/cmd-repos.ts'
import { cmdScan } from './commands/scan/cmd-scan.ts'
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: cmdAction,
cdxgen: cmdCdxgen,
fix: cmdFix,
info: cmdInfo,
login: loginCommand,
logout: logoutCommand,
npm: npmCommand,
npx: npxCommand,
optimize: optimizeCommand,
organization: organizationCommand,
'raw-npm': rawNpmCommand,
'raw-npx': rawNpxCommand,
report: cmdReport,
wrapper: wrapperCommand,
scan: cmdScan,
'audit-log': cmdAuditLog,
repos: cmdRepos,
dependencies: cmdScanCreate,
analytics: cmdAnalytics,
'diff-scan': cmdDiffScan,
'threat-feed': threatFeedCommand,
manifest: cmdManifest
},
{
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)
}
})()