From 4184288de9b364d08e275539480e566ea562fff3 Mon Sep 17 00:00:00 2001 From: toothlessdev Date: Thu, 15 Jan 2026 18:27:26 +0900 Subject: [PATCH 1/6] =?UTF-8?q?chore:=20resolveJsonModule=20=EC=98=B5?= =?UTF-8?q?=EC=85=98=EC=9C=BC=EB=A1=9C=20cli=20=EB=B2=84=EC=A0=84=EC=9D=84?= =?UTF-8?q?=20=ED=8C=A8=ED=82=A4=EC=A7=80=EB=B2=84=EC=A0=84=EA=B3=BC=20?= =?UTF-8?q?=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/patchlogr-cli/tsconfig.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/patchlogr-cli/tsconfig.json b/packages/patchlogr-cli/tsconfig.json index 8e56657..3eaafcb 100644 --- a/packages/patchlogr-cli/tsconfig.json +++ b/packages/patchlogr-cli/tsconfig.json @@ -7,7 +7,9 @@ "declaration": true, "declarationMap": true, - "emitDeclarationOnly": false + "emitDeclarationOnly": false, + + "resolveJsonModule": true }, "include": ["src"] } From ad8bc253006a927c540833944e41b7be71496ac5 Mon Sep 17 00:00:00 2001 From: toothlessdev Date: Thu, 15 Jan 2026 18:27:48 +0900 Subject: [PATCH 2/6] =?UTF-8?q?refactor:=20=EA=B0=81=20command=20=EB=A5=BC?= =?UTF-8?q?=20src/commands/*.ts=20=EC=9C=BC=EB=A1=9C=20=ED=99=95=EC=9E=A5?= =?UTF-8?q?=EA=B0=80=EB=8A=A5=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/patchlogr-cli/src/cli.ts | 41 ---------------- .../src/commands/canonicalize.ts | 48 +++++++++++++++++++ packages/patchlogr-cli/src/commands/help.ts | 8 ++++ .../src/commands/runCanonicalize.ts | 29 ----------- packages/patchlogr-cli/src/createCLI.ts | 14 ++++++ packages/patchlogr-cli/src/index.ts | 2 +- 6 files changed, 71 insertions(+), 71 deletions(-) delete mode 100644 packages/patchlogr-cli/src/cli.ts create mode 100644 packages/patchlogr-cli/src/commands/canonicalize.ts create mode 100644 packages/patchlogr-cli/src/commands/help.ts delete mode 100644 packages/patchlogr-cli/src/commands/runCanonicalize.ts create mode 100644 packages/patchlogr-cli/src/createCLI.ts diff --git a/packages/patchlogr-cli/src/cli.ts b/packages/patchlogr-cli/src/cli.ts deleted file mode 100644 index 8bc66cf..0000000 --- a/packages/patchlogr-cli/src/cli.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { Command } from "commander"; -import { runCanonicalize } from "./commands/runCanonicalize"; - -export function createCLI() { - const program = new Command(); - - program - .name("patchlogr") - .version("0.0.0") - .description("PatchlogrCLI : changelogs from openapi specs"); - - program - .command("help") - .description("Display help information about patchlogr commands") - .action(() => { - program.outputHelp(); - }); - - program - .command("canonicalize") - .argument("", "Path to the OpenAPI specification file") - .option( - "--skipValidation", - "Skip validation of the OpenAPI specification", - ) - .option( - "-o, --output ", - "Write result to file instead of stdout (default: stdout)", - "stdout", - ) - .action(async (apiDocs, options) => { - try { - await runCanonicalize(apiDocs, options); - } catch (error) { - console.error(error); - process.exitCode = 1; - } - }); - - return program; -} diff --git a/packages/patchlogr-cli/src/commands/canonicalize.ts b/packages/patchlogr-cli/src/commands/canonicalize.ts new file mode 100644 index 0000000..e572686 --- /dev/null +++ b/packages/patchlogr-cli/src/commands/canonicalize.ts @@ -0,0 +1,48 @@ +import { program } from "commander"; + +import { preprocessOASDocument } from "@patchlogr/oas"; +import { type OASStageOptions } from "@patchlogr/oas"; +import type { OpenAPI } from "openapi-types"; +import fs from "fs/promises"; + +export type CanonicalizeOptions = OASStageOptions & { + output?: "stdout" | string; +}; + +export const canonicalizeCommand = program + .command("canonicalize") + .argument("", "Path to the OpenAPI specification file") + .option("--skipValidation", "Skip validation of the OpenAPI specification") + .option( + "-o, --output ", + "Write result to file instead of stdout (default: stdout)", + "stdout", + ) + .action(canonicalizeAction); + +export async function canonicalizeAction( + apiDocs: OpenAPI.Document, + options: CanonicalizeOptions, +) { + try { + const rawOutput = await preprocessOASDocument(apiDocs, { + skipValidation: !!options.skipValidation, + }); + const output = JSON.stringify(rawOutput, null, 2); + + if (options.output === "stdout" || options.output === undefined) { + console.log(output); + } else { + try { + await fs.writeFile(options.output, output, "utf-8"); + } catch (error) { + throw new Error(`Failed to write to file ${options.output}:`, { + cause: error, + }); + } + } + } catch (error) { + console.error(error); + process.exitCode = 1; + } +} diff --git a/packages/patchlogr-cli/src/commands/help.ts b/packages/patchlogr-cli/src/commands/help.ts new file mode 100644 index 0000000..0d0d3bc --- /dev/null +++ b/packages/patchlogr-cli/src/commands/help.ts @@ -0,0 +1,8 @@ +import { Command, CommandOptions, program } from "commander"; + +export const helpCommand = program + .command("help") + .description("Display help information about patchlogr commands") + .action(() => { + program.outputHelp(); + }); diff --git a/packages/patchlogr-cli/src/commands/runCanonicalize.ts b/packages/patchlogr-cli/src/commands/runCanonicalize.ts deleted file mode 100644 index 03a7461..0000000 --- a/packages/patchlogr-cli/src/commands/runCanonicalize.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { preprocessOASDocument } from "@patchlogr/oas"; -import { type OASStageOptions } from "@patchlogr/oas"; -import type { OpenAPI } from "openapi-types"; -import fs from "fs/promises"; - -export type RunCanonicalizeOptions = OASStageOptions & { - output?: "stdout" | string; -}; - -export async function runCanonicalize( - apiDocs: OpenAPI.Document, - options: RunCanonicalizeOptions, -) { - const output = await preprocessOASDocument(apiDocs, { - skipValidation: !!options.skipValidation, - }); - - if (options.output === "stdout" || options.output === undefined) { - console.log(JSON.stringify(output, null, 2)); - } else { - try { - await fs.writeFile(options.output, JSON.stringify(output, null, 2)); - } catch (error) { - throw new Error(`Failed to write to file ${options.output}:`, { - cause: error, - }); - } - } -} diff --git a/packages/patchlogr-cli/src/createCLI.ts b/packages/patchlogr-cli/src/createCLI.ts new file mode 100644 index 0000000..a1498f2 --- /dev/null +++ b/packages/patchlogr-cli/src/createCLI.ts @@ -0,0 +1,14 @@ +import { Command } from "commander"; +import pkg from "../package.json"; + +import { helpCommand } from "./commands/help"; +import { canonicalizeCommand } from "./commands/canonicalize"; + +export function createCLI() { + return new Command() + .name("patchlogr") + .version(pkg.version) + .description("PatchlogrCLI : changelogs from openapi specs") + .addCommand(helpCommand) + .addCommand(canonicalizeCommand); +} diff --git a/packages/patchlogr-cli/src/index.ts b/packages/patchlogr-cli/src/index.ts index 914ae17..67fe5fa 100644 --- a/packages/patchlogr-cli/src/index.ts +++ b/packages/patchlogr-cli/src/index.ts @@ -1,4 +1,4 @@ -import { createCLI } from "./cli"; +import { createCLI } from "./createCLI"; const program = createCLI(); From 408651d1baec69ce9e5be8a27258b0059780d9b6 Mon Sep 17 00:00:00 2001 From: toothlessdev Date: Thu, 15 Jan 2026 18:30:47 +0900 Subject: [PATCH 3/6] =?UTF-8?q?chore:=20unused=20imports=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/patchlogr-cli/src/commands/help.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/patchlogr-cli/src/commands/help.ts b/packages/patchlogr-cli/src/commands/help.ts index 0d0d3bc..bd42cbc 100644 --- a/packages/patchlogr-cli/src/commands/help.ts +++ b/packages/patchlogr-cli/src/commands/help.ts @@ -1,4 +1,4 @@ -import { Command, CommandOptions, program } from "commander"; +import { program } from "commander"; export const helpCommand = program .command("help") From affcbf4cfcd2306992441605722fa6fa885fcd72 Mon Sep 17 00:00:00 2001 From: toothlessdev Date: Thu, 15 Jan 2026 18:33:39 +0900 Subject: [PATCH 4/6] =?UTF-8?q?refactor:=20Command=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9E=90=EB=A1=9C=20=EC=9D=B8=EC=8A=A4=ED=84=B4=EC=8A=A4=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/patchlogr-cli/src/commands/canonicalize.ts | 5 ++--- packages/patchlogr-cli/src/commands/help.ts | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/patchlogr-cli/src/commands/canonicalize.ts b/packages/patchlogr-cli/src/commands/canonicalize.ts index e572686..5392b52 100644 --- a/packages/patchlogr-cli/src/commands/canonicalize.ts +++ b/packages/patchlogr-cli/src/commands/canonicalize.ts @@ -1,4 +1,4 @@ -import { program } from "commander"; +import { Command } from "commander"; import { preprocessOASDocument } from "@patchlogr/oas"; import { type OASStageOptions } from "@patchlogr/oas"; @@ -9,8 +9,7 @@ export type CanonicalizeOptions = OASStageOptions & { output?: "stdout" | string; }; -export const canonicalizeCommand = program - .command("canonicalize") +export const canonicalizeCommand = new Command("canonicalize") .argument("", "Path to the OpenAPI specification file") .option("--skipValidation", "Skip validation of the OpenAPI specification") .option( diff --git a/packages/patchlogr-cli/src/commands/help.ts b/packages/patchlogr-cli/src/commands/help.ts index bd42cbc..cb3f3d6 100644 --- a/packages/patchlogr-cli/src/commands/help.ts +++ b/packages/patchlogr-cli/src/commands/help.ts @@ -1,7 +1,6 @@ -import { program } from "commander"; +import { Command, program } from "commander"; -export const helpCommand = program - .command("help") +export const helpCommand = new Command("help") .description("Display help information about patchlogr commands") .action(() => { program.outputHelp(); From 858a4083a9ba03bf756fb6ce2473c598c7f2da98 Mon Sep 17 00:00:00 2001 From: toothlessdev Date: Thu, 15 Jan 2026 18:34:32 +0900 Subject: [PATCH 5/6] =?UTF-8?q?refactor:=20helpCommand=20=EC=95=A1?= =?UTF-8?q?=EC=85=98=EC=97=90=EC=84=9C=20program=20=EB=8C=80=EC=8B=A0=20co?= =?UTF-8?q?mmand.parent=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/patchlogr-cli/src/commands/help.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/patchlogr-cli/src/commands/help.ts b/packages/patchlogr-cli/src/commands/help.ts index cb3f3d6..543b4b0 100644 --- a/packages/patchlogr-cli/src/commands/help.ts +++ b/packages/patchlogr-cli/src/commands/help.ts @@ -2,6 +2,6 @@ import { Command, program } from "commander"; export const helpCommand = new Command("help") .description("Display help information about patchlogr commands") - .action(() => { - program.outputHelp(); + .action((_options, command) => { + command.parent?.outputHelp(); }); From 4cbc7f9513c8e64f1498f2b5056c317c6dea50e3 Mon Sep 17 00:00:00 2001 From: toothlessdev Date: Thu, 15 Jan 2026 18:36:05 +0900 Subject: [PATCH 6/6] =?UTF-8?q?chore:=20unused=20imports=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/patchlogr-cli/src/commands/help.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/patchlogr-cli/src/commands/help.ts b/packages/patchlogr-cli/src/commands/help.ts index 543b4b0..445afc9 100644 --- a/packages/patchlogr-cli/src/commands/help.ts +++ b/packages/patchlogr-cli/src/commands/help.ts @@ -1,4 +1,4 @@ -import { Command, program } from "commander"; +import { Command } from "commander"; export const helpCommand = new Command("help") .description("Display help information about patchlogr commands")