mirror of
https://github.com/Dokploy/cli.git
synced 2026-06-15 20:25:22 +02:00
Merge pull request #42 from immanuwell/fix-cli-version-from-package
fix: read CLI version from package metadata
This commit is contained in:
@@ -1,13 +1,18 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
import { readFileSync } from "node:fs";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
import { program } from "commander";
|
import { program } from "commander";
|
||||||
import { registerAuthCommand } from "./commands/auth.js";
|
import { registerAuthCommand } from "./commands/auth.js";
|
||||||
import { registerGeneratedCommands } from "./generated/commands.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 = {
|
const pkg = {
|
||||||
name: "dokploy",
|
name: "dokploy",
|
||||||
version: "0.3.0",
|
version: packageJson.version,
|
||||||
description: "Dokploy CLI - Manage your Dokploy server",
|
description: "Dokploy CLI - Manage your Dokploy server",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { execFileSync } from "node:child_process";
|
import { execFileSync } from "node:child_process";
|
||||||
|
import * as fs from "node:fs";
|
||||||
import * as path from "node:path";
|
import * as path from "node:path";
|
||||||
import { fileURLToPath } from "node:url";
|
import { fileURLToPath } from "node:url";
|
||||||
import { describe, expect, it } from "vitest";
|
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 __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
const ROOT = path.resolve(__dirname, "..");
|
const ROOT = path.resolve(__dirname, "..");
|
||||||
const CLI = path.join(ROOT, "dist", "index.js");
|
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 {
|
function run(...args: string[]): string {
|
||||||
return execFileSync("node", [CLI, ...args], {
|
return execFileSync("node", [CLI, ...args], {
|
||||||
@@ -25,7 +29,7 @@ describe("CLI", () => {
|
|||||||
|
|
||||||
it("should show version with --version", () => {
|
it("should show version with --version", () => {
|
||||||
const output = run("--version");
|
const output = run("--version");
|
||||||
expect(output.trim()).toMatch(/^\d+\.\d+\.\d+$/);
|
expect(output.trim()).toBe(packageJson.version);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should show subcommands for application", () => {
|
it("should show subcommands for application", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user