UNPKG

projex

Version:
39 lines (38 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAppRoot = exports.PACKAGE_FILE_NAME = exports.MANIFEST_FILE_NAME = void 0; const fs_1 = require("fs"); const path = require('path'); exports.MANIFEST_FILE_NAME = 'manifest.json'; exports.PACKAGE_FILE_NAME = 'package.json'; const fileExists = (filePath) => { try { (0, fs_1.accessSync)(filePath); return true; } catch (err) { return false; } }; const getAppRoot = () => { if (process.env.OCLIF_COMPILATION) { return ''; } const cwd = process.cwd(); const { root: rootDirName } = path.parse(cwd); const find = (dir) => { const manifestPath = path.join(dir, exports.MANIFEST_FILE_NAME); const packagePath = path.join(dir, exports.PACKAGE_FILE_NAME); if (fileExists(manifestPath) || fileExists(packagePath)) { return dir; } else { if (dir === rootDirName) { throw new Error("Manifest or package file doesn't exist or is not readable. Please make sure you're in the app's directory or add the required files in the root folder of the app."); } return find(path.resolve(dir, '..')); } }; return find(cwd); }; exports.getAppRoot = getAppRoot;