Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions internal-packages/llm-model-catalog/scripts/generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@
// - Catalog: pnpm run generate-catalog (uses Claude CLI to research models)

import { readFileSync, writeFileSync, existsSync } from "node:fs";
import { execFileSync } from "node:child_process";
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";

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

// Generated files are checked in, so their output must match oxfmt (the repo
// formatter) exactly. JSON.stringify emits quoted keys and no trailing commas,
// which oxfmt rewrites, so without this the files show as modified every time
// `turbo run generate` runs (e.g. as part of `pnpm run db:migrate`).
const written = [];

// --- 1. Generate defaultPrices.ts from default-model-prices.json ---

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

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

writeFileSync(join(srcDir, "modelCatalog.ts"), out);
const outPath = join(srcDir, "modelCatalog.ts");
writeFileSync(outPath, out);
written.push(outPath);
console.log(`Generated modelCatalog.ts (${Object.keys(data).length} entries)`);
} else {
console.log("Skipping modelCatalog.ts — model-catalog.json not found");
}

// --- 3. Format generated files with oxfmt so they match the committed output ---

if (written.length > 0) {
// execFileSync doesn't apply PATHEXT, so target pnpm's .cmd shim on Windows.
const pnpm = process.platform === "win32" ? "pnpm.cmd" : "pnpm";
execFileSync(pnpm, ["exec", "oxfmt", ...written], { stdio: "inherit" });
console.log(`Formatted ${written.length} file(s) with oxfmt`);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}