@openapi-qraft/cli 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 CHANGED
@@ -1,5 +1,39 @@
1
1
  # @openapi-qraft/cli
2
2
 
3
+ ## 2.15.0-beta.2
4
+
5
+ ### Patch Changes
6
+
7
+ - @openapi-qraft/plugin@2.15.0-beta.2
8
+ - @openapi-qraft/tanstack-query-react-plugin@2.15.0-beta.2
9
+ - @openapi-qraft/openapi-typescript-plugin@2.15.0-beta.2
10
+ - @qraft/cli-utils@1.0.0-beta.1
11
+ - @qraft/plugin@1.0.0-beta.1
12
+
13
+ ## 2.15.0-beta.1
14
+
15
+ ### Minor Changes
16
+
17
+ - a282960: Introduce unified CLI tool `@qraft/cli` that extends code generation capabilities beyond OpenAPI to support AsyncAPI
18
+ specifications. The new CLI provides three main commands:
19
+ - `qraft openapi` - Generate type-safe code from OpenAPI documents (React Query hooks and TypeScript types)
20
+ - `qraft asyncapi` - Generate TypeScript types from AsyncAPI documents
21
+ - `qraft redocly` - Generate code from Redocly configuration files supporting both OpenAPI and AsyncAPI APIs
22
+
23
+ The CLI uses a plugin-based architecture where plugins are installed as peer dependencies, allowing users to install
24
+ only the plugins they need. It maintains full backward compatibility with existing OpenAPI workflows while adding
25
+ seamless support for event-driven API specifications.
26
+
27
+ ### Patch Changes
28
+
29
+ - Updated dependencies [7074f50]
30
+ - Updated dependencies [a282960]
31
+ - @openapi-qraft/tanstack-query-react-plugin@2.15.0-beta.1
32
+ - @openapi-qraft/openapi-typescript-plugin@2.15.0-beta.1
33
+ - @openapi-qraft/plugin@2.15.0-beta.1
34
+ - @qraft/cli-utils@1.0.0-beta.0
35
+ - @qraft/plugin@1.0.0-beta.0
36
+
3
37
  ## 2.15.0-beta.0
4
38
 
5
39
  ### Patch Changes
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":";AAIA,OAAO,EAAU,YAAY,EAAE,MAAM,WAAW,CAAC;AAIjD,wBAAsB,IAAI,CACxB,WAAW,EAAE,MAAM,EAAE,EACrB,uBAAuB,CAAC,EAAE,YAAY,iBAavC;AAkED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE;;;;;;EA6BtD"}
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 { RedoclyConfigCommand } from '@openapi-qraft/plugin/lib/RedoclyConfigCommand';
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(command, plugins);
21
+ await setupPlugins({
22
+ command,
23
+ plugins,
24
+ builtInPlugins,
25
+ addUsage: addCommandUsageWithPlugins,
26
+ });
19
27
  }
20
28
  else {
21
- // Default - set up the tanstack-query-react plugin
22
- await setupPlugins(command, [
23
- 'tanstack-query-react',
24
- ]);
25
- // Option to display help with all available plugins
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,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAC;AACtF,OAAO,EAAE,MAAM,EAAgB,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAA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eAAO,MAAM,cAAc;;;CAKjB,CAAC"}
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":"AAAA,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;CAC5C,CAAC"}
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.15.0-beta.0",
3
+ "version": "2.15.0-beta.2",
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.15.0-beta.0",
19
- "@openapi-qraft/plugin": "2.15.0-beta.0",
20
- "@openapi-qraft/tanstack-query-react-plugin": "2.15.0-beta.0",
18
+ "@openapi-qraft/openapi-typescript-plugin": "2.15.0-beta.2",
19
+ "@openapi-qraft/plugin": "2.15.0-beta.2",
20
+ "@openapi-qraft/tanstack-query-react-plugin": "2.15.0-beta.2",
21
+ "@qraft/cli-utils": "1.0.0-beta.1",
22
+ "@qraft/plugin": "1.0.0-beta.1",
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 { QraftCommandPlugin } from '@openapi-qraft/plugin/lib/QraftCommandPlugin';
2
+ import type { ParseOptions } from 'commander';
3
3
  import { QraftCommand } from '@openapi-qraft/plugin';
4
- import { RedoclyConfigCommand } from '@openapi-qraft/plugin/lib/RedoclyConfigCommand';
5
- import { Option, ParseOptions } from 'commander';
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(command, plugins);
46
+ await setupPlugins({
47
+ command,
48
+ plugins,
49
+ builtInPlugins,
50
+ addUsage: addCommandUsageWithPlugins,
51
+ });
36
52
  } else {
37
- // Default - set up the tanstack-query-react plugin
38
- await setupPlugins(command, [
39
- 'tanstack-query-react',
40
- ] satisfies (keyof typeof builtInPlugins)[]);
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
- }
@@ -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;