|
12 | 12 | // - Catalog: pnpm run generate-catalog (uses Claude CLI to research models) |
13 | 13 |
|
14 | 14 | import { readFileSync, writeFileSync, existsSync } from "node:fs"; |
| 15 | +import { execFileSync } from "node:child_process"; |
15 | 16 | import { join, dirname } from "node:path"; |
16 | 17 | import { fileURLToPath } from "node:url"; |
17 | 18 |
|
18 | 19 | const __dirname = dirname(fileURLToPath(import.meta.url)); |
19 | 20 | const srcDir = join(__dirname, "..", "src"); |
20 | 21 |
|
| 22 | +// Generated files are checked in, so their output must match oxfmt (the repo |
| 23 | +// formatter) exactly. JSON.stringify emits quoted keys and no trailing commas, |
| 24 | +// which oxfmt rewrites, so without this the files show as modified every time |
| 25 | +// `turbo run generate` runs (e.g. as part of `pnpm run db:migrate`). |
| 26 | +const written = []; |
| 27 | + |
21 | 28 | // --- 1. Generate defaultPrices.ts from default-model-prices.json --- |
22 | 29 |
|
23 | 30 | const pricesJsonPath = join(srcDir, "default-model-prices.json"); |
@@ -49,7 +56,9 @@ if (existsSync(pricesJsonPath)) { |
49 | 56 | out += "export const defaultModelPrices: DefaultModelDefinition[] = "; |
50 | 57 | out += JSON.stringify(stripped, null, 2) + ";\n"; |
51 | 58 |
|
52 | | - writeFileSync(join(srcDir, "defaultPrices.ts"), out); |
| 59 | + const outPath = join(srcDir, "defaultPrices.ts"); |
| 60 | + writeFileSync(outPath, out); |
| 61 | + written.push(outPath); |
53 | 62 | console.log(`Generated defaultPrices.ts (${stripped.length} models)`); |
54 | 63 | } else { |
55 | 64 | console.log("Skipping defaultPrices.ts — default-model-prices.json not found"); |
@@ -91,8 +100,17 @@ if (existsSync(catalogJsonPath)) { |
91 | 100 | out += "export const modelCatalog: Record<string, ModelCatalogEntry> = "; |
92 | 101 | out += JSON.stringify(data, null, 2) + ";\n"; |
93 | 102 |
|
94 | | - writeFileSync(join(srcDir, "modelCatalog.ts"), out); |
| 103 | + const outPath = join(srcDir, "modelCatalog.ts"); |
| 104 | + writeFileSync(outPath, out); |
| 105 | + written.push(outPath); |
95 | 106 | console.log(`Generated modelCatalog.ts (${Object.keys(data).length} entries)`); |
96 | 107 | } else { |
97 | 108 | console.log("Skipping modelCatalog.ts — model-catalog.json not found"); |
98 | 109 | } |
| 110 | + |
| 111 | +// --- 3. Format generated files with oxfmt so they match the committed output --- |
| 112 | + |
| 113 | +if (written.length > 0) { |
| 114 | + execFileSync("pnpm", ["exec", "oxfmt", ...written], { stdio: "inherit" }); |
| 115 | + console.log(`Formatted ${written.length} file(s) with oxfmt`); |
| 116 | +} |
0 commit comments