-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathCommandLineOptions.ts
More file actions
96 lines (88 loc) · 3.12 KB
/
CommandLineOptions.ts
File metadata and controls
96 lines (88 loc) · 3.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
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
import * as commander from 'commander'
import ts from 'typescript'
import packageJson from '../package.json'
import { parseHumanByteSizeIntoNumber } from './parseHumanByteSizeIntoNumber'
import * as scip from './scip'
/** Configuration options to index a multi-project workspace. */
export interface MultiProjectOptions {
inferTsconfig: boolean
progressBar: boolean
yarnWorkspaces: boolean
yarnBerryWorkspaces: boolean
pnpmWorkspaces: boolean
globalCaches: boolean
maxFileByteSize?: string
maxFileByteSizeNumber?: number
cwd: string
output: string
indexedProjects: Set<string>
}
/** Configuration options to index a single TypeScript project. */
export interface ProjectOptions extends MultiProjectOptions {
projectRoot: string
projectDisplayName: string
writeIndex: (index: scip.scip.Index) => void
}
/** Cached values */
export interface GlobalCache {
sources: Map<
string,
[ts.SourceFile | undefined, ts.ScriptTarget | ts.CreateSourceFileOptions]
>
parsedCommandLines: Map<string, ts.ParsedCommandLine>
}
export function mainCommand(
indexAction: (projects: string[], options: MultiProjectOptions) => void
): commander.Command {
const command = new commander.Command()
command
.name('scip-typescript')
.version(packageJson.version)
.description(
'SCIP indexer for TypeScript and JavaScript\nFor usage examples, see https://github.com/sourcegraph/scip-typescript/blob/main/README.md'
)
command
.command('index')
.option('--cwd <path>', 'the working directory', process.cwd())
.option('--pnpm-workspaces', 'whether to index all pnpm workspaces', false)
.option('--yarn-workspaces', 'whether to index all yarn workspaces', false)
.option(
'--yarn-berry-workspaces',
'(deprecated) use --yarn-workspaces instead',
false
)
.option(
'--infer-tsconfig',
"whether to infer the tsconfig.json file, if it's missing",
false
)
.option('--output <path>', 'path to the output file', 'index.scip')
.option('--progress-bar', 'whether to enable a rich progress bar')
.option('--no-progress-bar', 'whether to disable the rich progress bar')
.option(
'--no-global-caches',
'whether to disable global caches between TypeScript projects'
)
.option(
'--max-file-byte-size <value>',
'skip files that have a larger byte size than the provided value. Supported formats: 1kb, 1mb, 1gb.',
'1mb'
)
.argument('[projects...]')
.action((parsedProjects, parsedOptions) => {
const options = parsedOptions as MultiProjectOptions
// Parse and validate human-provided --max-file-byte-size value
options.maxFileByteSizeNumber = parseHumanByteSizeIntoNumber(
options.maxFileByteSize ?? '1mb'
)
if (isNaN(options.maxFileByteSizeNumber)) {
console.error(
`invalid byte size '${options.maxFileByteSize}'. To fix this problem, change the value of the flag --max-file-byte-size to use a valid byte size format: 1kb, 1mb, 1gb.`
)
process.exitCode = 1
return
}
indexAction(parsedProjects as string[], options)
})
return command
}