UNPKG

prompt-helper

Version:

A CLI tool to help you create and manage prompts for AI models.

75 lines 3.52 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.getPackageVersion = getPackageVersion; // src/libs/getPackageVersion.ts const fs = __importStar(require("fs")); const path = __importStar(require("path")); /** * Reads the version from the project's package.json file. * This function assumes that the compiled JavaScript file (e.g., getPackageVersion.js) * will be located in a subdirectory relative to the project root (like `dist/libs/`), * such that `../../package.json` from `__dirname` correctly points to the * project root's `package.json`. * * @returns {string} The project version string (e.g., "1.2.3") as defined in * `package.json`, or the string "unknown" if the version cannot be * determined or an error occurs during file access or parsing. */ function getPackageVersion() { try { // Path resolution explanation: // If this file (getPackageVersion.ts) is in `src/libs/`, and compiled to `dist/libs/getPackageVersion.js`: // `__dirname` (inside the compiled `dist/libs/getPackageVersion.js`) will be `project_root/dist/libs`. // `path.resolve(__dirname, '../../package.json')` then correctly resolves to `project_root/package.json`. const packageJsonPath = path.resolve(__dirname, '../../package.json'); if (fs.existsSync(packageJsonPath)) { const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8'); const packageJson = JSON.parse(packageJsonContent); return packageJson.version || 'unknown'; } else { // This case might occur if the path resolution is incorrect or package.json is genuinely missing. console.warn(`Warning: package.json not found at expected path: ${packageJsonPath}`); } } catch (error) { // Log as a warning because the CLI might still be functional for other tasks // even if its own version cannot be determined for the --version flag. console.warn('Warning: Error reading package.json for version:', error); } return 'unknown'; // Fallback version } //# sourceMappingURL=getPackageVersion.js.map