UNPKG

@magidoc/cli

Version:

Magidoc CLI application responsible for generating GraphQL documentation websites.

33 lines (30 loc) 1.1 kB
import { readFileSync, existsSync } from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; let version; function getVersion() { if (!version) { const packageJsonPath = findPackageJsonPath(); if (!packageJsonPath) { throw new Error('Could not resolve path to package.json'); } const packageJson = JSON.parse(readFileSync(packageJsonPath).toString()); version = packageJson.version; if (!version) { throw new Error('Expected version to be defined in package.json. Could not extract version number, but it is required to fetch the right template versions.'); } } return version; } function findPackageJsonPath(test = path.join(path.dirname(fileURLToPath(import.meta.url)), './package.json')) { if (existsSync(test)) { return test; } const newPath = path.join(path.dirname(path.dirname(test)), 'package.json'); if (newPath === test) { return undefined; } return findPackageJsonPath(newPath); } export { getVersion }; //# sourceMappingURL=version.js.map