cumulocity-cypress
Version:
Cypress commands for Cumulocity IoT
23 lines (22 loc) • 723 B
JavaScript
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";
}