@openapi-qraft/cli 2.3.2 → 2.4.1
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 +21 -0
- package/README.md +50 -31
- package/bin.mjs +1 -1
- package/dist/bin.d.ts +4 -3
- package/dist/bin.d.ts.map +1 -1
- package/dist/bin.js +21 -15
- package/dist/bin.js.map +1 -1
- package/package.json +7 -4
- package/src/bin.ts +39 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @openapi-qraft/cli
|
|
2
2
|
|
|
3
|
+
## 2.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @openapi-qraft/plugin@2.4.1
|
|
8
|
+
- @openapi-qraft/tanstack-query-react-plugin@2.4.1
|
|
9
|
+
- @openapi-qraft/openapi-typescript-plugin@1.2.14
|
|
10
|
+
|
|
11
|
+
## 2.4.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- cc314c3: Added support for Redocly configuration, allowing to generate multiple API clients in a single command.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [cc314c3]
|
|
20
|
+
- @openapi-qraft/plugin@2.4.0
|
|
21
|
+
- @openapi-qraft/openapi-typescript-plugin@1.2.13
|
|
22
|
+
- @openapi-qraft/tanstack-query-react-plugin@2.4.0
|
|
23
|
+
|
|
3
24
|
## 2.3.2
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -21,27 +21,29 @@ npm install -g @openapi-qraft/cli
|
|
|
21
21
|
```
|
|
22
22
|
Usage: openapi-qraft --plugin tanstack-query-react --plugin openapi-typescript [input] [options]
|
|
23
23
|
|
|
24
|
-
Generate
|
|
24
|
+
Generate a type-safe TanStack Query client for React from an OpenAPI Document.
|
|
25
25
|
|
|
26
26
|
Arguments:
|
|
27
|
-
input
|
|
27
|
+
input Input OpenAPI Document file path, URL (json, yml) (default: null)
|
|
28
28
|
|
|
29
29
|
Options:
|
|
30
30
|
-o, --output-dir <path> Output directory for generated services
|
|
31
31
|
-rm, --clean Clean output directory before generating services
|
|
32
|
-
--filter-services <glob-patterns...> Filter services to be generated
|
|
33
|
-
--operation-predefined-parameters <patterns...> Predefined parameters for services. The specified
|
|
34
|
-
|
|
35
|
-
--operation-name-modifier <patterns...> Modifies operation names using a pattern. Use the `==>` operator to separate the regular expression (left) and the substitution string (right). For
|
|
36
|
-
example: "post /**:[A-Za-z]+Id ==> createOne"
|
|
32
|
+
--filter-services <glob-patterns...> Filter services to be generated using glob patterns. Example: "/user/**,/post/**". For more details, see the NPM `micromatch` package documentation.
|
|
33
|
+
--operation-predefined-parameters <patterns...> Predefined parameters for services. The specified service parameters will be optional. Example: "/**:header.x-monite-version,query.x-api-key" or "get /**:header.x-monite-entity-id"
|
|
34
|
+
--operation-name-modifier <patterns...> Modifies operation names using a pattern. Use the `==>` operator to separate the regular expression (left) and the substitution string (right). For example: "post /**:[A-Za-z]+Id ==> createOne"
|
|
37
35
|
--postfix-services <string> Postfix to be added to the generated service name (eg: Service)
|
|
38
36
|
--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. (default: "endpoint[0]")
|
|
39
37
|
--file-header <string> Header to be added to the generated file (eg: /* eslint-disable */)
|
|
40
|
-
--
|
|
38
|
+
--redocly [config] Use the Redocly configuration to generate multiple API clients
|
|
39
|
+
If the [config] parameter is not specified, the default Redocly configuration will be used: [redocly.yaml | redocly.yml | .redocly.yaml | .redocly.yml].
|
|
40
|
+
For more information about this option, use the command: --redocly-help
|
|
41
|
+
Examples: "openapi-qraft --redocly", "openapi-qraft my-api@v1 external-api --redocly", "openapi-qraft --redocly
|
|
42
|
+
./my-redocly-config.yaml"
|
|
43
|
+
--openapi-types-import-path <path> Path to schema types file (.d.ts), e.g.: "../schema.d.ts"
|
|
41
44
|
--explicit-import-extensions [extension] All import statements will contain an explicit file extension. Ideal for projects using ECMAScript modules. (choices: ".js", ".ts", preset: ".js")
|
|
42
|
-
--export-openapi-types [bool]
|
|
43
|
-
--
|
|
44
|
-
--openapi-types-file-name <path> OpenAPI Schema types file name, eg: "schema.d.ts" (default: "schema.ts")
|
|
45
|
+
--export-openapi-types [bool] Add an export statement of the generated OpenAPI document types from the `./index.ts' file. Useful for sharing types within your project. (default: true)
|
|
46
|
+
--openapi-types-file-name <path> OpenAPI Schema types file name, e.g.: "schema.d.ts" (default: "schema.ts")
|
|
45
47
|
--enum Export true TS enums instead of unions
|
|
46
48
|
--enum-values Export enum values as arrays.
|
|
47
49
|
--dedupe-enums Dedupe enum types when `--enum` is set
|
|
@@ -95,7 +97,8 @@ npx openapi-qraft --plugin tanstack-query-react --plugin openapi-typescript http
|
|
|
95
97
|
a colon, and a comma-separated list of **operation parameters** to be set as optional.
|
|
96
98
|
More than one predefined parameter option can be specified.
|
|
97
99
|
|
|
98
|
-
This most
|
|
100
|
+
This option 💎 is arguably one of the most awesome features, allowing you to **set default parameters** across multiple endpoints.
|
|
101
|
+
However, if an endpoint doesn't contain a parameter specified in this option, an error will be displayed. For example:
|
|
99
102
|
|
|
100
103
|
```text
|
|
101
104
|
⚠ Missing predefined parameter 'header' 'x-monite-version' in 'post /files' in '/**'
|
|
@@ -108,16 +111,11 @@ npx openapi-qraft --plugin tanstack-query-react --plugin openapi-typescript http
|
|
|
108
111
|
```
|
|
109
112
|
|
|
110
113
|
- Examples:
|
|
111
|
-
|
|
112
114
|
- `--operation-predefined-parameters '/**:header.x-monite-version'` - set `header.x-monite-version`
|
|
113
115
|
as optional parameters for all services.
|
|
114
116
|
- `--operation-predefined-parameters '/**,!/auth/token:header.x-entity-id'` - set `header.x-entity-id` as optional parameters for all services except `/auth/token`.
|
|
115
117
|
- `--operation-predefined-parameters 'post,put /**:header.x-entity-id'` - set the `Header` record `x-entity-id` as an optional parameter for the `POST` and `PUT` methods.
|
|
116
118
|
|
|
117
|
-
> **Note:** In future versions of the library, this feature will be expanded. Not only will it make parameters
|
|
118
|
-
> optional, but it will also offer typed suggestions for these predefined parameters when creating a client. This enhancement will
|
|
119
|
-
> further improve type safety and developer experience.
|
|
120
|
-
|
|
121
119
|
- **`--operation-name-modifier <patterns...>`:** Modifies operation names using a pattern.
|
|
122
120
|
|
|
123
121
|
- **Pattern syntax:**
|
|
@@ -137,14 +135,32 @@ npx openapi-qraft --plugin tanstack-query-react --plugin openapi-typescript http
|
|
|
137
135
|
|
|
138
136
|
- **`--explicit-component-exports`:** Enabling this option will export API components as separate type aliases, alongside `components` interface.
|
|
139
137
|
|
|
140
|
-
- **`--
|
|
138
|
+
- **`--redocly [config]`:** Use the Redocly configuration to generate multiple API clients. If the `[config]` parameter is not specified, the default Redocly configuration will be used: `[redocly.yaml | redocly.yml | .redocly.yaml | .redocly.yml]`. _(optional)_
|
|
139
|
+
|
|
141
140
|
- Examples:
|
|
142
|
-
- `--
|
|
143
|
-
- `--
|
|
144
|
-
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
141
|
+
- `--redocly` - use the default Redocly configuration file
|
|
142
|
+
- `--redocly ./my-redocly-config.yaml` - use a custom Redocly configuration file
|
|
143
|
+
- `openapi-qraft my-api@v1 external-api --redocly` - generate clients for multiple APIs defined in the Redocly configuration
|
|
144
|
+
- For more information about this option, use the command: `--redocly-help`
|
|
145
|
+
|
|
146
|
+
- **`--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. _(optional, default: `endpoint[0]`)_.
|
|
147
|
+
- **`endpoint[<index>]`** - Use the path segment (e.g., `/0/1/2`) as the base name for the service.
|
|
148
|
+
- Examples:
|
|
149
|
+
- `--service-name-base endpoint[0]` generates `services/FooService.ts` for the endpoint `/foo/bar/baz`
|
|
150
|
+
- `--service-name-base endpoint[1]` generates `services/BarService.ts` for the endpoint `/foo/bar/baz`
|
|
151
|
+
- `--service-name-base endpoint[3]` generates `services/BazService.ts` for the endpoint `/foo/bar/baz` _(if the endpoint is shorter than the index, the last part is used)_
|
|
152
|
+
- If used `endpoint[<index>]` as the base name, operation names will be generated according to the specified index.
|
|
153
|
+
- For example:
|
|
154
|
+
- `--service-name-base endpoint[1]` for the endpoint `/api/bar` generates `get` operation name.
|
|
155
|
+
- `--service-name-base endpoint[1]` for the endpoint `/api/foo/bar` generates `getBar` operation name.
|
|
156
|
+
- **`tags`** - Use the OpenAPI Operation `tags` as the base name of the service.
|
|
157
|
+
- Examples:
|
|
158
|
+
- `--service-name-base tags` will generate services based on the OpenAPI Operation tags instead of the endpoint.
|
|
159
|
+
- If multiple tags are present for the operation, similar services will be created for each tag. Operation with `tags: [Foo, Bar]` will generate `services/FooService.ts` and `services/BarService.ts`.
|
|
160
|
+
- If there are no tags for the operation, the services will be created under the `default` tag. Operation with empty `tags: []` will generate `services/DefaultService.ts`.
|
|
161
|
+
- If `tags` are used as the base name, operation names will be generated based on the `operationId` from the
|
|
162
|
+
OpenAPI Operation, or from the path if `operationId` is not provided.
|
|
163
|
+
You can use `--operation-name-modifier` to customize the operation names.
|
|
148
164
|
- **`--explicit-import-extensions [extension]`**: All import statements will contain an explicit file extension. Ideal for projects using ECMAScript modules
|
|
149
165
|
when TypeScript's _--moduleResolution_ is `node16` or `nodenext`. Choices: `.js`, `.ts`, preset: `.js`. _(optional)_
|
|
150
166
|
- **`--file-header <string>`:** Add a custom header to each generated file, useful for disabling linting rules or adding file
|
|
@@ -182,12 +198,14 @@ The following plugins are currently supported:
|
|
|
182
198
|
- `--openapi-types-import-path '@external-package-types'`
|
|
183
199
|
- **`--operation-generics-import-path <path>`:** Define the path to the operation generics file, allowing for custom
|
|
184
200
|
operation handling _(optional, default: `@openapi-qraft/react`)_.
|
|
185
|
-
- **`--export-openapi-types [bool]`:**
|
|
201
|
+
- **`--export-openapi-types [bool]`:** Add an export statement of the generated OpenAPI document types from the `./index.ts` file. Useful for sharing types within your project. _(optional, default: `true`, if `--plugin openapi-typescript` is used)_
|
|
186
202
|
|
|
187
203
|
### `--plugin openapi-typescript` options
|
|
188
204
|
|
|
189
205
|
- **`--openapi-types-file-name <path>`**: OpenAPI Schema types file name, e.g., `schema.d.ts` (default: `schema.ts`).
|
|
190
206
|
- **`--enum`**: Export true TypeScript enums instead of unions.
|
|
207
|
+
- **`--enum-values`**: Export enum values as arrays.
|
|
208
|
+
- **`--dedupe-enums`**: Dedupe enum types when `--enum` is set.
|
|
191
209
|
- **`-t, --export-type`**: Export top-level `type` instead of `interface`.
|
|
192
210
|
- **`--immutable`**: Generate readonly types.
|
|
193
211
|
- **`--additional-properties`**: Treat schema objects as if `additionalProperties: true` is set.
|
|
@@ -199,20 +217,21 @@ The following plugins are currently supported:
|
|
|
199
217
|
- **`--alphabetize`**: Sort object keys alphabetically.
|
|
200
218
|
- **`--exclude-deprecated`**: Exclude deprecated types.
|
|
201
219
|
- **`--no-blob-from-binary`**: If this option is enabled, `format: binary` fields will not be converted to `Blob` types, preserving the native type. Could be used with `--plugin openapi-typescript` option.
|
|
220
|
+
- **`--explicit-component-exports`**: Enabling this option will export API components as separate type aliases, alongside `components` interface.
|
|
202
221
|
|
|
203
222
|
## In-project Setup
|
|
204
223
|
|
|
205
224
|
Add the following `"scripts"` to your `package.json` file:
|
|
206
225
|
|
|
207
|
-
```
|
|
226
|
+
```json5 title="package.json"
|
|
208
227
|
{
|
|
209
|
-
|
|
210
|
-
|
|
228
|
+
devDependencies: {
|
|
229
|
+
'@openapi-qraft/cli': 'latest',
|
|
211
230
|
},
|
|
212
|
-
|
|
213
|
-
|
|
231
|
+
scripts: {
|
|
232
|
+
'generate-client': 'openapi-qraft --plugin tanstack-query-react --plugin openapi-typescript https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml --output-dir src/api',
|
|
214
233
|
// ...other scripts
|
|
215
|
-
}
|
|
234
|
+
},
|
|
216
235
|
}
|
|
217
236
|
```
|
|
218
237
|
|
package/bin.mjs
CHANGED
package/dist/bin.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
import { ParseOptions } from 'commander';
|
|
3
|
+
export declare function main(processArgv: string[], processArgvParseOptions?: ParseOptions): Promise<void>;
|
|
3
4
|
/**
|
|
4
|
-
* Extracts multiple `--plugin <name>` options from
|
|
5
|
-
* and returns the filtered `argv` and the
|
|
5
|
+
* Extracts multiple `--plugin <name>` options from `argv`
|
|
6
|
+
* and returns both the filtered `argv` and the extracted plugins list.
|
|
6
7
|
*/
|
|
7
8
|
export declare function extractArgvPluginOptions(argv: string[]): {
|
|
8
9
|
argv: string[];
|
package/dist/bin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AAIA,OAAO,EAAU,YAAY,EAAE,MAAM,WAAW,CAAC;AAGjD,wBAAsB,IAAI,CACxB,WAAW,EAAE,MAAM,EAAE,EACrB,uBAAuB,CAAC,EAAE,YAAY,iBAWvC;AAkED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE;;;;;;EA6BtD"}
|
package/dist/bin.js
CHANGED
|
@@ -1,28 +1,34 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import { QraftCommand } from '@openapi-qraft/plugin';
|
|
3
|
+
import { RedoclyConfigCommand } from '@openapi-qraft/plugin/lib/RedoclyConfigCommand';
|
|
4
4
|
import { Option } from 'commander';
|
|
5
5
|
import { builtInPlugins } from './builtInPlugins.js';
|
|
6
|
-
export async function main() {
|
|
6
|
+
export async function main(processArgv, processArgvParseOptions) {
|
|
7
|
+
const redoclyConfigParseResult = await new RedoclyConfigCommand().parseConfig(qraft, processArgv, processArgvParseOptions);
|
|
8
|
+
if (redoclyConfigParseResult?.length)
|
|
9
|
+
return;
|
|
10
|
+
await qraft(processArgv, processArgvParseOptions);
|
|
11
|
+
}
|
|
12
|
+
async function qraft(processArgv, processArgvParseOptions) {
|
|
7
13
|
const command = new QraftCommand();
|
|
8
|
-
const { argv, plugins } = extractArgvPluginOptions(
|
|
14
|
+
const { argv, plugins } = extractArgvPluginOptions(processArgv);
|
|
9
15
|
if (plugins) {
|
|
10
16
|
await setupPlugins(command, plugins);
|
|
11
17
|
}
|
|
12
18
|
else {
|
|
13
|
-
//
|
|
19
|
+
// Default - set up the tanstack-query-react plugin
|
|
14
20
|
await setupPlugins(command, [
|
|
15
21
|
'tanstack-query-react',
|
|
16
22
|
]);
|
|
17
|
-
//
|
|
18
|
-
command.addOption(new Option('--plugin <name_1> --plugin <name_2>', `
|
|
23
|
+
// Option to display help with all available plugins
|
|
24
|
+
command.addOption(new Option('--plugin <name_1> --plugin <name_2>', `Specifies which generator plugins should be used for code generation`)
|
|
19
25
|
.choices(Object.keys(builtInPlugins))
|
|
20
26
|
.argParser(() => {
|
|
21
|
-
// Fallback
|
|
22
|
-
throw new Error('
|
|
27
|
+
// Fallback handler for when plugin parsing fails
|
|
28
|
+
throw new Error('The plugin option must be processed before command parsing and should not be directly passed to the commander');
|
|
23
29
|
}));
|
|
24
30
|
}
|
|
25
|
-
|
|
31
|
+
await command.parseAsync(argv, processArgvParseOptions);
|
|
26
32
|
}
|
|
27
33
|
async function setupPlugins(command, plugins) {
|
|
28
34
|
const pluginList = [];
|
|
@@ -37,15 +43,15 @@ async function setupPlugins(command, plugins) {
|
|
|
37
43
|
await Promise.all(pluginList.map((plugin) => plugin.postSetupCommand?.(command, plugins)));
|
|
38
44
|
}
|
|
39
45
|
/**
|
|
40
|
-
*
|
|
46
|
+
* Adds plugin usage instructions by calling `command.usage(...)`
|
|
41
47
|
*/
|
|
42
48
|
function addCommandUsageWithPlugins(command, plugins) {
|
|
43
49
|
const pluginUsage = plugins.map((plugin) => `--plugin ${plugin}`).join(' ');
|
|
44
50
|
command.usage(`${pluginUsage} [input] [options]`);
|
|
45
51
|
}
|
|
46
52
|
/**
|
|
47
|
-
* Extracts multiple `--plugin <name>` options from
|
|
48
|
-
* and returns the filtered `argv` and the
|
|
53
|
+
* Extracts multiple `--plugin <name>` options from `argv`
|
|
54
|
+
* and returns both the filtered `argv` and the extracted plugins list.
|
|
49
55
|
*/
|
|
50
56
|
export function extractArgvPluginOptions(argv) {
|
|
51
57
|
const pluginIndex = argv.indexOf('--plugin');
|
|
@@ -57,9 +63,9 @@ export function extractArgvPluginOptions(argv) {
|
|
|
57
63
|
if (argv[i] === '--plugin') {
|
|
58
64
|
const pluginName = argv.at(i + 1);
|
|
59
65
|
if (!pluginName)
|
|
60
|
-
throw new Error(`
|
|
66
|
+
throw new Error(`A plugin name must be specified after the '--plugin' option`);
|
|
61
67
|
if (pluginName?.startsWith('--'))
|
|
62
|
-
throw new Error(`Invalid plugin name: '${pluginName}'`);
|
|
68
|
+
throw new Error(`Invalid plugin name: '${pluginName}'. Plugin names cannot start with '--'`);
|
|
63
69
|
plugins.push(pluginName);
|
|
64
70
|
i++; // Skip next item
|
|
65
71
|
}
|
package/dist/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAC;AACtF,OAAO,EAAE,MAAM,EAAgB,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,MA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AC,CAAC,KAAK,UAAU,EAAE,CAAC;YAC3B,MAAM,UAAU,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAClC,IAAI,CAAC,UAAU;gBACb,MAAM,IAAI,KAAK,CACb,6DAA6D,CAC9D,CAAC;YACJ,IAAI,UAAU,EAAE,UAAU,CAAC,IAAI,CAAC;gBAC9B,MAAM,IAAI,KAAK,CACb,yBAAyB,UAAU,wCAAwC,CAC5E,CAAC;YACJ,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACzB,CAAC,EAAE,CAAC,CAAC,iBAAiB;QACxB,CAAC;aAAM,CAAC;YACN,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,EAAE,YAAY;QAClB,OAAO;KACR,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-qraft/cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "CLI for generating typed TanStack Query React Hooks and services from OpenAPI Document, improving type safety in React apps",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc --project tsconfig.build.json",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"openapi-qraft": "./bin.mjs"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@openapi-qraft/openapi-typescript-plugin": "1.2.
|
|
19
|
-
"@openapi-qraft/plugin": "2.
|
|
20
|
-
"@openapi-qraft/tanstack-query-react-plugin": "2.
|
|
18
|
+
"@openapi-qraft/openapi-typescript-plugin": "1.2.14",
|
|
19
|
+
"@openapi-qraft/plugin": "2.4.1",
|
|
20
|
+
"@openapi-qraft/tanstack-query-react-plugin": "2.4.1",
|
|
21
21
|
"commander": "^11.1.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
@@ -28,6 +28,9 @@
|
|
|
28
28
|
"typescript": "^5.6.2",
|
|
29
29
|
"vitest": "^3.0.5"
|
|
30
30
|
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"ansi-colors": "^4.1.3"
|
|
33
|
+
},
|
|
31
34
|
"files": [
|
|
32
35
|
"dist",
|
|
33
36
|
"src",
|
package/src/bin.ts
CHANGED
|
@@ -1,40 +1,58 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import type { QraftCommandPlugin } from '@openapi-qraft/plugin/lib/QraftCommandPlugin';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { Option } from 'commander';
|
|
3
|
+
import { QraftCommand } from '@openapi-qraft/plugin';
|
|
4
|
+
import { RedoclyConfigCommand } from '@openapi-qraft/plugin/lib/RedoclyConfigCommand';
|
|
5
|
+
import { Option, ParseOptions } from 'commander';
|
|
6
6
|
import { builtInPlugins } from './builtInPlugins.js';
|
|
7
7
|
|
|
8
|
-
export async function main(
|
|
8
|
+
export async function main(
|
|
9
|
+
processArgv: string[],
|
|
10
|
+
processArgvParseOptions?: ParseOptions
|
|
11
|
+
) {
|
|
12
|
+
const redoclyConfigParseResult = await new RedoclyConfigCommand().parseConfig(
|
|
13
|
+
qraft,
|
|
14
|
+
processArgv,
|
|
15
|
+
processArgvParseOptions
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
if (redoclyConfigParseResult?.length) return;
|
|
19
|
+
|
|
20
|
+
await qraft(processArgv, processArgvParseOptions);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function qraft(
|
|
24
|
+
processArgv: string[],
|
|
25
|
+
processArgvParseOptions?: ParseOptions
|
|
26
|
+
) {
|
|
9
27
|
const command = new QraftCommand();
|
|
10
28
|
|
|
11
|
-
const { argv, plugins } = extractArgvPluginOptions(
|
|
29
|
+
const { argv, plugins } = extractArgvPluginOptions(processArgv);
|
|
12
30
|
|
|
13
31
|
if (plugins) {
|
|
14
32
|
await setupPlugins(command, plugins);
|
|
15
33
|
} else {
|
|
16
|
-
//
|
|
34
|
+
// Default - set up the tanstack-query-react plugin
|
|
17
35
|
await setupPlugins(command, [
|
|
18
36
|
'tanstack-query-react',
|
|
19
37
|
] satisfies (keyof typeof builtInPlugins)[]);
|
|
20
38
|
|
|
21
|
-
//
|
|
39
|
+
// Option to display help with all available plugins
|
|
22
40
|
command.addOption(
|
|
23
41
|
new Option(
|
|
24
42
|
'--plugin <name_1> --plugin <name_2>',
|
|
25
|
-
`
|
|
43
|
+
`Specifies which generator plugins should be used for code generation`
|
|
26
44
|
)
|
|
27
45
|
.choices(Object.keys(builtInPlugins))
|
|
28
46
|
.argParser(() => {
|
|
29
|
-
// Fallback
|
|
47
|
+
// Fallback handler for when plugin parsing fails
|
|
30
48
|
throw new Error(
|
|
31
|
-
'
|
|
49
|
+
'The plugin option must be processed before command parsing and should not be directly passed to the commander'
|
|
32
50
|
);
|
|
33
51
|
})
|
|
34
52
|
);
|
|
35
53
|
}
|
|
36
54
|
|
|
37
|
-
|
|
55
|
+
await command.parseAsync(argv, processArgvParseOptions);
|
|
38
56
|
}
|
|
39
57
|
|
|
40
58
|
async function setupPlugins(command: QraftCommand, plugins: string[]) {
|
|
@@ -59,7 +77,7 @@ async function setupPlugins(command: QraftCommand, plugins: string[]) {
|
|
|
59
77
|
}
|
|
60
78
|
|
|
61
79
|
/**
|
|
62
|
-
*
|
|
80
|
+
* Adds plugin usage instructions by calling `command.usage(...)`
|
|
63
81
|
*/
|
|
64
82
|
function addCommandUsageWithPlugins(command: QraftCommand, plugins: string[]) {
|
|
65
83
|
const pluginUsage = plugins.map((plugin) => `--plugin ${plugin}`).join(' ');
|
|
@@ -67,8 +85,8 @@ function addCommandUsageWithPlugins(command: QraftCommand, plugins: string[]) {
|
|
|
67
85
|
}
|
|
68
86
|
|
|
69
87
|
/**
|
|
70
|
-
* Extracts multiple `--plugin <name>` options from
|
|
71
|
-
* and returns the filtered `argv` and the
|
|
88
|
+
* Extracts multiple `--plugin <name>` options from `argv`
|
|
89
|
+
* and returns both the filtered `argv` and the extracted plugins list.
|
|
72
90
|
*/
|
|
73
91
|
export function extractArgvPluginOptions(argv: string[]) {
|
|
74
92
|
const pluginIndex = argv.indexOf('--plugin');
|
|
@@ -80,9 +98,14 @@ export function extractArgvPluginOptions(argv: string[]) {
|
|
|
80
98
|
for (let i = pluginIndex; i < argv.length; i++) {
|
|
81
99
|
if (argv[i] === '--plugin') {
|
|
82
100
|
const pluginName = argv.at(i + 1);
|
|
83
|
-
if (!pluginName)
|
|
101
|
+
if (!pluginName)
|
|
102
|
+
throw new Error(
|
|
103
|
+
`A plugin name must be specified after the '--plugin' option`
|
|
104
|
+
);
|
|
84
105
|
if (pluginName?.startsWith('--'))
|
|
85
|
-
throw new Error(
|
|
106
|
+
throw new Error(
|
|
107
|
+
`Invalid plugin name: '${pluginName}'. Plugin names cannot start with '--'`
|
|
108
|
+
);
|
|
86
109
|
plugins.push(pluginName);
|
|
87
110
|
i++; // Skip next item
|
|
88
111
|
} else {
|