| 12 | const CONFIG_FILENAMES = ["codegen.config.json"] |
| 13 | |
| 14 | function loadConfig(cwd: string, explicit?: string): CodegenDefaults | undefined { |
| 15 | const candidates = explicit ? [path.resolve(cwd, explicit)] : CONFIG_FILENAMES.map((f) => path.join(cwd, f)) |
| 16 | for (const candidate of candidates) { |
| 17 | if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) { |
| 18 | const parsed = JSON.parse(fs.readFileSync(candidate, "utf8")) |
| 19 | return parsed as CodegenDefaults |
| 20 | } |
| 21 | } |
| 22 | if (explicit) { |
| 23 | throw new Error(`Config not found: ${explicit}`) |
| 24 | } |
| 25 | return undefined |
| 26 | } |
| 27 | |
| 28 | const modelBlockRe = /\/\/ codegen:start[ \t]*\{[^}]*\bpreset:\s*model\b/ |
| 29 | const staticTypeModelBlockRe = |