@storm-software/config-tools
Version:
A package containing various utilities to support custom workspace configurations and environment management for Storm Software projects, including configuration file handling, environment variable management, and logging utilities.
26 lines (22 loc) • 1.02 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/utilities/find-up.ts
var _fs = require('fs');
var _path = require('path');
var MAX_PATH_SEARCH_DEPTH = 30;
var depth = 0;
function findFolderUp(startPath, endFileNames = [], endDirectoryNames = []) {
const _startPath = _nullishCoalesce(startPath, () => ( process.cwd()));
if (endDirectoryNames.some(
(endDirName) => _fs.existsSync.call(void 0, _path.join.call(void 0, _startPath, endDirName))
)) {
return _startPath;
}
if (endFileNames.some((endFileName) => _fs.existsSync.call(void 0, _path.join.call(void 0, _startPath, endFileName)))) {
return _startPath;
}
if (_startPath !== "/" && depth++ < MAX_PATH_SEARCH_DEPTH) {
const parent = _path.join.call(void 0, _startPath, "..");
return findFolderUp(parent, endFileNames, endDirectoryNames);
}
return void 0;
}
exports.findFolderUp = findFolderUp;