config.ts 1018 B

123456789101112131415161718192021222324252627282930313233
  1. import { readFileSync, existsSync } from "node:fs";
  2. import { resolve } from "node:path";
  3. import { parse as parseYaml } from "yaml";
  4. function findConfigPath(explicit?: string): string | null {
  5. const candidates = [
  6. explicit,
  7. "pipeline.config.yaml",
  8. "pipeline.config.yml",
  9. "config/default.yaml",
  10. ].filter(Boolean) as string[];
  11. // Walk up from cwd so the lookup works in both dev (cwd = apps/web) and
  12. // Docker production (cwd = /app/apps/web), where the bundled import.meta.url
  13. // points inside .next rather than the source tree.
  14. let dir = process.cwd();
  15. for (let i = 0; i < 6; i++) {
  16. for (const c of candidates) {
  17. const p = resolve(dir, c);
  18. if (existsSync(p)) return p;
  19. }
  20. if (dir === "/") break;
  21. dir = resolve(dir, "..");
  22. }
  23. return null;
  24. }
  25. export function loadConfig(configPath?: string): Record<string, any> | null {
  26. const p = findConfigPath(configPath);
  27. if (!p) return null;
  28. const content = readFileSync(p, "utf-8");
  29. return parseYaml(content);
  30. }