UNPKG

a2r

Version:
37 lines (36 loc) 1.18 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = __importDefault(require("path")); const fs_1 = require("@a2r/fs"); /** * Working directory */ const workingDirectory = process.cwd(); /** * Project path */ let projectPath = ''; /** * Looks for folder containing `package.json` file with framework installed as a dev-dependency * @param targetPath Target path */ const getProjectPath = async (targetPath = workingDirectory) => { if (projectPath) { return projectPath; } const a2rSettingsPath = path_1.default.resolve(targetPath, '.a2r', 'settings.json'); const settingsExist = await (0, fs_1.exists)(a2rSettingsPath); if (settingsExist) { projectPath = path_1.default.dirname(path_1.default.dirname(a2rSettingsPath)); return projectPath; } const nextTarget = path_1.default.dirname(targetPath); if (nextTarget !== '/') { return getProjectPath(nextTarget); } return workingDirectory; }; exports.default = getProjectPath;