Skip to content

Commit 9f4cec4

Browse files
authored
Merge pull request #379 from OpenAPI-Qraft/chore/update-commander
feat: update commander
2 parents c15f121 + 59d2997 commit 9f4cec4

File tree

13 files changed

+106
-50
lines changed

13 files changed

+106
-50
lines changed

.changeset/shaggy-cats-jam.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@openapi-qraft/tanstack-query-react-plugin': minor
3+
'@openapi-qraft/openapi-typescript-plugin': minor
4+
'@openapi-qraft/plugin': minor
5+
'@openapi-qraft/cli': minor
6+
---
7+
8+
Deprecate `-rm` CLI option in favor of `-c` for `--clean` flag.
9+
10+
The `-rm` short flag for the `--clean` option has been deprecated due to commander.js v14 requiring single-character
11+
short flags. The option will continue to work but will show a deprecation warning. Please migrate to using `-c` or
12+
`--clean` instead. The `-rm` flag will be removed in v3.0.

packages/cli/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Arguments:
2828
2929
Options:
3030
-o, --output-dir <path> Output directory for generated services
31-
-rm, --clean Clean output directory before generating services
31+
-c, --clean Clean output directory before generating services
3232
--filter-services <glob-patterns...> Filter services to be generated using glob patterns. Example: "/user/**,/post/**". For more details, see the NPM `micromatch` package documentation.
3333
--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
3434
"get /**:header.x-monite-entity-id"
@@ -93,7 +93,7 @@ npx openapi-qraft --plugin tanstack-query-react --plugin openapi-typescript http
9393

9494
### Edge-case Options
9595

96-
- **`-rm, --clean`:** Clean the specified output directory services before generating to remove stale files _(optional)_.
96+
- **`-c, --clean`:** Clean the specified output directory services before generating to remove stale files _(optional)_.
9797
- **`--filter-services <glob-patterns...>`:** Filter services to be generated by glob pattern _(optional)_.
9898
- **Pattern syntax:**
9999
- `<glob-pattern>,<glob-pattern>,...` - comma-separated list of glob patterns. See [`micromatch`](https://github.com/micromatch/micromatch)

packages/cli/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"@openapi-qraft/openapi-typescript-plugin": "workspace:*",
1919
"@openapi-qraft/plugin": "workspace:*",
2020
"@openapi-qraft/tanstack-query-react-plugin": "workspace:*",
21-
"commander": "^11.1.0"
21+
"ansi-colors": "^4.1.3",
22+
"commander": "^14.0.2"
2223
},
2324
"devDependencies": {
2425
"@openapi-qraft/eslint-config": "workspace:*",

packages/cli/src/bin.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@ import { QraftCommand } from '@openapi-qraft/plugin';
44
import { RedoclyConfigCommand } from '@openapi-qraft/plugin/lib/RedoclyConfigCommand';
55
import { Option, ParseOptions } from 'commander';
66
import { builtInPlugins } from './builtInPlugins.js';
7+
import { handleDeprecatedOptions } from './handleDeprecatedOptions.js';
78

89
export async function main(
910
processArgv: string[],
1011
processArgvParseOptions?: ParseOptions
1112
) {
13+
const argv = handleDeprecatedOptions(processArgv);
14+
1215
const redoclyConfigParseResult = await new RedoclyConfigCommand().parseConfig(
1316
qraft,
14-
processArgv,
17+
argv,
1518
processArgvParseOptions
1619
);
1720

1821
if (redoclyConfigParseResult?.length) return;
1922

20-
await qraft(processArgv, processArgvParseOptions);
23+
await qraft(argv, processArgvParseOptions);
2124
}
2225

2326
async function qraft(
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2+
import { handleDeprecatedOptions } from './handleDeprecatedOptions.js';
3+
4+
describe('handleDeprecatedOptions', () => {
5+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
6+
7+
beforeEach(() => {
8+
warnSpy.mockClear();
9+
});
10+
11+
afterEach(() => {
12+
warnSpy.mockClear();
13+
});
14+
15+
it('should replace -rm with -c', () => {
16+
const result = handleDeprecatedOptions(['-rm']);
17+
expect(result).toEqual(['-c']);
18+
});
19+
20+
it('should show deprecation warning for -rm', () => {
21+
handleDeprecatedOptions(['-rm']);
22+
expect(warnSpy).toHaveBeenCalledTimes(1);
23+
expect(warnSpy.mock.calls[0][0]).toContain('-rm');
24+
expect(warnSpy.mock.calls[0][0]).toContain('-c');
25+
expect(warnSpy.mock.calls[0][0]).toContain('v3.0');
26+
});
27+
28+
it('should not modify other arguments', () => {
29+
const result = handleDeprecatedOptions(['--output-dir', 'src/api', '-o']);
30+
expect(result).toEqual(['--output-dir', 'src/api', '-o']);
31+
expect(warnSpy).not.toHaveBeenCalled();
32+
});
33+
34+
it('should handle mixed arguments with deprecated option', () => {
35+
const result = handleDeprecatedOptions([
36+
'--plugin',
37+
'tanstack-query-react',
38+
'-rm',
39+
'-o',
40+
'src/api',
41+
]);
42+
expect(result).toEqual([
43+
'--plugin',
44+
'tanstack-query-react',
45+
'-c',
46+
'-o',
47+
'src/api',
48+
]);
49+
expect(warnSpy).toHaveBeenCalledTimes(1);
50+
});
51+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import c from 'ansi-colors';
2+
3+
const deprecatedOptionsMap: Record<string, { replacement: string }> = {
4+
'-rm': { replacement: '-c' },
5+
};
6+
7+
export function handleDeprecatedOptions(argv: string[]): string[] {
8+
return argv.map((arg) => {
9+
const deprecated = deprecatedOptionsMap[arg];
10+
if (deprecated) {
11+
console.warn(
12+
c.yellow(
13+
`⚠ Option '${arg}' is deprecated and will be removed in v3.0. Please use '${deprecated.replacement}' instead.`
14+
)
15+
);
16+
return deprecated.replacement;
17+
}
18+
return arg;
19+
});
20+
}

packages/openapi-typescript-plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"@openapi-qraft/plugin": "workspace:^",
3838
"@redocly/openapi-core": "^1.34.5",
3939
"ansi-colors": "^4.1.3",
40-
"commander": "^11.1.0",
40+
"commander": "^14.0.2",
4141
"openapi-typescript": "^7.10.1",
4242
"typescript": "^5.6.2"
4343
},

packages/plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"@redocly/openapi-core": "^1.34.5",
3737
"ansi-colors": "^4.1.3",
3838
"camelcase": "^8.0.0",
39-
"commander": "^11.1.0",
39+
"commander": "^14.0.2",
4040
"micromatch": "^4.0.8",
4141
"openapi-typescript": "^7.10.1",
4242
"ora": "^8.2.0"

packages/plugin/src/lib/QraftCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class QraftCommand extends Command {
5454
)
5555
.addOption(
5656
new Option(
57-
'-rm, --clean',
57+
'-c, --clean',
5858
'Clean output directory before generating services'
5959
)
6060
)

packages/react-client/codegen.sh

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)