diff --git a/.changeset/wet-ads-live.md b/.changeset/wet-ads-live.md new file mode 100644 index 0000000..f5ce111 --- /dev/null +++ b/.changeset/wet-ads-live.md @@ -0,0 +1,5 @@ +--- +"create-better-t-stack": patch +--- + +auto get current package version diff --git a/apps/cli/src/consts.ts b/apps/cli/src/consts.ts index 029d03d..5c1f352 100644 --- a/apps/cli/src/consts.ts +++ b/apps/cli/src/consts.ts @@ -1,3 +1,6 @@ +import path from "node:path"; +import { fileURLToPath } from "node:url"; + export const TITLE_TEXT = ` ╔════════════════════════════════════════════════════════════╗ ║ ║ @@ -19,3 +22,7 @@ export const TITLE_TEXT = ` ║ ║ ╚════════════════════════════════════════════════════════════╝ `; + +const __filename = fileURLToPath(import.meta.url); +const distPath = path.dirname(__filename); +export const PKG_ROOT = path.join(distPath, "../"); diff --git a/apps/cli/src/index.ts b/apps/cli/src/index.ts index badca5f..750da7f 100644 --- a/apps/cli/src/index.ts +++ b/apps/cli/src/index.ts @@ -4,6 +4,7 @@ import { Command } from "commander"; import { createProject } from "./create-project"; import { renderTitle } from "./render-title"; import type { ProjectDatabase, ProjectFeature } from "./types"; +import { getVersion } from "./utils/get-version"; import { logger } from "./utils/logger"; const program = new Command(); @@ -116,7 +117,7 @@ process.on("SIGINT", () => { program .name("create-better-t-stack") .description("Create a new Better-T Stack project") - .version("1.0.0") + .version(getVersion()) .option("-y, --yes", "Accept all defaults") .action((options) => main(options)); diff --git a/apps/cli/src/utils/get-version.ts b/apps/cli/src/utils/get-version.ts new file mode 100644 index 0000000..2190751 --- /dev/null +++ b/apps/cli/src/utils/get-version.ts @@ -0,0 +1,11 @@ +import path from "node:path"; +import fs from "fs-extra"; +import { PKG_ROOT } from "../consts"; + +export const getVersion = () => { + const packageJsonPath = path.join(PKG_ROOT, "package.json"); + + const packageJsonContent = fs.readJSONSync(packageJsonPath); + + return packageJsonContent.version ?? "1.0.0"; +}; diff --git a/bun.lock b/bun.lock index eb19248..c4e9da9 100644 --- a/bun.lock +++ b/bun.lock @@ -14,7 +14,7 @@ }, "apps/cli": { "name": "create-better-t-stack", - "version": "1.0.0", + "version": "0.1.1", "bin": { "create-better-t-stack": "./dist/index.js" },