@iqai/adk-cli
Version:
CLI tool for creating, running, and testing ADK-TS agents
34 lines • 1.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.findProjectRoot = findProjectRoot;
const node_fs_1 = require("node:fs");
const node_path_1 = require("node:path");
/**
* Finds the root directory of a project by walking upward from a starting path.
*/
function findProjectRoot(startDir) {
const normalizedStart = normalizePath((0, node_path_1.resolve)(startDir));
let current = normalizedStart;
const { root } = (0, node_path_1.parse)(current);
while (true) {
// Check if current directory contains a marker file or folder
if (["package.json", "tsconfig.json", ".env", ".git"].some((marker) => (0, node_fs_1.existsSync)((0, node_path_1.join)(current, marker)))) {
return current;
}
const parent = normalizePath((0, node_path_1.dirname)(current));
// Stop if we've reached filesystem root (e.g., "/" or "C:\")
if (parent === current || parent === normalizePath(root)) {
break;
}
current = parent;
}
// Fallback to the normalized starting path if no project markers were found
return normalizedStart;
}
/**
* Normalizes path separators to forward slashes for cross-platform comparison.
*/
function normalizePath(p) {
return p.replace(/\\/g, "/");
}
//# sourceMappingURL=find-project-root.js.map