import { existsSync, readFileSync } from "node:fs"; import { dirname, join } from "node:path"; import type { PeppaProjectFile } from "@peppa/shared"; /** Walks up from `dir` looking for `.peppa/project.json`. */ export function findProjectFile(dir: string): { path: string; data: PeppaProjectFile } | null { let cur = dir; for (;;) { const path = join(cur, ".peppa", "project.json"); if (existsSync(path)) return { path, data: JSON.parse(readFileSync(path, "utf8")) as PeppaProjectFile }; const parent = dirname(cur); if (parent === cur) return null; cur = parent; } }