From 05ca9f8ce4a923439419f34ca0cb49d8cc116448 Mon Sep 17 00:00:00 2001 From: immanuwell Date: Sat, 9 May 2026 12:18:41 +0400 Subject: [PATCH] fix: read CLI version from package metadata --- src/index.ts | 7 ++++++- tests/cli.test.ts | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3e6b1c5..add938b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,18 @@ #!/usr/bin/env node +import { readFileSync } from "node:fs"; import chalk from "chalk"; import { program } from "commander"; import { registerAuthCommand } from "./commands/auth.js"; import { registerGeneratedCommands } from "./generated/commands.js"; +const packageJson = JSON.parse( + readFileSync(new URL("../package.json", import.meta.url), "utf8"), +) as { version: string }; + const pkg = { name: "dokploy", - version: "0.3.0", + version: packageJson.version, description: "Dokploy CLI - Manage your Dokploy server", }; diff --git a/tests/cli.test.ts b/tests/cli.test.ts index bd4b650..8e215a0 100644 --- a/tests/cli.test.ts +++ b/tests/cli.test.ts @@ -1,4 +1,5 @@ import { execFileSync } from "node:child_process"; +import * as fs from "node:fs"; import * as path from "node:path"; import { fileURLToPath } from "node:url"; import { describe, expect, it } from "vitest"; @@ -6,6 +7,9 @@ import { describe, expect, it } from "vitest"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const ROOT = path.resolve(__dirname, ".."); const CLI = path.join(ROOT, "dist", "index.js"); +const packageJson = JSON.parse( + fs.readFileSync(path.join(ROOT, "package.json"), "utf8"), +) as { version: string }; function run(...args: string[]): string { return execFileSync("node", [CLI, ...args], { @@ -25,7 +29,7 @@ describe("CLI", () => { it("should show version with --version", () => { const output = run("--version"); - expect(output.trim()).toMatch(/^\d+\.\d+\.\d+$/); + expect(output.trim()).toBe(packageJson.version); }); it("should show subcommands for application", () => {