@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 (24 loc) • 736 B
JavaScript
// src/utilities/find-up.ts
import { existsSync } from "node:fs";
import { join } from "node:path";
var MAX_PATH_SEARCH_DEPTH = 30;
var depth = 0;
function findFolderUp(startPath, endFileNames = [], endDirectoryNames = []) {
const _startPath = startPath ?? process.cwd();
if (endDirectoryNames.some(
(endDirName) => existsSync(join(_startPath, endDirName))
)) {
return _startPath;
}
if (endFileNames.some((endFileName) => existsSync(join(_startPath, endFileName)))) {
return _startPath;
}
if (_startPath !== "/" && depth++ < MAX_PATH_SEARCH_DEPTH) {
const parent = join(_startPath, "..");
return findFolderUp(parent, endFileNames, endDirectoryNames);
}
return void 0;
}
export {
findFolderUp
};