-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsii-pacmak.ts
More file actions
234 lines (226 loc) · 7.69 KB
/
Copy pathjsii-pacmak.ts
File metadata and controls
234 lines (226 loc) · 7.69 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/usr/bin/env node
import '@jsii/check-node/run';
import { UnknownSnippetMode } from 'jsii-rosetta';
import * as yargs from 'yargs';
import { pacmak, configureLogging, TargetName } from '../lib';
import { debug } from '../lib/logging';
import { VERSION_DESC } from '../lib/version';
(async function main() {
const argv = await yargs
.env('JSII_PACMAK')
.command(
['$0 [PROJECTS...]', 'generate [PROJECTS...]'],
'Generates jsii bindings for the selected project(s)',
(argv) =>
argv.positional('PROJECTS', {
type: 'string',
array: true,
desc: 'Project(s) to generate',
normalize: true,
default: ['.'],
}),
)
.option('targets', {
alias: ['target', 't'],
type: 'string',
array: true,
desc: 'target languages for which to generate bindings',
defaultDescription:
'all targets defined in `package.json` will be generated',
coerce: (value: string | string[]) =>
(typeof value === 'string'
? value.split(',')
: value.flatMap((item) => item.split(','))
).map((choice) => {
if (Object.values(TargetName).includes(choice as any)) {
return choice as TargetName;
}
throw new Error(
`Invalid target name: ${choice} (valid values are: ${Object.values(
TargetName,
).join(', ')})`,
);
}),
required: false,
})
.option('outdir', {
alias: 'o',
type: 'string',
desc: 'directory where artifacts will be generated',
defaultDescription: 'based on `jsii.output` in `package.json`',
required: false,
})
.option('code-only', {
alias: 'c',
type: 'boolean',
desc: 'generate code only (instead of building and packaging)',
default: false,
})
.option('runtime-type-checking', {
type: 'boolean',
desc: [
'generate runtime type checking code where compile-time type checking is not possible.',
'Disabling this will generate less code, but will produce less helpful error messages when',
'developers pass invalid values to the generated bindings.',
].join(' '),
default: true,
})
.option('fingerprint', {
type: 'boolean',
desc: 'attach a fingerprint to the generated artifacts, and skip generation if outdir contains artifacts that have a matching fingerprint',
default: true,
})
.option('force', {
alias: 'f',
type: 'boolean',
desc: 'force generation of new artifacts, even if the fingerprints match',
default: false,
})
.option('force-subdirectory', {
type: 'boolean',
desc: 'force generation into a target-named subdirectory, even in single-target mode',
default: true,
})
.option('force-target', {
type: 'boolean',
desc: 'force generation of the given targets, even if the source package.json doesnt declare it',
default: false,
})
.option('recurse', {
alias: 'R',
type: 'boolean',
desc: 'recursively generate and build all dependencies into `outdir`',
default: false,
})
.option('verbose', {
alias: 'v',
type: 'boolean',
desc: 'emit verbose build output',
count: true,
default: 0,
})
.option('clean', {
type: 'boolean',
desc: 'clean up temporary files upon success (use --no-clean to disable)',
default: true,
})
.option('npmignore', {
type: 'boolean',
desc: 'Auto-update .npmignore to exclude the output directory and include the .jsii file',
default: true,
})
.option('rosetta-tablet', {
type: 'string',
desc: "Location of a jsii-rosetta tablet with sample translations (created using 'jsii-rosetta extract')",
})
.option('rosetta-translate-live', {
type: 'boolean',
desc: "Translate code samples on-the-fly if they can't be found in the samples tablet (deprecated)",
default: undefined,
})
.option('rosetta-unknown-snippets', {
type: 'string',
requiresArg: true,
optional: true,
choices: [
UnknownSnippetMode.VERBATIM,
UnknownSnippetMode.TRANSLATE,
UnknownSnippetMode.FAIL,
],
desc: "What to do with code samples if they can't be found in the samples tablet",
})
.option('parallel', {
type: 'boolean',
desc: 'Generate all configured targets in parallel (disabling this might help if you encounter EMFILE errors)',
default: true,
})
.option('dotnet-nuget-global-packages-folder', {
type: 'string',
desc: 'Configure a different NuGet package cache for NuGet',
default: undefined,
// This is a hidden option, folks need not bother it unless they're very advanced
hidden: true,
// This is expected to be a path, which should be normalized
normalize: true,
})
.option('maven-local-repository', {
type: 'string',
desc: 'Configure a custom path (relative to current working directory) to a repository when packaging a Java package.',
defaultDescription: 'A temporary directory is used.',
default: undefined,
hidden: true,
})
.option('maven-extra-repository-id', {
type: 'string',
desc: 'ID of additional repository to add to Maven settings file',
defaultDescription: 'No extra repository is registered.',
default: undefined,
hidden: true,
})
.option('maven-extra-repository-url', {
type: 'string',
desc: 'URL of additional repository to add to Maven settings file',
defaultDescription: 'No extra repository is registered.',
default: undefined,
hidden: true,
})
.option('maven-extra-repository-username', {
type: 'string',
desc: 'Username for authenticating to extra repository',
defaultDescription: 'No extra repository is registered.',
default: undefined,
hidden: true,
})
.option('maven-extra-repository-password', {
type: 'string',
desc: 'Password for authenticating to extra repository',
defaultDescription: 'No extra repository is registered.',
default: undefined,
hidden: true,
})
.option('validate-assemblies', {
type: 'boolean',
desc: 'Whether jsii assemblies should be validated. This can be expensive and is skipped by default.',
default: false,
})
.version(VERSION_DESC)
.strict().argv;
configureLogging({ level: argv.verbose !== undefined ? argv.verbose : 0 });
// Default to 4 threads in case of concurrency, good enough for most situations
debug('command line arguments:', argv);
if (
argv['rosetta-translate-live'] !== undefined &&
argv['rosetta-unknown-snippets'] !== undefined
) {
throw new Error(
'Prefer using --rosetta-unknown-snippets over --rosetta-translate-live',
);
}
const rosettaUnknownSnippets =
argv['rosetta-unknown-snippets'] ??
(argv['rosetta-translate-live']
? UnknownSnippetMode.TRANSLATE
: UnknownSnippetMode.VERBATIM);
return pacmak({
argv,
clean: argv.clean,
codeOnly: argv['code-only'],
fingerprint: argv.fingerprint,
force: argv.force,
forceSubdirectory: argv['force-subdirectory'],
forceTarget: argv['force-target'],
inputDirectories: argv.PROJECTS,
outputDirectory: argv.outdir,
parallel: argv.parallel,
recurse: argv.recurse,
rosettaUnknownSnippets,
rosettaTablet: argv['rosetta-tablet'],
runtimeTypeChecking: argv['runtime-type-checking'],
targets: argv.targets?.map((target) => target),
updateNpmIgnoreFiles: argv.npmignore,
validateAssemblies: argv['validate-assemblies'],
});
})().catch((err) => {
process.stderr.write(`${err.stack}\n`);
process.exit(1);
});