fabro/lib/packages/fabro-api-client/scripts/normalize-generated.ts
Bryan Helmkamp d53cf1eb76
chore(api-client): make client generation idempotent
`bun run generate` (openapi-generator typescript-axios) emits trailing
spaces and extra blank lines, so every regeneration produced a noisy
whitespace diff that masked real spec/client drift.

Add a normalize-generated.ts post-generation pass that strips trailing
whitespace and ends each file with exactly one newline, and chain it
into the `generate` script. Establishes the normalized baseline across
the generated client; running `generate` twice now yields no diff.

No content changes — the entire diff is whitespace.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 14:29:11 -04:00

27 lines
883 B
TypeScript

// Normalizes openapi-generator output so `bun run generate` is idempotent.
//
// The typescript-axios templates emit trailing spaces on some lines and extra
// blank lines at end of file. Left alone, every regeneration produces a noisy
// whitespace diff that masks real spec/client drift. This pass strips trailing
// whitespace from every line and ends each file with exactly one newline.
import { Glob } from "bun";
const glob = new Glob("src/**/*.ts");
let changed = 0;
for await (const path of glob.scan(".")) {
const original = await Bun.file(path).text();
const normalized =
original
.split("\n")
.map((line) => line.replace(/\s+$/, ""))
.join("\n")
.replace(/\n+$/, "") + "\n";
if (normalized !== original) {
await Bun.write(path, normalized);
changed += 1;
}
}
console.log(`normalize-generated: ${changed} file(s) updated`);