import { readFileSync, existsSync } from "node:fs"; import { resolve } from "node:path"; import { parse as parseYaml } from "yaml"; function findConfigPath(explicit?: string): string | null { const candidates = [ explicit, "pipeline.config.yaml", "pipeline.config.yml", "config/default.yaml", ].filter(Boolean) as string[]; // Walk up from cwd so the lookup works in both dev (cwd = apps/web) and // Docker production (cwd = /app/apps/web), where the bundled import.meta.url // points inside .next rather than the source tree. let dir = process.cwd(); for (let i = 0; i < 6; i++) { for (const c of candidates) { const p = resolve(dir, c); if (existsSync(p)) return p; } if (dir === "/") break; dir = resolve(dir, ".."); } return null; } export function loadConfig(configPath?: string): Record | null { const p = findConfigPath(configPath); if (!p) return null; const content = readFileSync(p, "utf-8"); return parseYaml(content); }