72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
#!/usr/bin/env bun
|
|
/**
|
|
* `check-locale-completeness.ts` — assert every key in
|
|
* `<package>/src/locales/en-GB.json` exists in every other locale
|
|
* bundle shipped by `@suaveplan/react-forms`. Wraps the shared check
|
|
* implemented inside `@suaveplan/react-ui`'s sibling script so the two
|
|
* packages stay parity-equivalent.
|
|
*
|
|
* Usage:
|
|
* bun packages/react/react-forms/scripts/check-locale-completeness.ts <package-root>
|
|
*
|
|
* Exit codes:
|
|
* 0 — every key parity-complete
|
|
* 1 — at least one key missing
|
|
* 2 — internal failure
|
|
*/
|
|
|
|
import { checkLocaleCompleteness } from "../../react-ui/scripts/check-locale-completeness.js";
|
|
|
|
interface BundleDiff {
|
|
readonly locale: string;
|
|
readonly missing: ReadonlyArray<string>;
|
|
readonly extra: ReadonlyArray<string>;
|
|
}
|
|
|
|
function format(diffs: ReadonlyArray<BundleDiff>): string {
|
|
if (diffs.length === 0) {
|
|
return "check-locale-completeness: every locale parity-complete.";
|
|
}
|
|
const lines: string[] = [
|
|
`check-locale-completeness: ${diffs.length} locale(s) failed parity.`,
|
|
];
|
|
for (const d of diffs) {
|
|
lines.push(` ${d.locale}:`);
|
|
if (d.missing.length > 0) {
|
|
lines.push(" missing keys:");
|
|
for (const k of d.missing) lines.push(` - ${k}`);
|
|
}
|
|
if (d.extra.length > 0) {
|
|
lines.push(" extra keys (not in en-GB):");
|
|
for (const k of d.extra) lines.push(` - ${k}`);
|
|
}
|
|
}
|
|
return lines.join("\n");
|
|
}
|
|
|
|
async function main(): Promise<void> {
|
|
const argv = process.argv.slice(2);
|
|
if (argv.length === 0) {
|
|
process.stderr.write(
|
|
"Usage: check-locale-completeness.ts <package-root>\n"
|
|
);
|
|
process.exit(2);
|
|
}
|
|
const root = argv[0] as string;
|
|
const diffs = (await checkLocaleCompleteness(root)) as BundleDiff[];
|
|
const message = format(diffs);
|
|
if (diffs.length === 0) {
|
|
process.stdout.write(`${message}\n`);
|
|
process.exit(0);
|
|
}
|
|
process.stderr.write(`${message}\n`);
|
|
process.exit(1);
|
|
}
|
|
|
|
if (import.meta.main) {
|
|
await main().catch((err: unknown) => {
|
|
process.stderr.write(`internal error: ${(err as Error).message}\n`);
|
|
process.exit(2);
|
|
});
|
|
}
|