auto get current package version

This commit is contained in:
Aman Varshney
2025-02-12 17:13:02 +05:30
parent 8a716bf9db
commit 5554818335
5 changed files with 26 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"create-better-t-stack": patch
---
auto get current package version

View File

@@ -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, "../");

View File

@@ -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));

View File

@@ -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";
};

View File

@@ -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"
},