Skip to content

Commit 7f1a026

Browse files
committed
fix(llm-model-catalog): format generated files so they stop showing as modified
generate.mjs wrote defaultPrices.ts and modelCatalog.ts with raw JSON.stringify (quoted keys, no trailing commas), but the committed files were oxfmt-formatted, so the generator output never matched HEAD. Any 'turbo run generate' (e.g. via 'pnpm run db:migrate') left both files dirty with an identical-data diff. Run oxfmt on the output as the final generate step so regeneration is a no-op.
1 parent 4c2c255 commit 7f1a026

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

internal-packages/llm-model-catalog/scripts/generate.mjs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@
1212
// - Catalog: pnpm run generate-catalog (uses Claude CLI to research models)
1313

1414
import { readFileSync, writeFileSync, existsSync } from "node:fs";
15+
import { execFileSync } from "node:child_process";
1516
import { join, dirname } from "node:path";
1617
import { fileURLToPath } from "node:url";
1718

1819
const __dirname = dirname(fileURLToPath(import.meta.url));
1920
const srcDir = join(__dirname, "..", "src");
2021

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+
2128
// --- 1. Generate defaultPrices.ts from default-model-prices.json ---
2229

2330
const pricesJsonPath = join(srcDir, "default-model-prices.json");
@@ -49,7 +56,9 @@ if (existsSync(pricesJsonPath)) {
4956
out += "export const defaultModelPrices: DefaultModelDefinition[] = ";
5057
out += JSON.stringify(stripped, null, 2) + ";\n";
5158

52-
writeFileSync(join(srcDir, "defaultPrices.ts"), out);
59+
const outPath = join(srcDir, "defaultPrices.ts");
60+
writeFileSync(outPath, out);
61+
written.push(outPath);
5362
console.log(`Generated defaultPrices.ts (${stripped.length} models)`);
5463
} else {
5564
console.log("Skipping defaultPrices.ts — default-model-prices.json not found");
@@ -91,8 +100,17 @@ if (existsSync(catalogJsonPath)) {
91100
out += "export const modelCatalog: Record<string, ModelCatalogEntry> = ";
92101
out += JSON.stringify(data, null, 2) + ";\n";
93102

94-
writeFileSync(join(srcDir, "modelCatalog.ts"), out);
103+
const outPath = join(srcDir, "modelCatalog.ts");
104+
writeFileSync(outPath, out);
105+
written.push(outPath);
95106
console.log(`Generated modelCatalog.ts (${Object.keys(data).length} entries)`);
96107
} else {
97108
console.log("Skipping modelCatalog.ts — model-catalog.json not found");
98109
}
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

Comments
 (0)