Skip to content

Commit

Permalink
Merge pull request #1046 from AugusDogus/main
Browse files Browse the repository at this point in the history
Respect debug and silent logging configuration for both cli and lib modes
  • Loading branch information
smorimoto authored Feb 12, 2025
2 parents 16cdf0e + 40dd9d8 commit 46d461f
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-trains-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"swagger-typescript-api": patch
---

Respect debug and silent logging configuration for both cli and lib modes.
15 changes: 8 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { TemplatesGenConfig } from "./src/commands/generate-templates/configurat
import { CodeGenConfig } from "./src/configuration.js";
import { HTTP_CLIENT } from "./src/constants.js";
import { generateApi, generateTemplates } from "./src/index.js";
import type { HttpClientType } from "./types/index.js";

const templateGenBaseConfig = new TemplatesGenConfig({});

Expand Down Expand Up @@ -52,18 +53,21 @@ const generateTemplatesCommand = defineCommand({
description: "Output only errors to console",
default: templateGenBaseConfig.silent,
},
debug: {
type: "boolean",
description: "additional information about processes inside this tool",
default: templateGenBaseConfig.debug,
},
},
run: async ({ args }) => {
if (args.debug) consola.level = Number.MAX_SAFE_INTEGER;
if (args.silent) consola.level = 0;

await generateTemplates({
cleanOutput: args["clean-output"],
httpClientType: args["http-client"],
httpClientType: args["http-client"] as HttpClientType,
modular: args.modular,
output: args.output,
rewrite: args.rewrite,
silent: args.silent,
debug: args.debug,
});
},
});
Expand Down Expand Up @@ -274,9 +278,6 @@ const generateCommand = defineCommand({
},
},
run: async ({ args }) => {
if (args.debug) consola.level = Number.MAX_SAFE_INTEGER;
if (args.silent) consola.level = 0;

let customConfig;

if (args["custom-config"]) {
Expand Down
10 changes: 7 additions & 3 deletions src/commands/generate-templates/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import type { GenerateTemplatesParams } from "../../../types/index.js";
import type {
GenerateTemplatesParams,
HttpClientType,
} from "../../../types/index.js";
import { HTTP_CLIENT, PROJECT_VERSION } from "../../constants.js";
import { objectAssign } from "../../util/object-assign.js";

export class TemplatesGenConfig {
cleanOutput = false;
output = undefined;
httpClientType = HTTP_CLIENT.FETCH;
httpClientType: HttpClientType = HTTP_CLIENT.FETCH;
modular = false;
rewrite = false;
silent = false;
debug = false;
version = PROJECT_VERSION;
rewrite = false;

constructor(config: GenerateTemplatesParams) {
this.update(config);
Expand Down
3 changes: 3 additions & 0 deletions src/commands/generate-templates/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { consola } from "consola";
import type { GenerateTemplatesParams } from "../../../types/index.js";
import { TemplatesGenProcess } from "./templates-gen-process.js";

export async function generateTemplates(config: GenerateTemplatesParams) {
if (config.debug) consola.level = Number.MAX_SAFE_INTEGER;
if (config.silent) consola.level = 0;
const codeGenProcess = new TemplatesGenProcess(config);
return await codeGenProcess.start();
}
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { consola } from "consola";
import type { GenerateApiConfiguration } from "../types/index.js";
import { CodeGenProcess } from "./code-gen-process.js";

export async function generateApi(
config: Partial<GenerateApiConfiguration["config"]>,
) {
if (config.debug) consola.level = Number.MAX_SAFE_INTEGER;
if (config.silent) consola.level = 0;
const codeGenProcess = new CodeGenProcess(config);
return await codeGenProcess.start();
}
Expand Down
2 changes: 2 additions & 0 deletions src/templates-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export class TemplatesWorker {
this.config = config;
this.fileSystem = fileSystem;
this.getRenderTemplateData = getRenderTemplateData;
if (this.config.debug) consola.level = Number.MAX_SAFE_INTEGER;
if (this.config.silent) consola.level = 0;
}

getTemplatePaths = (
Expand Down
5 changes: 4 additions & 1 deletion types/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { ComponentTypeNameResolver } from "../src/component-type-name-resolver.js";
import type { HTTP_CLIENT } from "../src/constants.js";
import type { MonoSchemaParser } from "../src/schema-parser/mono-schema-parser.js";
import type { Translator } from "../src/translators/translator.js";

type HttpClientType = "axios" | "fetch";
export type HttpClientType = (typeof HTTP_CLIENT)[keyof typeof HTTP_CLIENT];

interface GenerateApiParamsBase {
/**
Expand Down Expand Up @@ -773,7 +774,9 @@ export interface GenerateTemplatesParams {
output?: string;
httpClientType?: HttpClientType;
modular?: boolean;
rewrite?: boolean;
silent?: boolean;
debug?: boolean;
}

export interface GenerateTemplatesOutput
Expand Down

0 comments on commit 46d461f

Please sign in to comment.