UNPKG

@o3r/schematics

Version:

Schematics module of the Otter framework

31 lines 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.findClosestPackageJson = void 0; exports.getPackageVersion = getPackageVersion; const fs = require("node:fs"); const node_fs_1 = require("node:fs"); const node_path_1 = require("node:path"); /** * Return the version of the given package json path * @param packageJsonPath */ function getPackageVersion(packageJsonPath) { const packageJsonContent = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf8' })); return packageJsonContent.version; } /** * Find the closest package.json file in parent folders * Note: It is using file system if no tree provided * @param currentPath current path to inspect * @param tree current path to inspect */ const findClosestPackageJson = (currentPath, tree) => { const dir = (tree ? node_path_1.posix.dirname.bind(node_path_1.posix) : node_path_1.dirname)(currentPath); if (dir === currentPath || currentPath === '/') { return undefined; } const packageJsonPath = (tree ? node_path_1.posix.join.bind(node_path_1.posix) : node_path_1.join)(dir, 'package.json'); return (tree ? tree.exists.bind(tree) : node_fs_1.existsSync)(packageJsonPath) ? packageJsonPath : (0, exports.findClosestPackageJson)(dir, tree); }; exports.findClosestPackageJson = findClosestPackageJson; //# sourceMappingURL=package-version.js.map