@openapi-qraft/cli 2.14.0 → 2.15.0-beta.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 +33 -0
- package/README.md +0 -2
- package/dist/bin.d.ts +1 -12
- package/dist/bin.d.ts.map +1 -1
- package/dist/bin.js +20 -58
- package/dist/bin.js.map +1 -1
- package/dist/builtInPlugins.d.ts.map +1 -1
- package/dist/builtInPlugins.js.map +1 -1
- package/package.json +7 -5
- package/src/bin.ts +30 -76
- package/src/builtInPlugins.ts +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @openapi-qraft/cli
|
|
2
2
|
|
|
3
|
+
## 2.15.0-beta.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a282960: Introduce unified CLI tool `@qraft/cli` that extends code generation capabilities beyond OpenAPI to support AsyncAPI
|
|
8
|
+
specifications. The new CLI provides three main commands:
|
|
9
|
+
- `qraft openapi` - Generate type-safe code from OpenAPI documents (React Query hooks and TypeScript types)
|
|
10
|
+
- `qraft asyncapi` - Generate TypeScript types from AsyncAPI documents
|
|
11
|
+
- `qraft redocly` - Generate code from Redocly configuration files supporting both OpenAPI and AsyncAPI APIs
|
|
12
|
+
|
|
13
|
+
The CLI uses a plugin-based architecture where plugins are installed as peer dependencies, allowing users to install
|
|
14
|
+
only the plugins they need. It maintains full backward compatibility with existing OpenAPI workflows while adding
|
|
15
|
+
seamless support for event-driven API specifications.
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [7074f50]
|
|
20
|
+
- Updated dependencies [a282960]
|
|
21
|
+
- @openapi-qraft/tanstack-query-react-plugin@2.15.0-beta.1
|
|
22
|
+
- @openapi-qraft/openapi-typescript-plugin@2.15.0-beta.1
|
|
23
|
+
- @openapi-qraft/plugin@2.15.0-beta.1
|
|
24
|
+
- @qraft/cli-utils@1.0.0-beta.0
|
|
25
|
+
- @qraft/plugin@1.0.0-beta.0
|
|
26
|
+
|
|
27
|
+
## 2.15.0-beta.0
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- Updated dependencies [87730d2]
|
|
32
|
+
- @openapi-qraft/tanstack-query-react-plugin@2.15.0-beta.0
|
|
33
|
+
- @openapi-qraft/plugin@2.15.0-beta.0
|
|
34
|
+
- @openapi-qraft/openapi-typescript-plugin@2.15.0-beta.0
|
|
35
|
+
|
|
3
36
|
## 2.14.0
|
|
4
37
|
|
|
5
38
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -209,8 +209,6 @@ The following plugins are currently supported:
|
|
|
209
209
|
- `--openapi-types-import-path ../openapi.d.ts`
|
|
210
210
|
- `--openapi-types-import-path '@/api/openapi.d.ts'`
|
|
211
211
|
- `--openapi-types-import-path '@external-package-types'`
|
|
212
|
-
- **`--operation-generics-import-path <path>`:** Define the path to the operation generics file, allowing for custom
|
|
213
|
-
operation handling _(optional, default: `@openapi-qraft/react`)_.
|
|
214
212
|
- **`--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)_
|
|
215
213
|
|
|
216
214
|
### `--plugin openapi-typescript` options
|
package/dist/bin.d.ts
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { ParseOptions } from 'commander';
|
|
2
|
+
import type { ParseOptions } from 'commander';
|
|
3
3
|
export declare function main(processArgv: string[], processArgvParseOptions?: ParseOptions): Promise<void>;
|
|
4
|
-
/**
|
|
5
|
-
* Extracts multiple `--plugin <name>` options from `argv`
|
|
6
|
-
* and returns both the filtered `argv` and the extracted plugins list.
|
|
7
|
-
*/
|
|
8
|
-
export declare function extractArgvPluginOptions(argv: string[]): {
|
|
9
|
-
argv: string[];
|
|
10
|
-
plugins?: undefined;
|
|
11
|
-
} | {
|
|
12
|
-
argv: string[];
|
|
13
|
-
plugins: string[];
|
|
14
|
-
};
|
|
15
4
|
//# sourceMappingURL=bin.d.ts.map
|
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":";AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAgB9C,wBAAsB,IAAI,CACxB,WAAW,EAAE,MAAM,EAAE,EACrB,uBAAuB,CAAC,EAAE,YAAY,iBAavC"}
|
package/dist/bin.js
CHANGED
|
@@ -1,83 +1,45 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { QraftCommand } from '@openapi-qraft/plugin';
|
|
3
|
-
import {
|
|
3
|
+
import { addCommandUsageWithPlugins, createFileHeader, extractArgvPluginOptions, setupPlugins, } from '@qraft/cli-utils';
|
|
4
|
+
import { OPENAPI_QRAFT_REDOC_CONFIG_KEY, RedoclyConfigCommand, } from '@qraft/plugin/lib/RedoclyConfigCommand';
|
|
4
5
|
import { Option } from 'commander';
|
|
5
6
|
import { builtInPlugins } from './builtInPlugins.js';
|
|
6
7
|
import { handleDeprecatedOptions } from './handleDeprecatedOptions.js';
|
|
7
8
|
export async function main(processArgv, processArgvParseOptions) {
|
|
8
9
|
const argv = handleDeprecatedOptions(processArgv);
|
|
9
|
-
const redoclyConfigParseResult = await new RedoclyConfigCommand().parseConfig(qraft, argv, processArgvParseOptions);
|
|
10
|
+
const redoclyConfigParseResult = await new RedoclyConfigCommand().parseConfig({ [OPENAPI_QRAFT_REDOC_CONFIG_KEY]: qraft }, argv, processArgvParseOptions);
|
|
10
11
|
if (redoclyConfigParseResult?.length)
|
|
11
12
|
return;
|
|
12
13
|
await qraft(argv, processArgvParseOptions);
|
|
13
14
|
}
|
|
14
15
|
async function qraft(processArgv, processArgvParseOptions) {
|
|
15
|
-
const command = new QraftCommand(
|
|
16
|
+
const command = new QraftCommand(undefined, {
|
|
17
|
+
defaultFileHeader: createFileHeader('@openapi-qraft/cli'),
|
|
18
|
+
});
|
|
16
19
|
const { argv, plugins } = extractArgvPluginOptions(processArgv);
|
|
17
20
|
if (plugins) {
|
|
18
|
-
await setupPlugins(
|
|
21
|
+
await setupPlugins({
|
|
22
|
+
command,
|
|
23
|
+
plugins,
|
|
24
|
+
builtInPlugins,
|
|
25
|
+
addUsage: addCommandUsageWithPlugins,
|
|
26
|
+
});
|
|
19
27
|
}
|
|
20
28
|
else {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
await setupPlugins({
|
|
30
|
+
command,
|
|
31
|
+
plugins: [
|
|
32
|
+
'tanstack-query-react',
|
|
33
|
+
],
|
|
34
|
+
builtInPlugins,
|
|
35
|
+
addUsage: addCommandUsageWithPlugins,
|
|
36
|
+
});
|
|
26
37
|
command.addOption(new Option('--plugin <name_1> --plugin <name_2>', `Specifies which generator plugins should be used for code generation`)
|
|
27
38
|
.choices(Object.keys(builtInPlugins))
|
|
28
39
|
.argParser(() => {
|
|
29
|
-
// Fallback handler for when plugin parsing fails
|
|
30
40
|
throw new Error('The plugin option must be processed before command parsing and should not be directly passed to the commander');
|
|
31
41
|
}));
|
|
32
42
|
}
|
|
33
43
|
await command.parseAsync(argv, processArgvParseOptions);
|
|
34
44
|
}
|
|
35
|
-
async function setupPlugins(command, plugins) {
|
|
36
|
-
const pluginList = [];
|
|
37
|
-
for (const pluginName of plugins) {
|
|
38
|
-
if (!(pluginName in builtInPlugins))
|
|
39
|
-
throw new Error(`Unknown plugin: '${pluginName}'`);
|
|
40
|
-
pluginList.push((await builtInPlugins[pluginName]())
|
|
41
|
-
.default);
|
|
42
|
-
addCommandUsageWithPlugins(command, plugins);
|
|
43
|
-
}
|
|
44
|
-
await Promise.all(pluginList.map((plugin) => plugin.setupCommand(command)));
|
|
45
|
-
await Promise.all(pluginList.map((plugin) => plugin.postSetupCommand?.(command, plugins)));
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Adds plugin usage instructions by calling `command.usage(...)`
|
|
49
|
-
*/
|
|
50
|
-
function addCommandUsageWithPlugins(command, plugins) {
|
|
51
|
-
const pluginUsage = plugins.map((plugin) => `--plugin ${plugin}`).join(' ');
|
|
52
|
-
command.usage(`${pluginUsage} [input] [options]`);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Extracts multiple `--plugin <name>` options from `argv`
|
|
56
|
-
* and returns both the filtered `argv` and the extracted plugins list.
|
|
57
|
-
*/
|
|
58
|
-
export function extractArgvPluginOptions(argv) {
|
|
59
|
-
const pluginIndex = argv.indexOf('--plugin');
|
|
60
|
-
if (pluginIndex === -1)
|
|
61
|
-
return { argv };
|
|
62
|
-
const filteredArgv = argv.slice(0, pluginIndex);
|
|
63
|
-
const plugins = [];
|
|
64
|
-
for (let i = pluginIndex; i < argv.length; i++) {
|
|
65
|
-
if (argv[i] === '--plugin') {
|
|
66
|
-
const pluginName = argv.at(i + 1);
|
|
67
|
-
if (!pluginName)
|
|
68
|
-
throw new Error(`A plugin name must be specified after the '--plugin' option`);
|
|
69
|
-
if (pluginName?.startsWith('--'))
|
|
70
|
-
throw new Error(`Invalid plugin name: '${pluginName}'. Plugin names cannot start with '--'`);
|
|
71
|
-
plugins.push(pluginName);
|
|
72
|
-
i++; // Skip next item
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
filteredArgv.push(argv[i]);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
argv: filteredArgv,
|
|
80
|
-
plugins,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
45
|
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EACL,0BAA0B,EAC1B,gBAAgB,EAChB,wBAAwB,EACxB,YAAY,GACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,8BAA8B,EAC9B,oBAAoB,GACrB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,MAAM,CAAC,KAAK,UAAU,IAAI,CACxB,WAAqB,EACrB,uBAAsC;IAEtC,MAAM,IAAI,GAAG,uBAAuB,CAAC,WAAW,CAAC,CAAC;IAElD,MAAM,wBAAwB,GAAG,MAAM,IAAI,oBAAoB,EAAE,CAAC,WAAW,CAC3E,EAAE,CAAC,8BAA8B,CAAC,EAAE,KAAK,EAAE,EAC3C,IAAI,EACJ,uBAAuB,CACxB,CAAC;IAEF,IAAI,wBAAwB,EAAE,MAAM;QAAE,OAAO;IAE7C,MAAM,KAAK,CAAC,IAAI,EAAE,uBAAuB,CAAC,CAAC;AAC7C,CAAC;AAED,KAAK,UAAU,KAAK,CAClB,WAAqB,EACrB,uBAAsC;IAEtC,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,SAAS,EAAE;QAC1C,iBAAiB,EAAE,gBAAgB,CAAC,oBAAoB,CAAC;KAC1D,CAAC,CAAC;IAEH,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,wBAAwB,CAAC,WAAW,CAAC,CAAC;IAEhE,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,YAAY,CAAC;YACjB,OAAO;YACP,OAAO;YACP,cAAc;YACd,QAAQ,EAAE,0BAA0B;SACrC,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,MAAM,YAAY,CAAC;YACjB,OAAO;YACP,OAAO,EAAE;gBACP,sBAAsB;aACmB;YAC3C,cAAc;YACd,QAAQ,EAAE,0BAA0B;SACrC,CAAC,CAAC;QAEH,OAAO,CAAC,SAAS,CACf,IAAI,MAAM,CACR,qCAAqC,EACrC,sEAAsE,CACvE;aACE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;aACpC,SAAS,CAAC,GAAG,EAAE;YACd,MAAM,IAAI,KAAK,CACb,+GAA+G,CAChH,CAAC;QACJ,CAAC,CAAC,CACL,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,uBAAuB,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builtInPlugins.d.ts","sourceRoot":"","sources":["../src/builtInPlugins.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"builtInPlugins.d.ts","sourceRoot":"","sources":["../src/builtInPlugins.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc;;;CAKQ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builtInPlugins.js","sourceRoot":"","sources":["../src/builtInPlugins.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"builtInPlugins.js","sourceRoot":"","sources":["../src/builtInPlugins.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,sBAAsB,EAAE,GAAG,EAAE,CAC3B,MAAM,CAAC,4CAA4C,CAAC;IACtD,oBAAoB,EAAE,GAAG,EAAE,CACzB,MAAM,CAAC,0CAA0C,CAAC;CACnB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-qraft/cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.0-beta.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,11 @@
|
|
|
15
15
|
"openapi-qraft": "./bin.mjs"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@openapi-qraft/openapi-typescript-plugin": "2.
|
|
19
|
-
"@openapi-qraft/plugin": "2.
|
|
20
|
-
"@openapi-qraft/tanstack-query-react-plugin": "2.
|
|
18
|
+
"@openapi-qraft/openapi-typescript-plugin": "2.15.0-beta.1",
|
|
19
|
+
"@openapi-qraft/plugin": "2.15.0-beta.1",
|
|
20
|
+
"@openapi-qraft/tanstack-query-react-plugin": "2.15.0-beta.1",
|
|
21
|
+
"@qraft/cli-utils": "1.0.0-beta.0",
|
|
22
|
+
"@qraft/plugin": "1.0.0-beta.0",
|
|
21
23
|
"ansi-colors": "^4.1.3",
|
|
22
24
|
"commander": "^14.0.2"
|
|
23
25
|
},
|
|
@@ -56,7 +58,7 @@
|
|
|
56
58
|
"repository": {
|
|
57
59
|
"type": "git",
|
|
58
60
|
"url": "git+https://github.com/OpenAPI-Qraft/openapi-qraft.git",
|
|
59
|
-
"directory": "packages/cli"
|
|
61
|
+
"directory": "packages/openapi-cli"
|
|
60
62
|
},
|
|
61
63
|
"bugs": {
|
|
62
64
|
"url": "https://github.com/OpenAPI-Qraft/openapi-qraft/issues"
|
package/src/bin.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import type {
|
|
2
|
+
import type { ParseOptions } from 'commander';
|
|
3
3
|
import { QraftCommand } from '@openapi-qraft/plugin';
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
addCommandUsageWithPlugins,
|
|
6
|
+
createFileHeader,
|
|
7
|
+
extractArgvPluginOptions,
|
|
8
|
+
setupPlugins,
|
|
9
|
+
} from '@qraft/cli-utils';
|
|
10
|
+
import {
|
|
11
|
+
OPENAPI_QRAFT_REDOC_CONFIG_KEY,
|
|
12
|
+
RedoclyConfigCommand,
|
|
13
|
+
} from '@qraft/plugin/lib/RedoclyConfigCommand';
|
|
14
|
+
import { Option } from 'commander';
|
|
6
15
|
import { builtInPlugins } from './builtInPlugins.js';
|
|
7
16
|
import { handleDeprecatedOptions } from './handleDeprecatedOptions.js';
|
|
8
17
|
|
|
@@ -13,7 +22,7 @@ export async function main(
|
|
|
13
22
|
const argv = handleDeprecatedOptions(processArgv);
|
|
14
23
|
|
|
15
24
|
const redoclyConfigParseResult = await new RedoclyConfigCommand().parseConfig(
|
|
16
|
-
qraft,
|
|
25
|
+
{ [OPENAPI_QRAFT_REDOC_CONFIG_KEY]: qraft },
|
|
17
26
|
argv,
|
|
18
27
|
processArgvParseOptions
|
|
19
28
|
);
|
|
@@ -27,19 +36,29 @@ async function qraft(
|
|
|
27
36
|
processArgv: string[],
|
|
28
37
|
processArgvParseOptions?: ParseOptions
|
|
29
38
|
) {
|
|
30
|
-
const command = new QraftCommand(
|
|
39
|
+
const command = new QraftCommand(undefined, {
|
|
40
|
+
defaultFileHeader: createFileHeader('@openapi-qraft/cli'),
|
|
41
|
+
});
|
|
31
42
|
|
|
32
43
|
const { argv, plugins } = extractArgvPluginOptions(processArgv);
|
|
33
44
|
|
|
34
45
|
if (plugins) {
|
|
35
|
-
await setupPlugins(
|
|
46
|
+
await setupPlugins({
|
|
47
|
+
command,
|
|
48
|
+
plugins,
|
|
49
|
+
builtInPlugins,
|
|
50
|
+
addUsage: addCommandUsageWithPlugins,
|
|
51
|
+
});
|
|
36
52
|
} else {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
53
|
+
await setupPlugins({
|
|
54
|
+
command,
|
|
55
|
+
plugins: [
|
|
56
|
+
'tanstack-query-react',
|
|
57
|
+
] satisfies (keyof typeof builtInPlugins)[],
|
|
58
|
+
builtInPlugins,
|
|
59
|
+
addUsage: addCommandUsageWithPlugins,
|
|
60
|
+
});
|
|
41
61
|
|
|
42
|
-
// Option to display help with all available plugins
|
|
43
62
|
command.addOption(
|
|
44
63
|
new Option(
|
|
45
64
|
'--plugin <name_1> --plugin <name_2>',
|
|
@@ -47,7 +66,6 @@ async function qraft(
|
|
|
47
66
|
)
|
|
48
67
|
.choices(Object.keys(builtInPlugins))
|
|
49
68
|
.argParser(() => {
|
|
50
|
-
// Fallback handler for when plugin parsing fails
|
|
51
69
|
throw new Error(
|
|
52
70
|
'The plugin option must be processed before command parsing and should not be directly passed to the commander'
|
|
53
71
|
);
|
|
@@ -57,67 +75,3 @@ async function qraft(
|
|
|
57
75
|
|
|
58
76
|
await command.parseAsync(argv, processArgvParseOptions);
|
|
59
77
|
}
|
|
60
|
-
|
|
61
|
-
async function setupPlugins(command: QraftCommand, plugins: string[]) {
|
|
62
|
-
const pluginList: QraftCommandPlugin[] = [];
|
|
63
|
-
|
|
64
|
-
for (const pluginName of plugins) {
|
|
65
|
-
if (!(pluginName in builtInPlugins))
|
|
66
|
-
throw new Error(`Unknown plugin: '${pluginName}'`);
|
|
67
|
-
|
|
68
|
-
pluginList.push(
|
|
69
|
-
(await builtInPlugins[pluginName as keyof typeof builtInPlugins]())
|
|
70
|
-
.default
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
addCommandUsageWithPlugins(command, plugins);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
await Promise.all(pluginList.map((plugin) => plugin.setupCommand(command)));
|
|
77
|
-
await Promise.all(
|
|
78
|
-
pluginList.map((plugin) => plugin.postSetupCommand?.(command, plugins))
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Adds plugin usage instructions by calling `command.usage(...)`
|
|
84
|
-
*/
|
|
85
|
-
function addCommandUsageWithPlugins(command: QraftCommand, plugins: string[]) {
|
|
86
|
-
const pluginUsage = plugins.map((plugin) => `--plugin ${plugin}`).join(' ');
|
|
87
|
-
command.usage(`${pluginUsage} [input] [options]`);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Extracts multiple `--plugin <name>` options from `argv`
|
|
92
|
-
* and returns both the filtered `argv` and the extracted plugins list.
|
|
93
|
-
*/
|
|
94
|
-
export function extractArgvPluginOptions(argv: string[]) {
|
|
95
|
-
const pluginIndex = argv.indexOf('--plugin');
|
|
96
|
-
if (pluginIndex === -1) return { argv };
|
|
97
|
-
|
|
98
|
-
const filteredArgv: string[] = argv.slice(0, pluginIndex);
|
|
99
|
-
const plugins: string[] = [];
|
|
100
|
-
|
|
101
|
-
for (let i = pluginIndex; i < argv.length; i++) {
|
|
102
|
-
if (argv[i] === '--plugin') {
|
|
103
|
-
const pluginName = argv.at(i + 1);
|
|
104
|
-
if (!pluginName)
|
|
105
|
-
throw new Error(
|
|
106
|
-
`A plugin name must be specified after the '--plugin' option`
|
|
107
|
-
);
|
|
108
|
-
if (pluginName?.startsWith('--'))
|
|
109
|
-
throw new Error(
|
|
110
|
-
`Invalid plugin name: '${pluginName}'. Plugin names cannot start with '--'`
|
|
111
|
-
);
|
|
112
|
-
plugins.push(pluginName);
|
|
113
|
-
i++; // Skip next item
|
|
114
|
-
} else {
|
|
115
|
-
filteredArgv.push(argv[i]);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return {
|
|
120
|
-
argv: filteredArgv,
|
|
121
|
-
plugins,
|
|
122
|
-
};
|
|
123
|
-
}
|
package/src/builtInPlugins.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { BuiltInPlugins } from '@qraft/cli-utils';
|
|
2
|
+
|
|
1
3
|
export const builtInPlugins = {
|
|
2
4
|
'tanstack-query-react': () =>
|
|
3
5
|
import('@openapi-qraft/tanstack-query-react-plugin'),
|
|
4
6
|
'openapi-typescript': () =>
|
|
5
7
|
import('@openapi-qraft/openapi-typescript-plugin'),
|
|
6
|
-
} as const;
|
|
8
|
+
} as const satisfies BuiltInPlugins;
|