UNPKG

sda

Version:

Software development assistant

66 lines 2.7 kB
"use strict"; // tslint:disable-next-line: no-reference /// <reference path="../../typings/yeoman-environment-resolver.d.ts" /> var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs = __importStar(require("fs")); const path = __importStar(require("path")); const resolver_1 = __importDefault(require("yeoman-environment/lib/resolver")); const getAbsolutePath_1 = __importDefault(require("../utils/getAbsolutePath")); const Constants_1 = require("./Constants"); const HomeConfig_1 = __importDefault(require("./HomeConfig")); /** * Find all configuration files. Includes current folder upwards, npm packages with configs and the home folder file. * @param rootDir - Current directory. */ function getAllConfigPaths(rootDir, argsConfigPath) { const paths = []; paths.push(...getConfigPaths(rootDir)); paths.push(...getPackageConfigPaths()); const userHomeConfigPath = HomeConfig_1.default.getPathIfExists(); if (userHomeConfigPath) { paths.push(userHomeConfigPath); } // If a config path is passed as arguments, merge it last if (argsConfigPath) { paths.push(getAbsolutePath_1.default(argsConfigPath, process.cwd())); } return paths; } exports.getAllConfigPaths = getAllConfigPaths; /** * Returns the list of paths to config files from npm packages that start with sda-* */ function getPackageConfigPaths() { return resolver_1.default.findGeneratorsIn(resolver_1.default.getNpmPaths(false).reverse(), 'sda-*') .map((dir) => path.join(dir, Constants_1.configFileName)) .filter((fileName) => fs.existsSync(fileName)); } /** * Find all configuration files from the input folder path up to the root folder. * @param dir - Directory to start browsing up */ function getConfigPaths(dir) { const paths = []; dir = path.normalize(dir); const root = path.parse(dir).root; do { const fileName = path.join(dir, Constants_1.configFileName); if (fs.existsSync(fileName)) { paths.push(fileName); } dir = path.normalize(path.join(dir, '..')); } while (dir !== root); return paths; } exports.getConfigPaths = getConfigPaths; //# sourceMappingURL=getConfigPaths.js.map