Skip to content

Commit

Permalink
fix(cli-core): bump commander dependency to 12.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Sep 28, 2024
1 parent 77a22c3 commit b03f228
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 171 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@tsed/normalize-path": ">=7.14.2",
"axios": "^1.7.7",
"chalk": "^5.3.0",
"commander": "^9.3.0",
"commander": "^12.1.0",
"consolidate": "^1.0.4",
"execa": "8.0.1",
"figures": "^6.1.0",
Expand Down Expand Up @@ -94,7 +94,7 @@
"husky": "9.1.6",
"is-ci": "3.0.1",
"lint-staged": "15.2.10",
"markdown-it": "13.0.2",
"markdown-it": "14.1.0",
"prettier": "3.3.3",
"semantic-release": "24.1.1",
"semantic-release-slack-bot": "4.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"axios": "^1.7.7",
"chalk": "^5.3.0",
"change-case": "^5.4.4",
"commander": "^9.3.0",
"commander": "^12.1.0",
"consolidate": "^1.0.4",
"create-frame": "^1.0.0",
"enquirer": "^2.4.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/cli-core/src/services/CliService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type {CommandProvider} from "../interfaces/CommandProvider.js";
import {PackageManagersModule} from "../packageManagers/index.js";
import {createSubTasks, createTasksRunner} from "../utils/createTasksRunner.js";
import {getCommandMetadata} from "../utils/getCommandMetadata.js";
import {mapCommanderOptions} from "../utils/index.js";
import {mapCommanderArgs} from "../utils/mapCommanderArgs.js";
import {mapCommanderOptions} from "../utils/mapCommanderOptions.js";
import {parseOption} from "../utils/parseOption.js";
import {CliHooks} from "./CliHooks.js";
import {ProjectPackageJson} from "./ProjectPackageJson.js";
Expand Down Expand Up @@ -196,10 +196,10 @@ export class CliService {

let cmd = this.program.command(name);

const onAction = (...commanderArgs: any[]) => {
const onAction = (commandName: string) => {
const [, ...rawArgs] = cmd.args;
const mappedArgs = mapCommanderArgs(args, commanderArgs);
const allOpts = mapCommanderOptions(this.program.commands);
const mappedArgs = mapCommanderArgs(args, this.program.args);
const allOpts = mapCommanderOptions(commandName, this.program.commands);

const data = {
...allOpts,
Expand Down
7 changes: 6 additions & 1 deletion packages/cli-core/src/utils/mapCommanderOptions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import type {Command} from "commander";

export function mapCommanderOptions(commands: Command[]) {
export function mapCommanderOptions(commandName: string, commands: readonly Command[]) {
const options: any = {};

commands.forEach((command) => {
if (command.name() !== commandName) {
return;
}

Object.entries(command.opts())
.filter(([key]) => !key.startsWith("_") && !["commands", "options", "parent", "rawArgs", "args"].includes(key))
.forEach(([key, value]) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-generate-http-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@tsed/cli-core": "workspace:*",
"@tsed/typescript": "workspace:*",
"cross-env": "7.0.3",
"swagger-typescript-api": "^9.3.1",
"swagger-typescript-api": "^13.0.22",
"typescript": "5.6.2",
"vitest": "2.1.1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ export class GenerateHttpClientCmd implements CommandProvider {
}
} as any);

const promises = files.map(({content, name}) => {
content = content
const promises = files.map((file) => {
const name = file.fileName;
file.fileContent = file.fileContent
.replace("class Api", `class ${$ctx.name}`)
.replace(".then((response) => response.data)", ".then((response) => response.data as T)")
.replace('requestParams.headers.common = { Accept: "*/*" };', "")
Expand All @@ -153,7 +154,7 @@ export class GenerateHttpClientCmd implements CommandProvider {
.replace("(this.instance.defaults.headers || {})", "((this.instance.defaults.headers || {}) as any)");

console.log(`${$ctx.output}/${name}`, path.resolve(`${$ctx.output}/${name}`));
return this.fs.writeFile(`${$ctx.output}/${name}`, content, {encoding: "utf8"});
return this.fs.writeFile(`${$ctx.output}/${name}`, file.fileContent, {encoding: "utf8"});
});

return Promise.all(promises);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/generate/GenerateCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const searchFactory = (list: any) => {
}
},
options: {
"-r, --route <route>": {
"--route <route>": {
type: String,
description: "The route for the controller generated file"
},
Expand Down
Loading

0 comments on commit b03f228

Please sign in to comment.