Skip to content

Commit 40dd9d8

Browse files
AugusDogussmorimoto
authored andcommitted
Respect debug and silent logging configuration for both cli and lib modes
1 parent 16cdf0e commit 40dd9d8

File tree

7 files changed

+32
-11
lines changed

7 files changed

+32
-11
lines changed

.changeset/afraid-trains-care.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"swagger-typescript-api": patch
3+
---
4+
5+
Respect debug and silent logging configuration for both cli and lib modes.

index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { TemplatesGenConfig } from "./src/commands/generate-templates/configurat
77
import { CodeGenConfig } from "./src/configuration.js";
88
import { HTTP_CLIENT } from "./src/constants.js";
99
import { generateApi, generateTemplates } from "./src/index.js";
10+
import type { HttpClientType } from "./types/index.js";
1011

1112
const templateGenBaseConfig = new TemplatesGenConfig({});
1213

@@ -52,18 +53,21 @@ const generateTemplatesCommand = defineCommand({
5253
description: "Output only errors to console",
5354
default: templateGenBaseConfig.silent,
5455
},
56+
debug: {
57+
type: "boolean",
58+
description: "additional information about processes inside this tool",
59+
default: templateGenBaseConfig.debug,
60+
},
5561
},
5662
run: async ({ args }) => {
57-
if (args.debug) consola.level = Number.MAX_SAFE_INTEGER;
58-
if (args.silent) consola.level = 0;
59-
6063
await generateTemplates({
6164
cleanOutput: args["clean-output"],
62-
httpClientType: args["http-client"],
65+
httpClientType: args["http-client"] as HttpClientType,
6366
modular: args.modular,
6467
output: args.output,
6568
rewrite: args.rewrite,
6669
silent: args.silent,
70+
debug: args.debug,
6771
});
6872
},
6973
});
@@ -274,9 +278,6 @@ const generateCommand = defineCommand({
274278
},
275279
},
276280
run: async ({ args }) => {
277-
if (args.debug) consola.level = Number.MAX_SAFE_INTEGER;
278-
if (args.silent) consola.level = 0;
279-
280281
let customConfig;
281282

282283
if (args["custom-config"]) {

src/commands/generate-templates/configuration.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
import type { GenerateTemplatesParams } from "../../../types/index.js";
1+
import type {
2+
GenerateTemplatesParams,
3+
HttpClientType,
4+
} from "../../../types/index.js";
25
import { HTTP_CLIENT, PROJECT_VERSION } from "../../constants.js";
36
import { objectAssign } from "../../util/object-assign.js";
47

58
export class TemplatesGenConfig {
69
cleanOutput = false;
710
output = undefined;
8-
httpClientType = HTTP_CLIENT.FETCH;
11+
httpClientType: HttpClientType = HTTP_CLIENT.FETCH;
912
modular = false;
13+
rewrite = false;
1014
silent = false;
15+
debug = false;
1116
version = PROJECT_VERSION;
12-
rewrite = false;
1317

1418
constructor(config: GenerateTemplatesParams) {
1519
this.update(config);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import { consola } from "consola";
12
import type { GenerateTemplatesParams } from "../../../types/index.js";
23
import { TemplatesGenProcess } from "./templates-gen-process.js";
34

45
export async function generateTemplates(config: GenerateTemplatesParams) {
6+
if (config.debug) consola.level = Number.MAX_SAFE_INTEGER;
7+
if (config.silent) consola.level = 0;
58
const codeGenProcess = new TemplatesGenProcess(config);
69
return await codeGenProcess.start();
710
}

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import { consola } from "consola";
12
import type { GenerateApiConfiguration } from "../types/index.js";
23
import { CodeGenProcess } from "./code-gen-process.js";
34

45
export async function generateApi(
56
config: Partial<GenerateApiConfiguration["config"]>,
67
) {
8+
if (config.debug) consola.level = Number.MAX_SAFE_INTEGER;
9+
if (config.silent) consola.level = 0;
710
const codeGenProcess = new CodeGenProcess(config);
811
return await codeGenProcess.start();
912
}

src/templates-worker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export class TemplatesWorker {
2020
this.config = config;
2121
this.fileSystem = fileSystem;
2222
this.getRenderTemplateData = getRenderTemplateData;
23+
if (this.config.debug) consola.level = Number.MAX_SAFE_INTEGER;
24+
if (this.config.silent) consola.level = 0;
2325
}
2426

2527
getTemplatePaths = (

types/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type { ComponentTypeNameResolver } from "../src/component-type-name-resolver.js";
2+
import type { HTTP_CLIENT } from "../src/constants.js";
23
import type { MonoSchemaParser } from "../src/schema-parser/mono-schema-parser.js";
34
import type { Translator } from "../src/translators/translator.js";
45

5-
type HttpClientType = "axios" | "fetch";
6+
export type HttpClientType = (typeof HTTP_CLIENT)[keyof typeof HTTP_CLIENT];
67

78
interface GenerateApiParamsBase {
89
/**
@@ -773,7 +774,9 @@ export interface GenerateTemplatesParams {
773774
output?: string;
774775
httpClientType?: HttpClientType;
775776
modular?: boolean;
777+
rewrite?: boolean;
776778
silent?: boolean;
779+
debug?: boolean;
777780
}
778781

779782
export interface GenerateTemplatesOutput

0 commit comments

Comments
 (0)