Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

i18n-check.ts

32 lines1.2 KB

1#!/usr/bin/env node
2// @effect-diagnostics nodeBuiltinImport:off globalConsole:off - A one-shot CI check; synchronous Node APIs keep it small.
3// Fails when a committed GT catalog drifts from the source: `gt generate --check` would write a
4// different en.json, or a locale catalog's keys differ from en.json. Needs no GT credentials or network.
5import * as NodeChildProcess from "node:child_process";
6import * as NodePath from "node:path";
7​
8const APPS = ["apps/web", "apps/mobile", "apps/desktop"];
9const root = NodePath.resolve(import.meta.dirname, "..");
10let failed = false;
11​
12for (const app of APPS) {
13 // The gt CLI runs through Node because the `.bin/gt` shim is a shell script Windows cannot spawn.
14 const gt = NodeChildProcess.spawnSync(
15 process.execPath,
16 ["node_modules/gt/bin/main.js", "generate", "--check"],
17 { cwd: NodePath.join(root, app), encoding: "utf8" },
18 );
19 if (gt.status !== 0) {
20 failed = true;
21 console.error(`${app}: catalogs are out of date\n${gt.stdout}${gt.stderr}`);
22 }
24​
25if (failed) {
26 console.error(
27 "\nRun `vp run i18n:generate` in the app, then translate any new keys in every locale catalog.",
28 );
29 process.exitCode = 1;
30} else {
31 console.log(`i18n catalogs match the source in ${APPS.join(", ")}.`);