thoughtmcp
Version:
AI that thinks more like humans do - MCP server with human-like cognitive architecture for enhanced reasoning, memory, and self-monitoring
58 lines • 1.95 kB
JavaScript
/**
* Version utility that provides centralized version management
* All version references should use this utility instead of hardcoded strings
*/
import { readFileSync } from "fs";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
// Get the directory of this file
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Cache for the version to avoid repeated file reads
let cachedVersion = null;
/**
* Get the current package version from package.json
* @returns The version string from package.json
*/
export function getVersion() {
if (cachedVersion) {
return cachedVersion;
}
try {
// Navigate up to the project root and read package.json
const packageJsonPath = join(__dirname, "../../package.json");
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
if (!packageJson.version || typeof packageJson.version !== "string") {
throw new Error("Invalid or missing version in package.json");
}
cachedVersion = packageJson.version;
return cachedVersion;
}
catch (error) {
console.error("Failed to read version from package.json:", error);
// Fallback version - should never be used in production
return "0.0.0";
}
}
/**
* Get version info with additional metadata
* @returns Object containing version and metadata
*/
export function getVersionInfo() {
const version = getVersion();
const parts = version.split(".");
return {
version,
major: parseInt(parts[0] || "0", 10),
minor: parseInt(parts[1] || "0", 10),
patch: parseInt(parts[2] || "0", 10),
isPrerelease: version.includes("-") || version.includes("+"),
};
}
/**
* Clear the version cache (useful for testing)
*/
export function clearVersionCache() {
cachedVersion = null;
}
//# sourceMappingURL=version.js.map