@openapi-qraft/plugin 1.8.0 → 1.9.0
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 +13 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/GeneratorFile.d.ts +1 -0
- package/dist/lib/GeneratorFile.d.ts.map +1 -0
- package/dist/lib/OutputOptions.d.ts +1 -0
- package/dist/lib/OutputOptions.d.ts.map +1 -0
- package/dist/lib/QraftCommand.d.ts +35 -7
- package/dist/lib/QraftCommand.d.ts.map +1 -0
- package/dist/lib/QraftCommand.js +165 -56
- package/dist/lib/QraftCommand.js.map +1 -1
- package/dist/lib/QraftCommandPlugin.d.ts +6 -1
- package/dist/lib/QraftCommandPlugin.d.ts.map +1 -0
- package/dist/lib/fileHeader.d.ts +2 -1
- package/dist/lib/fileHeader.d.ts.map +1 -0
- package/dist/lib/fileHeader.js +6 -2
- package/dist/lib/fileHeader.js.map +1 -1
- package/dist/lib/filterDocumentPaths.d.ts +18 -0
- package/dist/lib/filterDocumentPaths.d.ts.map +1 -0
- package/dist/lib/filterDocumentPaths.js +46 -0
- package/dist/lib/filterDocumentPaths.js.map +1 -0
- package/dist/lib/formatFileHeader.d.ts +2 -0
- package/dist/lib/formatFileHeader.d.ts.map +1 -0
- package/dist/lib/formatFileHeader.js +6 -0
- package/dist/lib/formatFileHeader.js.map +1 -0
- package/dist/lib/handleSchemaInput.d.ts +12 -0
- package/dist/lib/handleSchemaInput.d.ts.map +1 -0
- package/dist/lib/handleSchemaInput.js +40 -0
- package/dist/lib/handleSchemaInput.js.map +1 -0
- package/dist/lib/open-api/OpenAPISchemaType.d.ts +6 -0
- package/dist/lib/open-api/OpenAPISchemaType.d.ts.map +1 -0
- package/dist/lib/open-api/getContent.d.ts +1 -0
- package/dist/lib/open-api/getContent.d.ts.map +1 -0
- package/dist/lib/open-api/getOperationName.d.ts +1 -0
- package/dist/lib/open-api/getOperationName.d.ts.map +1 -0
- package/dist/lib/open-api/getServiceName.d.ts +1 -0
- package/dist/lib/open-api/getServiceName.d.ts.map +1 -0
- package/dist/lib/open-api/getServiceNamesByOperationEndpoint.d.ts +1 -0
- package/dist/lib/open-api/getServiceNamesByOperationEndpoint.d.ts.map +1 -0
- package/dist/lib/open-api/getServiceNamesByOperationTags.d.ts +1 -0
- package/dist/lib/open-api/getServiceNamesByOperationTags.d.ts.map +1 -0
- package/dist/lib/open-api/getServices.d.ts +2 -6
- package/dist/lib/open-api/getServices.d.ts.map +1 -0
- package/dist/lib/open-api/getServices.js +1 -26
- package/dist/lib/open-api/getServices.js.map +1 -1
- package/dist/lib/open-api/readSchema.d.ts +1 -1
- package/dist/lib/open-api/readSchema.d.ts.map +1 -0
- package/dist/lib/vitestFsMock.d.ts +2 -0
- package/dist/lib/vitestFsMock.d.ts.map +1 -0
- package/dist/lib/vitestFsMock.js +16 -0
- package/dist/lib/vitestFsMock.js.map +1 -0
- package/dist/lib/writeGeneratorFiles.d.ts +1 -0
- package/dist/lib/writeGeneratorFiles.d.ts.map +1 -0
- package/package.json +4 -2
- package/src/index.ts +2 -0
- package/src/lib/QraftCommand.ts +316 -77
- package/src/lib/QraftCommandPlugin.ts +9 -1
- package/src/lib/fileHeader.ts +6 -2
- package/src/lib/filterDocumentPaths.ts +58 -0
- package/src/lib/formatFileHeader.ts +4 -0
- package/src/lib/handleSchemaInput.ts +53 -0
- package/src/lib/open-api/OpenAPISchemaType.ts +5 -0
- package/src/lib/open-api/getServices.ts +1 -34
- package/src/lib/vitestFsMock.ts +23 -0
- package/dist/lib/open-api/getDocumentServices.d.ts +0 -12
- package/dist/lib/open-api/getDocumentServices.js +0 -7
- package/dist/lib/open-api/getDocumentServices.js.map +0 -1
- package/src/lib/open-api/getDocumentServices.ts +0 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @openapi-qraft/plugin
|
|
2
2
|
|
|
3
|
+
## 1.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3a75364: **Plugin Support in CLI**: Introduced the `--plugin <name>` option in the OpenAPI Qraft CLI to allow users to specify
|
|
8
|
+
plugins such as `tanstack-query-react` for React service generation and `openapi-typescript` for TypeScript type
|
|
9
|
+
generation. This enhancement provides greater flexibility and customization options in the API generation process. The
|
|
10
|
+
CLI now supports using multiple plugins simultaneously, enhancing the tool's versatility for developers.
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 943a9d3: Fixed issue where async functions in the plugin were not awaited
|
|
15
|
+
|
|
3
16
|
## 1.8.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,6BAA6B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
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,12 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { Command, type Option } from 'commander';
|
|
3
|
+
import { URL } from 'node:url';
|
|
2
4
|
import { Ora } from 'ora';
|
|
3
5
|
import { GeneratorFile } from './GeneratorFile.js';
|
|
4
|
-
import { Service } from './open-api/getServices.js';
|
|
6
|
+
import { type Service } from './open-api/getServices.js';
|
|
7
|
+
import { OpenAPISchemaType } from './open-api/OpenAPISchemaType.js';
|
|
5
8
|
import { OutputOptions } from './OutputOptions.js';
|
|
6
9
|
export declare class QraftCommand extends Command {
|
|
7
|
-
|
|
10
|
+
protected readonly cwd: URL;
|
|
11
|
+
protected registeredPluginActions: QraftCommandActionCallback[];
|
|
8
12
|
constructor();
|
|
9
13
|
action(callback: QraftCommandActionCallback): this;
|
|
14
|
+
actionCallback(...actionArgs: any[]): Promise<void>;
|
|
15
|
+
protected registerPluginAction(callback: QraftCommandActionCallback): void;
|
|
16
|
+
option(flags: string, description?: string, defaultValue?: string | boolean | string[]): this;
|
|
17
|
+
option<T>(flags: string, description: string, parseArg: (value: string, previous: T) => T, defaultValue?: T): this;
|
|
18
|
+
/** @deprecated since v7, instead use choices or a custom function */
|
|
19
|
+
option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean | string[]): this;
|
|
20
|
+
requiredOption(flags: string, description?: string, defaultValue?: string | boolean | string[]): this;
|
|
21
|
+
requiredOption<T>(flags: string, description: string, parseArg: (value: string, previous: T) => T, defaultValue?: T): this;
|
|
22
|
+
/** @deprecated since v7, instead use choices or a custom function */
|
|
23
|
+
requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean | string[]): this;
|
|
24
|
+
protected findSimilarOption(option: {
|
|
25
|
+
flags: string;
|
|
26
|
+
mandatory: boolean;
|
|
27
|
+
}): Option | undefined;
|
|
10
28
|
}
|
|
11
29
|
export type QraftCommandActionCallback = (options: {
|
|
12
30
|
/**
|
|
@@ -17,9 +35,6 @@ export type QraftCommandActionCallback = (options: {
|
|
|
17
35
|
* Command arguments, e.g. `bin <input> [options]` where `[options]` is the `args`
|
|
18
36
|
*/
|
|
19
37
|
args: Record<string, any>;
|
|
20
|
-
/**
|
|
21
|
-
* Resolve the generator files
|
|
22
|
-
*/
|
|
23
38
|
/**
|
|
24
39
|
* Spinner instance
|
|
25
40
|
*/
|
|
@@ -28,8 +43,21 @@ export type QraftCommandActionCallback = (options: {
|
|
|
28
43
|
* OpenAPI services
|
|
29
44
|
*/
|
|
30
45
|
services: Service[];
|
|
46
|
+
/**
|
|
47
|
+
* OpenAPI schema
|
|
48
|
+
*/
|
|
49
|
+
schema: OpenAPISchemaType;
|
|
31
50
|
/**
|
|
32
51
|
* Output options
|
|
33
52
|
*/
|
|
34
53
|
output: OutputOptions;
|
|
35
|
-
}, resolve: (files: GeneratorFile[]) =>
|
|
54
|
+
}, resolve: (files: GeneratorFile[]) => void) => Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Split the short and long flag out of something like '-m,--mixed <value>'
|
|
57
|
+
* @link https://github.com/tj/commander.js/blob/83c3f4e391754d2f80b179acc4bccc2d4d0c863d/lib/option.js#L310
|
|
58
|
+
*/
|
|
59
|
+
export declare function splitOptionFlags(flags: string): {
|
|
60
|
+
shortFlag: string | undefined;
|
|
61
|
+
longFlag: string | undefined;
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=QraftCommand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QraftCommand.d.ts","sourceRoot":"","sources":["../../src/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
3
|
+
import * as console from 'node:console';
|
|
3
4
|
import { sep } from 'node:path';
|
|
4
5
|
import process from 'node:process';
|
|
5
|
-
import { pathToFileURL
|
|
6
|
+
import { pathToFileURL } from 'node:url';
|
|
6
7
|
import ora from 'ora';
|
|
7
|
-
import {
|
|
8
|
+
import { filterDocumentPaths } from './filterDocumentPaths.js';
|
|
9
|
+
import { handleSchemaInput } from './handleSchemaInput.js';
|
|
10
|
+
import { getServices } from './open-api/getServices.js';
|
|
11
|
+
import { readSchema } from './open-api/readSchema.js';
|
|
8
12
|
import { writeGeneratorFiles } from './writeGeneratorFiles.js';
|
|
9
13
|
export class QraftCommand extends Command {
|
|
14
|
+
cwd;
|
|
15
|
+
registeredPluginActions = [];
|
|
10
16
|
constructor() {
|
|
11
17
|
super();
|
|
18
|
+
this.cwd = pathToFileURL(`${process.cwd()}/`);
|
|
12
19
|
this.usage('[input] [options]')
|
|
13
|
-
.argument('[input]', 'Input OpenAPI
|
|
20
|
+
.argument('[input]', 'Input OpenAPI Document file path, URL (json, yml)', null)
|
|
14
21
|
.requiredOption('-o, --output-dir <path>', 'Output directory for generated services')
|
|
15
22
|
.option('-rm, --clean', 'Clean output directory before generating services')
|
|
16
23
|
.option('--filter-services <glob-pattern>', 'Filter services to be generated by glob pattern. Eg: "/user/**,/post/**". See NPM `micromatch` package for more details.')
|
|
17
24
|
.option('--postfix-services <string>', 'Postfix to be added to the generated service name (eg: Service)')
|
|
18
|
-
.option('--service-name-base <endpoint[<index>] | tags>', 'Use OpenAPI Operation `endpoint[<index>]` path part (e.g.: "/0/1/2") or `tags` as the base name of the service.', 'endpoint[0]')
|
|
25
|
+
.option('--service-name-base <endpoint[<index>] | tags>', 'Use OpenAPI Operation `endpoint[<index>]` path part (e.g.: "/0/1/2") or `tags` as the base name of the service.', 'endpoint[0]')
|
|
26
|
+
.option('--file-header <string>', 'Header to be added to the generated file (eg: /* eslint-disable */)');
|
|
19
27
|
}
|
|
20
28
|
action(callback) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
console.info(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
29
|
+
this.registerPluginAction(callback);
|
|
30
|
+
return super.action(this.actionCallback.bind(this));
|
|
31
|
+
}
|
|
32
|
+
async actionCallback(...actionArgs) {
|
|
33
|
+
const { version: packageVersion } = await import('@openapi-qraft/plugin/package.json', {
|
|
34
|
+
assert: { type: 'json' },
|
|
35
|
+
}).then(({ default: packageJSON }) => packageJSON);
|
|
36
|
+
const inputs = actionArgs.filter((arg) => typeof arg === 'string');
|
|
37
|
+
const args = actionArgs.find((arg) => arg && typeof arg === 'object');
|
|
38
|
+
if (!args)
|
|
39
|
+
throw new Error('Arguments object not found');
|
|
40
|
+
if (args.version) {
|
|
41
|
+
console.info(`v${packageVersion}`); // todo::add displaying of the used plugin version
|
|
42
|
+
process.exit(0);
|
|
43
|
+
}
|
|
44
|
+
console.info(`✨ ${c.bold(`OpenAPI Qraft ${packageVersion}`)}`);
|
|
45
|
+
const spinner = ora('Starting ⛏︎').start();
|
|
46
|
+
const input = handleSchemaInput(inputs[0], this.cwd, spinner);
|
|
47
|
+
spinner.text = 'Reading OpenAPI Schema';
|
|
48
|
+
const schema = filterDocumentPaths(await readSchema(input), parseServicesFilterOption(args.filterServices));
|
|
49
|
+
spinner.text = 'Getting OpenAPI Services';
|
|
50
|
+
const services = getServices(schema, {
|
|
51
|
+
postfixServices: args.postfixServices,
|
|
52
|
+
serviceNameBase: args.serviceNameBase,
|
|
53
|
+
});
|
|
54
|
+
spinner.text = 'Generating code';
|
|
55
|
+
const outputDir = normalizeOutputDirPath(args.outputDir);
|
|
56
|
+
for (const pluginAction of this.registeredPluginActions) {
|
|
57
|
+
const fileItems = await new Promise((resolve, reject) => {
|
|
58
|
+
pluginAction({
|
|
59
|
+
inputs,
|
|
60
|
+
args,
|
|
61
|
+
spinner,
|
|
62
|
+
services,
|
|
63
|
+
schema,
|
|
64
|
+
output: {
|
|
65
|
+
dir: outputDir,
|
|
66
|
+
clean: args.clean,
|
|
67
|
+
},
|
|
68
|
+
}, resolve).catch(reject);
|
|
69
|
+
});
|
|
70
|
+
try {
|
|
71
|
+
if (this.registeredPluginActions.indexOf(pluginAction) === 0) {
|
|
46
72
|
await writeGeneratorFiles({
|
|
47
|
-
|
|
73
|
+
// Create output directory first, but for the first plugin only
|
|
74
|
+
fileItems: [{ directory: outputDir, clean: false }, ...fileItems],
|
|
48
75
|
spinner,
|
|
49
76
|
});
|
|
50
|
-
spinner.succeed(c.green('Qraft has been finished'));
|
|
51
77
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (error instanceof Error) {
|
|
55
|
-
console.error(c.red(error.message), c.red(error.stack ?? ''));
|
|
56
|
-
}
|
|
57
|
-
console.error(error);
|
|
58
|
-
process.exit(1);
|
|
78
|
+
else {
|
|
79
|
+
await writeGeneratorFiles({ fileItems, spinner });
|
|
59
80
|
}
|
|
60
|
-
}
|
|
61
|
-
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
spinner.fail(c.red('Error occurred during generation'));
|
|
84
|
+
if (error instanceof Error) {
|
|
85
|
+
console.error(c.red(error.message), c.red(error.stack ?? ''));
|
|
86
|
+
}
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
spinner.succeed(c.green('Qraft has been finished'));
|
|
91
|
+
}
|
|
92
|
+
registerPluginAction(callback) {
|
|
93
|
+
this.registeredPluginActions.push(callback);
|
|
62
94
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
95
|
+
option(flags, description, parseArg, defaultValue) {
|
|
96
|
+
if (this.findSimilarOption({
|
|
97
|
+
flags,
|
|
98
|
+
mandatory: false,
|
|
99
|
+
})) {
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
return super.option(flags,
|
|
103
|
+
// @ts-expect-error - Issues with overloading
|
|
104
|
+
description, parseArg, defaultValue);
|
|
105
|
+
}
|
|
106
|
+
requiredOption(flags, description, regexpOrDefaultValue, defaultValue) {
|
|
107
|
+
if (this.findSimilarOption({
|
|
108
|
+
flags,
|
|
109
|
+
mandatory: true,
|
|
110
|
+
})) {
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
return super.requiredOption(flags,
|
|
114
|
+
// @ts-expect-error - Issues with overloading
|
|
115
|
+
description, regexpOrDefaultValue, defaultValue);
|
|
116
|
+
}
|
|
117
|
+
findSimilarOption(option) {
|
|
118
|
+
try {
|
|
119
|
+
return findSimilarOption(option, this.options);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
console.error(c.red(error instanceof Error
|
|
123
|
+
? error.message
|
|
124
|
+
: 'Error occurred during option setup'));
|
|
125
|
+
throw error;
|
|
71
126
|
}
|
|
72
|
-
return await getDocumentServices({
|
|
73
|
-
output: {
|
|
74
|
-
postfixServices: args.postfixServices,
|
|
75
|
-
serviceNameBase: args.serviceNameBase,
|
|
76
|
-
},
|
|
77
|
-
servicesGlob: parseServicesFilterOption(args.filterServices),
|
|
78
|
-
source,
|
|
79
|
-
});
|
|
80
127
|
}
|
|
81
128
|
}
|
|
82
129
|
/**
|
|
@@ -100,4 +147,66 @@ function parseServicesFilterOption(endpointGlobs) {
|
|
|
100
147
|
.filter((item) => Boolean(typeof item === 'string' && item.trim()))
|
|
101
148
|
: undefined;
|
|
102
149
|
}
|
|
150
|
+
function findSimilarOption({ flags, mandatory, }, options) {
|
|
151
|
+
const newOptionParsedFlags = splitOptionFlags(flags);
|
|
152
|
+
/** @see {@link https://github.com/tj/commander.js/blob/83c3f4e391754d2f80b179acc4bccc2d4d0c863d/lib/option.js#L15} Source implementation */
|
|
153
|
+
const optional = flags.includes('['); // A value is optional when the option is specified.
|
|
154
|
+
const required = flags.includes('<'); // A value must be supplied when the option is specified.
|
|
155
|
+
// variadic test ignores <value,...> et al which might be used to describe custom splitting of single argument
|
|
156
|
+
const variadic = /\w\.\.\.[>\]]$/.test(flags); // The option can take multiple values.
|
|
157
|
+
return options.find((existingOption) => {
|
|
158
|
+
const existingOptionParsedFlags = splitOptionFlags(existingOption.flags);
|
|
159
|
+
if (!((existingOptionParsedFlags.longFlag !== undefined &&
|
|
160
|
+
existingOptionParsedFlags.longFlag ===
|
|
161
|
+
newOptionParsedFlags.longFlag) ||
|
|
162
|
+
(existingOptionParsedFlags.shortFlag !== undefined &&
|
|
163
|
+
existingOptionParsedFlags.shortFlag ===
|
|
164
|
+
newOptionParsedFlags.shortFlag))) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
if (existingOptionParsedFlags.longFlag !== undefined &&
|
|
168
|
+
newOptionParsedFlags.longFlag !== undefined &&
|
|
169
|
+
existingOptionParsedFlags.longFlag !== newOptionParsedFlags.longFlag) {
|
|
170
|
+
throw new Error(`Long flag ${flags} already exists in the option list with flags: "${existingOption.flags}" and description: "${existingOption.description}"`);
|
|
171
|
+
}
|
|
172
|
+
if (existingOptionParsedFlags.shortFlag !== undefined &&
|
|
173
|
+
newOptionParsedFlags.shortFlag !== undefined &&
|
|
174
|
+
existingOptionParsedFlags.shortFlag !== newOptionParsedFlags.shortFlag) {
|
|
175
|
+
throw new Error(`Short flag ${flags} already exists in the option list with flags: "${existingOption.flags}" and description: "${existingOption.description}"`);
|
|
176
|
+
}
|
|
177
|
+
if (required !== existingOption.required) {
|
|
178
|
+
throw new Error(`Flag ${flags} already exists in the option list with flags: "${existingOption.flags}" and description: "${existingOption.description}" but with different required status`);
|
|
179
|
+
}
|
|
180
|
+
if (optional !== existingOption.optional) {
|
|
181
|
+
throw new Error(`Flag ${flags} already exists in the option list with flags: "${existingOption.flags}" and description: "${existingOption.description}" but with different optional status`);
|
|
182
|
+
}
|
|
183
|
+
if (mandatory !== existingOption.mandatory) {
|
|
184
|
+
throw new Error(`Flag ${flags} already exists in the option list with flags: "${existingOption.flags}" and description: "${existingOption.description}" but with different mandatory status`);
|
|
185
|
+
}
|
|
186
|
+
if (variadic !== existingOption.variadic) {
|
|
187
|
+
throw new Error(`Flag ${flags} already exists in the option list with flags: "${existingOption.flags}" and description: "${existingOption.description}" but with different variadic status`);
|
|
188
|
+
}
|
|
189
|
+
return existingOption;
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Split the short and long flag out of something like '-m,--mixed <value>'
|
|
194
|
+
* @link https://github.com/tj/commander.js/blob/83c3f4e391754d2f80b179acc4bccc2d4d0c863d/lib/option.js#L310
|
|
195
|
+
*/
|
|
196
|
+
export function splitOptionFlags(flags) {
|
|
197
|
+
let shortFlag;
|
|
198
|
+
let longFlag;
|
|
199
|
+
// Use original very loose parsing to maintain backwards compatibility for now,
|
|
200
|
+
// which allowed, for example, unintended `-sw, --short-word` [sic].
|
|
201
|
+
const flagParts = flags.split(/[ |,]+/);
|
|
202
|
+
if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
|
|
203
|
+
shortFlag = flagParts.shift();
|
|
204
|
+
longFlag = flagParts.shift();
|
|
205
|
+
// Add support for a lone short flag without significantly changing parsing!
|
|
206
|
+
if (!shortFlag && /^-[^-]$/.test(longFlag ?? '')) {
|
|
207
|
+
shortFlag = longFlag;
|
|
208
|
+
longFlag = undefined;
|
|
209
|
+
}
|
|
210
|
+
return { shortFlag, longFlag };
|
|
211
|
+
}
|
|
103
212
|
//# sourceMappingURL=QraftCommand.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QraftCommand.js","sourceRoot":"","sources":["../../src/lib/QraftCommand.ts"],"names":[],"mappings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EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACjC,CAAC"}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { QraftCommand } from './QraftCommand.js';
|
|
2
2
|
export interface QraftCommandPlugin {
|
|
3
|
-
setupCommand(command: QraftCommand): void
|
|
3
|
+
setupCommand(command: QraftCommand): void | Promise<void>;
|
|
4
|
+
/**
|
|
5
|
+
* Called after all plugins have been set up
|
|
6
|
+
*/
|
|
7
|
+
postSetupCommand?(command: QraftCommand, plugins: string[]): void | Promise<void>;
|
|
4
8
|
}
|
|
9
|
+
//# sourceMappingURL=QraftCommandPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QraftCommandPlugin.d.ts","sourceRoot":"","sources":["../../src/lib/QraftCommandPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,WAAW,kBAAkB;IACjC,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1D;;OAEG;IACH,gBAAgB,CAAC,CACf,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,MAAM,EAAE,GAChB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB"}
|
package/dist/lib/fileHeader.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare const fileHeader = "
|
|
1
|
+
export declare const fileHeader = "/**\n * This file was auto-generated by @openapi-qraft/cli.\n * Do not make direct changes to the file.\n */\n\n";
|
|
2
|
+
//# sourceMappingURL=fileHeader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fileHeader.d.ts","sourceRoot":"","sources":["../../src/lib/fileHeader.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,qHAKtB,CAAC"}
|
package/dist/lib/fileHeader.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
export const fileHeader =
|
|
2
|
-
|
|
1
|
+
export const fileHeader = `/**
|
|
2
|
+
* This file was auto-generated by @openapi-qraft/cli.
|
|
3
|
+
* Do not make direct changes to the file.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
`;
|
|
3
7
|
//# sourceMappingURL=fileHeader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileHeader.js","sourceRoot":"","sources":["../../src/lib/fileHeader.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG
|
|
1
|
+
{"version":3,"file":"fileHeader.js","sourceRoot":"","sources":["../../src/lib/fileHeader.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG;;;;;CAKzB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { OpenAPISchemaType } from './open-api/OpenAPISchemaType.js';
|
|
2
|
+
/**
|
|
3
|
+
* Filter the schema to only include paths that match the servicesGlob
|
|
4
|
+
* @param schema OpenAPI schema
|
|
5
|
+
* @param servicesGlob Glob pattern to match services. E.g.: `['**']`
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* filterDocumentPaths(schema, ['/user/**', '/post/**', '!/user/internal'])
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const filterDocumentPaths: (schema: OpenAPISchemaType, servicesGlob: string[] | undefined) => OpenAPISchemaType;
|
|
13
|
+
/**
|
|
14
|
+
* Create a function to match service paths
|
|
15
|
+
* @param servicesGlob
|
|
16
|
+
*/
|
|
17
|
+
export declare const createServicePathMatch: (servicesGlob: string[]) => (path: string) => boolean;
|
|
18
|
+
//# sourceMappingURL=filterDocumentPaths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterDocumentPaths.d.ts","sourceRoot":"","sources":["../../src/lib/filterDocumentPaths.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAEzE;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,WACtB,iBAAiB,gBACX,MAAM,EAAE,GAAG,SAAS,sBAcnC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,iBAAkB,MAAM,EAAE,YAgBjB,MAAM,YAKjD,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import micromatch from 'micromatch';
|
|
2
|
+
/**
|
|
3
|
+
* Filter the schema to only include paths that match the servicesGlob
|
|
4
|
+
* @param schema OpenAPI schema
|
|
5
|
+
* @param servicesGlob Glob pattern to match services. E.g.: `['**']`
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* filterDocumentPaths(schema, ['/user/**', '/post/**', '!/user/internal'])
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export const filterDocumentPaths = (schema, servicesGlob) => {
|
|
13
|
+
if (!servicesGlob)
|
|
14
|
+
return schema;
|
|
15
|
+
const isPathMatch = createServicePathMatch(servicesGlob);
|
|
16
|
+
const paths = {};
|
|
17
|
+
for (const path in schema.paths) {
|
|
18
|
+
if (!Object.prototype.hasOwnProperty.call(schema.paths, path))
|
|
19
|
+
continue;
|
|
20
|
+
if (!isPathMatch(path))
|
|
21
|
+
continue;
|
|
22
|
+
paths[path] = schema.paths[path];
|
|
23
|
+
}
|
|
24
|
+
return { ...schema, paths };
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Create a function to match service paths
|
|
28
|
+
* @param servicesGlob
|
|
29
|
+
*/
|
|
30
|
+
export const createServicePathMatch = (servicesGlob) => {
|
|
31
|
+
const servicePathGlobs = servicesGlob.reduce((acc, glob) => {
|
|
32
|
+
glob.startsWith('!')
|
|
33
|
+
? acc.ignore.push(glob.slice(1))
|
|
34
|
+
: acc.match.push(glob);
|
|
35
|
+
return acc;
|
|
36
|
+
}, {
|
|
37
|
+
match: [],
|
|
38
|
+
ignore: [],
|
|
39
|
+
});
|
|
40
|
+
return function isServicePatchMatch(path) {
|
|
41
|
+
return micromatch.isMatch(path, servicePathGlobs.match, {
|
|
42
|
+
ignore: servicePathGlobs.ignore,
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=filterDocumentPaths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterDocumentPaths.js","sourceRoot":"","sources":["../../src/lib/filterDocumentPaths.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAIpC;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,MAAyB,EACzB,YAAkC,EAClC,EAAE;IACF,IAAI,CAAC,YAAY;QAAE,OAAO,MAAM,CAAC;IAEjC,MAAM,WAAW,GAAG,sBAAsB,CAAC,YAAY,CAAC,CAAC;IACzD,MAAM,KAAK,GAAwB,EAAE,CAAC;IAEtC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC;YAAE,SAAS;QACxE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;YAAE,SAAS;QACjC,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC;AAC9B,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,YAAsB,EAAE,EAAE;IAC/D,MAAM,gBAAgB,GAAG,YAAY,CAAC,MAAM,CAG1C,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;QACZ,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAClB,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAChC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzB,OAAO,GAAG,CAAC;IACb,CAAC,EACD;QACE,KAAK,EAAE,EAAE;QACT,MAAM,EAAE,EAAE;KACX,CACF,CAAC;IAEF,OAAO,SAAS,mBAAmB,CAAC,IAAY;QAC9C,OAAO,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,gBAAgB,CAAC,KAAK,EAAE;YACtD,MAAM,EAAE,gBAAgB,CAAC,MAAM;SAChC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatFileHeader.d.ts","sourceRoot":"","sources":["../../src/lib/formatFileHeader.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,eAAgB,MAAM,GAAG,SAAS,WAG9D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatFileHeader.js","sourceRoot":"","sources":["../../src/lib/formatFileHeader.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,UAA8B,EAAE,EAAE;IACjE,IAAI,CAAC,UAAU;QAAE,OAAO,EAAE,CAAC;IAC3B,OAAO,GAAG,UAAU,GAAG,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AACjE,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import { URL } from 'node:url';
|
|
4
|
+
import type { Ora } from 'ora';
|
|
5
|
+
/**
|
|
6
|
+
* Validates Schema's `input` and return `Readable` stream or `URL`
|
|
7
|
+
* @throws {Error} if input is invalid
|
|
8
|
+
*/
|
|
9
|
+
export declare function handleSchemaInput(input: unknown, cwd: URL, spinner: Ora): URL | (NodeJS.ReadStream & {
|
|
10
|
+
fd: 0;
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=handleSchemaInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleSchemaInput.d.ts","sourceRoot":"","sources":["../../src/lib/handleSchemaInput.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE/B;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG;;GA4CvE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { URL } from 'node:url';
|
|
3
|
+
/**
|
|
4
|
+
* Validates Schema's `input` and return `Readable` stream or `URL`
|
|
5
|
+
* @throws {Error} if input is invalid
|
|
6
|
+
*/
|
|
7
|
+
export function handleSchemaInput(input, cwd, spinner) {
|
|
8
|
+
if (!input) {
|
|
9
|
+
/**
|
|
10
|
+
* Handle `stdin`, if no input file is provided
|
|
11
|
+
* @example
|
|
12
|
+
* ```bash
|
|
13
|
+
* cat schema.json | script.js
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
if (process.stdin.isTTY) {
|
|
17
|
+
spinner.fail('Input file not found or stdin is empty. Please specify `--input` option or pipe OpenAPI Schema to stdin.');
|
|
18
|
+
throw new Error('Invalid input.');
|
|
19
|
+
}
|
|
20
|
+
return process.stdin;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Handle single file
|
|
24
|
+
* @example
|
|
25
|
+
* ```bash
|
|
26
|
+
* script.js schema.json
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
if (typeof input !== 'string') {
|
|
30
|
+
spinner.fail('Invalid input. Please specify a single file or URL.');
|
|
31
|
+
throw new Error('Invalid input.');
|
|
32
|
+
}
|
|
33
|
+
// throw error on glob
|
|
34
|
+
if (input.includes('*')) {
|
|
35
|
+
spinner.fail('Globbing is not supported. Please specify a single file or URL.');
|
|
36
|
+
throw new Error('Globbing is not supported.');
|
|
37
|
+
}
|
|
38
|
+
return new URL(input, cwd);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=handleSchemaInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleSchemaInput.js","sourceRoot":"","sources":["../../src/lib/handleSchemaInput.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAG/B;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAc,EAAE,GAAQ,EAAE,OAAY;IACtE,IAAI,CAAC,KAAK,EAAE,CAAC;QACX;;;;;;WAMG;QACH,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACxB,OAAO,CAAC,IAAI,CACV,0GAA0G,CAC3G,CAAC;YAEF,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;QACpC,CAAC;QAED,OAAO,OAAO,CAAC,KAAK,CAAC;IACvB,CAAC;IAED;;;;;;OAMG;IAEH,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAC;QAEpE,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACpC,CAAC;IAED,sBAAsB;IACtB,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO,CAAC,IAAI,CACV,iEAAiE,CAClE,CAAC;QAEF,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,IAAI,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC7B,CAAC"}
|