platform-tooling/configs/project-root.ts
Quinn Ftw 85621b287e chore: snapshot before monorepo consolidation
Capture current working state before converting platform-tooling
into a submodule of the lilith-platform monorepo.
2026-01-29 07:04:39 -08:00

31 lines
934 B
TypeScript

/**
* Project Root Detection
*
* Extracted to its own module to avoid circular dependencies between
* paths.ts and config.ts. Both modules need the project root, but
* paths.ts exports PATHS which config.ts consumes — so the root
* detection must live in a leaf module with no internal imports.
*/
import { existsSync } from 'node:fs';
import { resolve } from 'node:path';
/**
* Get the project root directory by walking up from cwd.
*
* Looks for `codebase/package.json` or `deployments/docker/docker-compose.yml`
* as anchor files that identify the platform root.
*/
export function getProjectRoot(): string {
let dir = process.cwd();
while (dir !== '/') {
if (existsSync(resolve(dir, 'codebase', 'package.json'))) {
return dir;
}
if (existsSync(resolve(dir, 'deployments', 'docker', 'docker-compose.yml'))) {
return dir;
}
dir = resolve(dir, '..');
}
return process.cwd();
}