@openapi-qraft/plugin 2.15.0-beta.0 → 2.15.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/dist/lib/QraftCommand.d.ts +8 -62
- package/dist/lib/QraftCommand.d.ts.map +1 -1
- package/dist/lib/QraftCommand.js +30 -193
- package/dist/lib/QraftCommand.js.map +1 -1
- package/dist/lib/QraftCommandPlugin.d.ts +2 -6
- package/dist/lib/QraftCommandPlugin.d.ts.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/package.json +5 -4
- package/src/lib/QraftCommand.ts +58 -381
- package/src/lib/QraftCommandPlugin.ts +2 -11
- package/src/packageVersion.ts +1 -1
- package/dist/lib/GeneratorFile.d.ts +0 -9
- package/dist/lib/GeneratorFile.d.ts.map +0 -1
- package/dist/lib/GeneratorFile.js +0 -2
- package/dist/lib/GeneratorFile.js.map +0 -1
- package/dist/lib/OutputOptions.d.ts +0 -6
- package/dist/lib/OutputOptions.d.ts.map +0 -1
- package/dist/lib/OutputOptions.js +0 -2
- package/dist/lib/OutputOptions.js.map +0 -1
- package/dist/lib/RedoclyConfigCommand.d.ts +0 -22
- package/dist/lib/RedoclyConfigCommand.d.ts.map +0 -1
- package/dist/lib/RedoclyConfigCommand.js +0 -133
- package/dist/lib/RedoclyConfigCommand.js.map +0 -1
- package/dist/lib/fileHeader.d.ts +0 -2
- package/dist/lib/fileHeader.d.ts.map +0 -1
- package/dist/lib/fileHeader.js +0 -7
- package/dist/lib/fileHeader.js.map +0 -1
- package/dist/lib/formatFileHeader.d.ts +0 -2
- package/dist/lib/formatFileHeader.d.ts.map +0 -1
- package/dist/lib/formatFileHeader.js +0 -6
- package/dist/lib/formatFileHeader.js.map +0 -1
- package/dist/lib/getRedocAPIsToQraft.d.ts +0 -16
- package/dist/lib/getRedocAPIsToQraft.d.ts.map +0 -1
- package/dist/lib/getRedocAPIsToQraft.js +0 -45
- package/dist/lib/getRedocAPIsToQraft.js.map +0 -1
- package/dist/lib/handleSchemaInput.d.ts +0 -10
- package/dist/lib/handleSchemaInput.d.ts.map +0 -1
- package/dist/lib/handleSchemaInput.js +0 -40
- package/dist/lib/handleSchemaInput.js.map +0 -1
- package/dist/lib/loadRedoclyConfig.d.ts +0 -12
- package/dist/lib/loadRedoclyConfig.d.ts.map +0 -1
- package/dist/lib/loadRedoclyConfig.js +0 -17
- package/dist/lib/loadRedoclyConfig.js.map +0 -1
- package/dist/lib/maybeEscapeShellArg.d.ts +0 -2
- package/dist/lib/maybeEscapeShellArg.d.ts.map +0 -1
- package/dist/lib/maybeEscapeShellArg.js +0 -9
- package/dist/lib/maybeEscapeShellArg.js.map +0 -1
- package/dist/lib/parseConfigToArgs.d.ts +0 -7
- package/dist/lib/parseConfigToArgs.d.ts.map +0 -1
- package/dist/lib/parseConfigToArgs.js +0 -130
- package/dist/lib/parseConfigToArgs.js.map +0 -1
- package/dist/lib/shouldQuoteCommandLineArg.d.ts +0 -11
- package/dist/lib/shouldQuoteCommandLineArg.d.ts.map +0 -1
- package/dist/lib/shouldQuoteCommandLineArg.js +0 -33
- package/dist/lib/shouldQuoteCommandLineArg.js.map +0 -1
- package/dist/lib/vitestFsMock.d.ts +0 -2
- package/dist/lib/vitestFsMock.d.ts.map +0 -1
- package/dist/lib/vitestFsMock.js +0 -16
- package/dist/lib/vitestFsMock.js.map +0 -1
- package/dist/lib/writeGeneratorFiles.d.ts +0 -7
- package/dist/lib/writeGeneratorFiles.d.ts.map +0 -1
- package/dist/lib/writeGeneratorFiles.js +0 -51
- package/dist/lib/writeGeneratorFiles.js.map +0 -1
- package/src/lib/GeneratorFile.ts +0 -5
- package/src/lib/OutputOptions.ts +0 -6
- package/src/lib/RedoclyConfigCommand.ts +0 -232
- package/src/lib/fileHeader.ts +0 -6
- package/src/lib/formatFileHeader.ts +0 -4
- package/src/lib/getRedocAPIsToQraft.ts +0 -87
- package/src/lib/handleSchemaInput.ts +0 -53
- package/src/lib/loadRedoclyConfig.ts +0 -47
- package/src/lib/maybeEscapeShellArg.ts +0 -10
- package/src/lib/parseConfigToArgs.ts +0 -134
- package/src/lib/shouldQuoteCommandLineArg.ts +0 -32
- package/src/lib/vitestFsMock.ts +0 -23
- package/src/lib/writeGeneratorFiles.ts +0 -82
package/src/lib/QraftCommand.ts
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
|
-
import { sep } from 'node:path';
|
|
2
1
|
import process from 'node:process';
|
|
3
|
-
import {
|
|
2
|
+
import { URL } from 'node:url';
|
|
3
|
+
import {
|
|
4
|
+
handleSchemaInput,
|
|
5
|
+
normalizeOutputDirPath,
|
|
6
|
+
QraftCommandActionOptions,
|
|
7
|
+
QraftCommand as QraftCommandBase,
|
|
8
|
+
QraftCommandOptions,
|
|
9
|
+
splitOptionFlags,
|
|
10
|
+
} from '@qraft/plugin';
|
|
11
|
+
import {
|
|
12
|
+
getRedocAPIsToQraft,
|
|
13
|
+
OPENAPI_QRAFT_REDOC_CONFIG_KEY,
|
|
14
|
+
} from '@qraft/plugin/lib/getRedocAPIsToQraft';
|
|
15
|
+
import { loadRedoclyConfig } from '@qraft/plugin/lib/loadRedoclyConfig';
|
|
16
|
+
import { createRedoclyOption } from '@qraft/plugin/lib/RedoclyConfigCommand';
|
|
4
17
|
import { Config, createConfig, getMergedConfig } from '@redocly/openapi-core';
|
|
5
18
|
import c from 'ansi-colors';
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
19
|
+
import { CommanderError, Option } from 'commander';
|
|
20
|
+
import { Ora } from 'ora';
|
|
8
21
|
import { packageVersion } from '../packageVersion.js';
|
|
9
22
|
import { filterDocumentPaths } from './filterDocumentPaths.js';
|
|
10
|
-
import { GeneratorFile } from './GeneratorFile.js';
|
|
11
|
-
import { getRedocAPIsToQraft } from './getRedocAPIsToQraft.js';
|
|
12
|
-
import { handleSchemaInput } from './handleSchemaInput.js';
|
|
13
|
-
import { loadRedoclyConfig } from './loadRedoclyConfig.js';
|
|
14
23
|
import { getServices } from './open-api/getServices.js';
|
|
15
24
|
import { OpenAPISchemaType } from './open-api/OpenAPISchemaType.js';
|
|
16
25
|
import { OpenAPIService } from './open-api/OpenAPIService.js';
|
|
17
26
|
import { readSchema } from './open-api/readSchema.js';
|
|
18
|
-
import { OutputOptions } from './OutputOptions.js';
|
|
19
27
|
import {
|
|
20
28
|
createPredefinedParametersGlobs,
|
|
21
29
|
parseOperationPredefinedParametersOption,
|
|
@@ -25,39 +33,20 @@ import {
|
|
|
25
33
|
parseOperationNameModifier,
|
|
26
34
|
processOperationNameModifierOption,
|
|
27
35
|
} from './processOperationNameModifierOption.js';
|
|
28
|
-
import { redoclyOption } from './RedoclyConfigCommand.js';
|
|
29
36
|
import { splitCommaSeparatedGlobs } from './splitCommaSeparatedGlobs.js';
|
|
30
|
-
import { writeGeneratorFiles } from './writeGeneratorFiles.js';
|
|
31
37
|
|
|
32
|
-
export
|
|
33
|
-
static spinner = ora();
|
|
38
|
+
export { splitOptionFlags };
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @param name - not used
|
|
40
|
-
*/
|
|
41
|
-
constructor(name?: string) {
|
|
42
|
-
super(name);
|
|
43
|
-
this.cwd = pathToFileURL(`${process.cwd()}/`);
|
|
40
|
+
export class QraftCommand extends QraftCommandBase<OpenAPIQraftCommandActionOptions> {
|
|
41
|
+
constructor(name?: string, options?: QraftCommandOptions) {
|
|
42
|
+
super(name, options);
|
|
44
43
|
|
|
45
44
|
this.usage('[input] [options]')
|
|
46
45
|
.argument(
|
|
47
|
-
'[input]',
|
|
46
|
+
'[input]', // todo::why now required with <input>?
|
|
48
47
|
'Input OpenAPI Document file path, URL (json, yml)',
|
|
49
48
|
null
|
|
50
49
|
)
|
|
51
|
-
.option(
|
|
52
|
-
'-o, --output-dir <path>',
|
|
53
|
-
'Output directory for generated services'
|
|
54
|
-
)
|
|
55
|
-
.addOption(
|
|
56
|
-
new Option(
|
|
57
|
-
'-c, --clean',
|
|
58
|
-
'Clean output directory before generating services'
|
|
59
|
-
)
|
|
60
|
-
)
|
|
61
50
|
.option(
|
|
62
51
|
'--filter-services <glob-patterns...>',
|
|
63
52
|
'Filter services to be generated using glob patterns. Example: "/user/**,/post/**". For more details, see the NPM `micromatch` package documentation.'
|
|
@@ -82,24 +71,10 @@ export class QraftCommand extends Command {
|
|
|
82
71
|
'Use OpenAPI Operation `endpoint[<index>]` path part (e.g.: "/0/1/2") or `tags` as the base name of the service.',
|
|
83
72
|
'endpoint[0]'
|
|
84
73
|
)
|
|
85
|
-
.addOption(
|
|
86
|
-
new Option(
|
|
87
|
-
'--file-header <string>',
|
|
88
|
-
'Header to be added to the generated file (eg: /* eslint-disable */)'
|
|
89
|
-
)
|
|
90
|
-
)
|
|
91
|
-
.addOption(redoclyOption);
|
|
74
|
+
.addOption(createRedoclyOption());
|
|
92
75
|
}
|
|
93
76
|
|
|
94
|
-
|
|
95
|
-
this.registerPluginAction(callback);
|
|
96
|
-
return super.action(this.actionCallback.bind(this));
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async actionCallback(...actionArgs: any[]) {
|
|
100
|
-
const inputs = actionArgs.filter(
|
|
101
|
-
(arg) => typeof arg === 'string'
|
|
102
|
-
) as string[];
|
|
77
|
+
async actionCallback(...actionArgs: any[]): Promise<void> {
|
|
103
78
|
const args = actionArgs.find(
|
|
104
79
|
(arg) => arg && typeof arg === 'object'
|
|
105
80
|
) as Record<string, any>;
|
|
@@ -107,13 +82,18 @@ export class QraftCommand extends Command {
|
|
|
107
82
|
if (!args) throw new Error('Arguments object not found');
|
|
108
83
|
|
|
109
84
|
if (args.version) {
|
|
110
|
-
console.info(`v${packageVersion}`);
|
|
85
|
+
console.info(`v${packageVersion}`);
|
|
111
86
|
process.exit(0);
|
|
112
87
|
}
|
|
113
88
|
|
|
114
|
-
|
|
89
|
+
return super.actionCallback(...actionArgs);
|
|
90
|
+
}
|
|
115
91
|
|
|
116
|
-
|
|
92
|
+
protected override async prepareActionOptions(
|
|
93
|
+
inputs: string[],
|
|
94
|
+
args: Record<string, any>
|
|
95
|
+
): Promise<OpenAPIQraftCommandActionOptions> {
|
|
96
|
+
const spinner = QraftCommand.spinner;
|
|
117
97
|
|
|
118
98
|
const redoc = args.redocly
|
|
119
99
|
? getMergedConfig(
|
|
@@ -123,7 +103,6 @@ export class QraftCommand extends Command {
|
|
|
123
103
|
: await createConfig(
|
|
124
104
|
{
|
|
125
105
|
rules: {
|
|
126
|
-
// throw error on duplicate operationIDs
|
|
127
106
|
'operation-operationId-unique': { severity: 'error' },
|
|
128
107
|
},
|
|
129
108
|
},
|
|
@@ -132,7 +111,7 @@ export class QraftCommand extends Command {
|
|
|
132
111
|
|
|
133
112
|
const input = args.redocly
|
|
134
113
|
? handleRedoclySchemaInput(redoc, inputs[0], this.cwd, spinner)
|
|
135
|
-
: handleSchemaInput(inputs[0], this.cwd, spinner);
|
|
114
|
+
: handleSchemaInput(inputs[0], this.cwd, spinner, 'OpenAPI Document');
|
|
136
115
|
|
|
137
116
|
spinner.text = 'Reading OpenAPI Document...';
|
|
138
117
|
|
|
@@ -222,346 +201,40 @@ export class QraftCommand extends Command {
|
|
|
222
201
|
services = modifiedServicesOperationNames;
|
|
223
202
|
}
|
|
224
203
|
|
|
225
|
-
spinner.text = 'Generating code...';
|
|
226
|
-
|
|
227
204
|
const outputDir = normalizeOutputDirPath(args.outputDir);
|
|
228
205
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
dir: outputDir,
|
|
241
|
-
clean: args.clean,
|
|
242
|
-
},
|
|
243
|
-
},
|
|
244
|
-
resolve
|
|
245
|
-
).catch(reject);
|
|
246
|
-
}
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
try {
|
|
250
|
-
if (this.registeredPluginActions.indexOf(pluginAction) === 0) {
|
|
251
|
-
await writeGeneratorFiles({
|
|
252
|
-
// Create output directory first, but for the first plugin only
|
|
253
|
-
fileItems: [{ directory: outputDir, clean: false }, ...fileItems],
|
|
254
|
-
spinner,
|
|
255
|
-
});
|
|
256
|
-
} else {
|
|
257
|
-
await writeGeneratorFiles({ fileItems, spinner });
|
|
258
|
-
}
|
|
259
|
-
} catch (error) {
|
|
260
|
-
spinner.fail(
|
|
261
|
-
c.red('An error occurred during the code generation process.')
|
|
262
|
-
);
|
|
263
|
-
|
|
264
|
-
if (error instanceof Error) {
|
|
265
|
-
console.error(c.red(error.message), c.red(error.stack ?? ''));
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
throw error;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
spinner.succeed(c.green('Qraft process completed successfully'));
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
protected registerPluginAction(callback: QraftCommandActionCallback) {
|
|
276
|
-
this.registeredPluginActions.push(callback);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
option(
|
|
280
|
-
flags: string,
|
|
281
|
-
description?: string,
|
|
282
|
-
defaultValue?: string | boolean | string[]
|
|
283
|
-
): this;
|
|
284
|
-
option<T>(
|
|
285
|
-
flags: string,
|
|
286
|
-
description: string,
|
|
287
|
-
parseArg: (value: string, previous: T) => T,
|
|
288
|
-
defaultValue?: T
|
|
289
|
-
): this;
|
|
290
|
-
/** @deprecated since v7, instead use choices or a custom function */
|
|
291
|
-
option(
|
|
292
|
-
flags: string,
|
|
293
|
-
description: string,
|
|
294
|
-
regexp: RegExp,
|
|
295
|
-
defaultValue?: string | boolean | string[]
|
|
296
|
-
): this;
|
|
297
|
-
option<T>(
|
|
298
|
-
flags: string,
|
|
299
|
-
description?: string,
|
|
300
|
-
parseArg?:
|
|
301
|
-
| ((value: string, previous: T) => T)
|
|
302
|
-
| string
|
|
303
|
-
| boolean
|
|
304
|
-
| string[]
|
|
305
|
-
| RegExp,
|
|
306
|
-
defaultValue?: T
|
|
307
|
-
): this {
|
|
308
|
-
if (
|
|
309
|
-
this.findSimilarOption({
|
|
310
|
-
flags,
|
|
311
|
-
mandatory: false,
|
|
312
|
-
})
|
|
313
|
-
) {
|
|
314
|
-
return this;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
return super.option(
|
|
318
|
-
flags,
|
|
319
|
-
// @ts-expect-error - Issues with overloading
|
|
320
|
-
description,
|
|
321
|
-
parseArg,
|
|
322
|
-
defaultValue
|
|
323
|
-
);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
requiredOption(
|
|
327
|
-
flags: string,
|
|
328
|
-
description?: string,
|
|
329
|
-
defaultValue?: string | boolean | string[]
|
|
330
|
-
): this;
|
|
331
|
-
requiredOption<T>(
|
|
332
|
-
flags: string,
|
|
333
|
-
description: string,
|
|
334
|
-
parseArg: (value: string, previous: T) => T,
|
|
335
|
-
defaultValue?: T
|
|
336
|
-
): this;
|
|
337
|
-
/** @deprecated since v7, instead use choices or a custom function */
|
|
338
|
-
requiredOption(
|
|
339
|
-
flags: string,
|
|
340
|
-
description: string,
|
|
341
|
-
regexp: RegExp,
|
|
342
|
-
defaultValue?: string | boolean | string[]
|
|
343
|
-
): this;
|
|
344
|
-
requiredOption<T>(
|
|
345
|
-
flags: string,
|
|
346
|
-
description?: string,
|
|
347
|
-
regexpOrDefaultValue?:
|
|
348
|
-
| string
|
|
349
|
-
| boolean
|
|
350
|
-
| string[]
|
|
351
|
-
| RegExp
|
|
352
|
-
| ((value: string, previous: T) => T),
|
|
353
|
-
defaultValue?: string | boolean | string[]
|
|
354
|
-
): this {
|
|
355
|
-
if (
|
|
356
|
-
this.findSimilarOption({
|
|
357
|
-
flags,
|
|
358
|
-
mandatory: true,
|
|
359
|
-
})
|
|
360
|
-
) {
|
|
361
|
-
return this;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
return super.requiredOption(
|
|
365
|
-
flags,
|
|
366
|
-
// @ts-expect-error - Issues with overloading
|
|
367
|
-
description,
|
|
368
|
-
regexpOrDefaultValue,
|
|
369
|
-
defaultValue
|
|
370
|
-
);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
addOption(option: Option): this {
|
|
374
|
-
if (
|
|
375
|
-
this.findSimilarOption({
|
|
376
|
-
flags: option.flags,
|
|
377
|
-
mandatory: option.mandatory,
|
|
378
|
-
})
|
|
379
|
-
) {
|
|
380
|
-
return this;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
return super.addOption(option);
|
|
206
|
+
return {
|
|
207
|
+
inputs,
|
|
208
|
+
args,
|
|
209
|
+
spinner,
|
|
210
|
+
services,
|
|
211
|
+
schema: schema as OpenAPISchemaType,
|
|
212
|
+
output: {
|
|
213
|
+
dir: outputDir,
|
|
214
|
+
clean: args.clean,
|
|
215
|
+
},
|
|
216
|
+
};
|
|
384
217
|
}
|
|
385
218
|
|
|
386
|
-
|
|
387
|
-
if (options?.from !== 'user') this.logVersion();
|
|
388
|
-
return super.parseAsync(argv, options);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
parse(argv?: readonly string[], options?: ParseOptions): this {
|
|
392
|
-
if (options?.from !== 'user') this.logVersion();
|
|
393
|
-
return super.parse(argv, options);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
protected logVersion() {
|
|
219
|
+
protected override logVersion() {
|
|
397
220
|
QraftCommand.spinner.info(
|
|
398
221
|
`✨ ${c.bold(`OpenAPI Qraft ${packageVersion}`)}`
|
|
399
222
|
);
|
|
400
223
|
}
|
|
401
|
-
|
|
402
|
-
protected findSimilarOption(option: { flags: string; mandatory: boolean }) {
|
|
403
|
-
try {
|
|
404
|
-
return findSimilarOption(option, this.options);
|
|
405
|
-
} catch (error) {
|
|
406
|
-
console.error(
|
|
407
|
-
c.red(
|
|
408
|
-
error instanceof Error
|
|
409
|
-
? error.message
|
|
410
|
-
: 'An error occurred during command option setup'
|
|
411
|
-
)
|
|
412
|
-
);
|
|
413
|
-
|
|
414
|
-
throw error;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
224
|
}
|
|
418
225
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
function normalizeOutputDirPath(outputDir: string): URL {
|
|
423
|
-
return pathToFileURL(
|
|
424
|
-
outputDir.endsWith(sep) ? outputDir : `${outputDir}${sep}`
|
|
425
|
-
);
|
|
226
|
+
export interface OpenAPIQraftCommandActionOptions extends QraftCommandActionOptions {
|
|
227
|
+
services: OpenAPIService[];
|
|
228
|
+
schema: OpenAPISchemaType;
|
|
426
229
|
}
|
|
427
230
|
|
|
428
231
|
export type QraftCommandActionCallback = (
|
|
429
|
-
options:
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
inputs: string[];
|
|
434
|
-
/**
|
|
435
|
-
* Command arguments, e.g. `bin <input> [options]` where `[options]` is the `args`
|
|
436
|
-
*/
|
|
437
|
-
args: Record<string, any>;
|
|
438
|
-
/**
|
|
439
|
-
* Spinner instance
|
|
440
|
-
*/
|
|
441
|
-
spinner: Ora;
|
|
442
|
-
/**
|
|
443
|
-
* OpenAPI services
|
|
444
|
-
*/
|
|
445
|
-
services: OpenAPIService[];
|
|
446
|
-
/**
|
|
447
|
-
* OpenAPI schema
|
|
448
|
-
*/
|
|
449
|
-
schema: OpenAPISchemaType;
|
|
450
|
-
/**
|
|
451
|
-
* Output options
|
|
452
|
-
*/
|
|
453
|
-
output: OutputOptions;
|
|
454
|
-
},
|
|
455
|
-
resolve: (files: GeneratorFile[]) => void
|
|
232
|
+
options: OpenAPIQraftCommandActionOptions,
|
|
233
|
+
resolve: (
|
|
234
|
+
files: import('@qraft/plugin/lib/GeneratorFile').GeneratorFile[]
|
|
235
|
+
) => void
|
|
456
236
|
) => Promise<void>;
|
|
457
237
|
|
|
458
|
-
function findSimilarOption(
|
|
459
|
-
{
|
|
460
|
-
flags,
|
|
461
|
-
mandatory,
|
|
462
|
-
}: {
|
|
463
|
-
flags: string;
|
|
464
|
-
mandatory: boolean;
|
|
465
|
-
},
|
|
466
|
-
options: readonly Option[]
|
|
467
|
-
) {
|
|
468
|
-
const newOptionParsedFlags = splitOptionFlags(flags);
|
|
469
|
-
/** @see {@link https://github.com/tj/commander.js/blob/83c3f4e391754d2f80b179acc4bccc2d4d0c863d/lib/option.js#L15} Source implementation */
|
|
470
|
-
const optional = flags.includes('['); // A value is optional when the option is specified.
|
|
471
|
-
const required = flags.includes('<'); // A value must be supplied when the option is specified.
|
|
472
|
-
// variadic test ignores <value,...> et al which might be used to describe custom splitting of single argument
|
|
473
|
-
const variadic = /\w\.\.\.[>\]]$/.test(flags); // The option can take multiple values.
|
|
474
|
-
|
|
475
|
-
return options.find((existingOption) => {
|
|
476
|
-
const existingOptionParsedFlags = splitOptionFlags(existingOption.flags);
|
|
477
|
-
|
|
478
|
-
if (
|
|
479
|
-
!(
|
|
480
|
-
(existingOptionParsedFlags.longFlag !== undefined &&
|
|
481
|
-
existingOptionParsedFlags.longFlag ===
|
|
482
|
-
newOptionParsedFlags.longFlag) ||
|
|
483
|
-
(existingOptionParsedFlags.shortFlag !== undefined &&
|
|
484
|
-
existingOptionParsedFlags.shortFlag ===
|
|
485
|
-
newOptionParsedFlags.shortFlag)
|
|
486
|
-
)
|
|
487
|
-
) {
|
|
488
|
-
return false;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
if (
|
|
492
|
-
existingOptionParsedFlags.longFlag !== undefined &&
|
|
493
|
-
newOptionParsedFlags.longFlag !== undefined &&
|
|
494
|
-
existingOptionParsedFlags.longFlag !== newOptionParsedFlags.longFlag
|
|
495
|
-
) {
|
|
496
|
-
throw new Error(
|
|
497
|
-
`Long flag ${flags} already exists in the option list with flags: "${existingOption.flags}" and description: "${existingOption.description}"`
|
|
498
|
-
);
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
if (
|
|
502
|
-
existingOptionParsedFlags.shortFlag !== undefined &&
|
|
503
|
-
newOptionParsedFlags.shortFlag !== undefined &&
|
|
504
|
-
existingOptionParsedFlags.shortFlag !== newOptionParsedFlags.shortFlag
|
|
505
|
-
) {
|
|
506
|
-
throw new Error(
|
|
507
|
-
`Short flag ${flags} already exists in the option list with flags: "${existingOption.flags}" and description: "${existingOption.description}"`
|
|
508
|
-
);
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
if (required !== existingOption.required) {
|
|
512
|
-
throw new Error(
|
|
513
|
-
`Flag ${flags} already exists in the option list with flags: "${existingOption.flags}" and description: "${existingOption.description}" but with different required status`
|
|
514
|
-
);
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
if (optional !== existingOption.optional) {
|
|
518
|
-
throw new Error(
|
|
519
|
-
`Flag ${flags} already exists in the option list with flags: "${existingOption.flags}" and description: "${existingOption.description}" but with different optional status`
|
|
520
|
-
);
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
if (mandatory !== existingOption.mandatory) {
|
|
524
|
-
throw new Error(
|
|
525
|
-
`Flag ${flags} already exists in the option list with flags: "${existingOption.flags}" and description: "${existingOption.description}" but with different mandatory status`
|
|
526
|
-
);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
if (variadic !== existingOption.variadic) {
|
|
530
|
-
throw new Error(
|
|
531
|
-
`Flag ${flags} already exists in the option list with flags: "${existingOption.flags}" and description: "${existingOption.description}" but with different variadic status`
|
|
532
|
-
);
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
return existingOption;
|
|
536
|
-
});
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
/**
|
|
540
|
-
* Split the short and long flag out of something like '-m,--mixed <value>'
|
|
541
|
-
* @link https://github.com/tj/commander.js/blob/83c3f4e391754d2f80b179acc4bccc2d4d0c863d/lib/option.js#L310
|
|
542
|
-
*/
|
|
543
|
-
export function splitOptionFlags(flags: string) {
|
|
544
|
-
let shortFlag;
|
|
545
|
-
let longFlag;
|
|
546
|
-
|
|
547
|
-
// Use original very loose parsing to maintain backwards compatibility for now,
|
|
548
|
-
// which allowed, for example, unintended `-sw, --short-word` [sic].
|
|
549
|
-
const flagParts = flags.split(/[ |,]+/);
|
|
550
|
-
|
|
551
|
-
if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
|
|
552
|
-
shortFlag = flagParts.shift();
|
|
553
|
-
|
|
554
|
-
longFlag = flagParts.shift();
|
|
555
|
-
|
|
556
|
-
// Add support for a lone short flag without significantly changing parsing!
|
|
557
|
-
if (!shortFlag && /^-[^-]$/.test(longFlag ?? '')) {
|
|
558
|
-
shortFlag = longFlag;
|
|
559
|
-
longFlag = undefined;
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
return { shortFlag, longFlag };
|
|
563
|
-
}
|
|
564
|
-
|
|
565
238
|
function parseColonSeparatedList(value: string, previous: unknown) {
|
|
566
239
|
if (Array.isArray(previous)) {
|
|
567
240
|
const previousValue = previous.at(-1);
|
|
@@ -594,9 +267,13 @@ function handleRedoclySchemaInput(
|
|
|
594
267
|
);
|
|
595
268
|
}
|
|
596
269
|
|
|
597
|
-
const api = getRedocAPIsToQraft(
|
|
270
|
+
const api = getRedocAPIsToQraft(
|
|
271
|
+
redoc,
|
|
272
|
+
cwd,
|
|
273
|
+
spinner,
|
|
274
|
+
OPENAPI_QRAFT_REDOC_CONFIG_KEY,
|
|
598
275
|
inputAPIName
|
|
599
|
-
];
|
|
276
|
+
)[inputAPIName];
|
|
600
277
|
|
|
601
278
|
if (!api)
|
|
602
279
|
throw new CommanderError(
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
+
import { QraftCommandPlugin as QraftCommandPluginBase } from '@qraft/plugin';
|
|
1
2
|
import { QraftCommand } from './QraftCommand.js';
|
|
2
3
|
|
|
3
|
-
export interface QraftCommandPlugin {
|
|
4
|
-
setupCommand(command: QraftCommand): void | Promise<void>;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Called after all plugins have been set up
|
|
8
|
-
*/
|
|
9
|
-
postSetupCommand?(
|
|
10
|
-
command: QraftCommand,
|
|
11
|
-
plugins: string[]
|
|
12
|
-
): void | Promise<void>;
|
|
13
|
-
}
|
|
4
|
+
export interface QraftCommandPlugin extends QraftCommandPluginBase<QraftCommand> {}
|
package/src/packageVersion.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file was generated automatically
|
|
2
|
-
export const packageVersion = '2.15.0-beta.
|
|
2
|
+
export const packageVersion = '2.15.0-beta.2';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GeneratorFile.d.ts","sourceRoot":"","sources":["../../src/lib/GeneratorFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,GAAG,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC3B;IAAE,SAAS,EAAE,GAAG,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GeneratorFile.js","sourceRoot":"","sources":["../../src/lib/GeneratorFile.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"OutputOptions.d.ts","sourceRoot":"","sources":["../../src/lib/OutputOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,EAAE,OAAO,CAAC;CAChB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"OutputOptions.js","sourceRoot":"","sources":["../../src/lib/OutputOptions.ts"],"names":[],"mappings":""}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { URL } from 'node:url';
|
|
2
|
-
import { Command, Option, ParseOptions } from 'commander';
|
|
3
|
-
export declare const redoclyOption: Option;
|
|
4
|
-
/**
|
|
5
|
-
* @param name - not used
|
|
6
|
-
*/
|
|
7
|
-
export declare class RedoclyConfigCommand extends Command {
|
|
8
|
-
protected readonly cwd: URL;
|
|
9
|
-
/**
|
|
10
|
-
* Redocly API item and QraftCommand arguments
|
|
11
|
-
*/
|
|
12
|
-
protected parsedAPIs: RedoclyQraftAPIs;
|
|
13
|
-
constructor(name?: string);
|
|
14
|
-
parseConfig<T>(callbackFn: CallbackFn<T>, argv: readonly string[], options?: ParseOptions): Promise<T[] | undefined>;
|
|
15
|
-
static forEachRedoclyAPIEntry<T>(redoclyAPIs: RedoclyQraftAPIs, callbackFn: CallbackFn<T>): Promise<T[]>;
|
|
16
|
-
}
|
|
17
|
-
type CallbackFn<T> = (processArgv: string[], processArgvParseOptions?: ParseOptions) => T;
|
|
18
|
-
type RedoclyQraftAPIs = {
|
|
19
|
-
[apiName: string]: string[];
|
|
20
|
-
};
|
|
21
|
-
export {};
|
|
22
|
-
//# sourceMappingURL=RedoclyConfigCommand.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RedoclyConfigCommand.d.ts","sourceRoot":"","sources":["../../src/lib/RedoclyConfigCommand.ts"],"names":[],"mappings":"AACA,OAAO,EAAgC,GAAG,EAAE,MAAM,UAAU,CAAC;AAG7D,OAAO,EAAE,OAAO,EAAkB,MAAM,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAO1E,eAAO,MAAM,aAAa,QAqBtB,CAAC;AACL;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,OAAO;IAC/C,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAE5B;;OAEG;IACH,SAAS,CAAC,UAAU,EAAE,gBAAgB,CAAM;gBAEhC,IAAI,CAAC,EAAE,MAAM;IA6FnB,WAAW,CAAC,CAAC,EACjB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EACzB,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC;WAWd,sBAAsB,CAAC,CAAC,EACnC,WAAW,EAAE,gBAAgB,EAC7B,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;CAoE5B;AAED,KAAK,UAAU,CAAC,CAAC,IAAI,CACnB,WAAW,EAAE,MAAM,EAAE,EACrB,uBAAuB,CAAC,EAAE,YAAY,KACnC,CAAC,CAAC;AAEP,KAAK,gBAAgB,GAAG;IACtB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC7B,CAAC"}
|