UNPKG

cumulocity-cypress

Version:
23 lines (22 loc) 723 B
import * as path from "path"; import * as fs from "fs"; export function getPackageVersion() { try { let currentDir = __dirname; let packageJsonPath; let maxLevels = 3; while (maxLevels > 0) { packageJsonPath = path.resolve(currentDir, "package.json"); if (fs.existsSync(packageJsonPath)) { const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8")); return packageJson.version; } currentDir = path.dirname(currentDir); maxLevels--; } } catch { console.error("Failed to get version from package.json. package.json not found."); } return "unknown"; }