@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* The build's front door to `check-i18n.mjs`.
|
||||
*
|
||||
* Imported by `astro.config.mjs` so a catalog problem is found before a single page
|
||||
* renders, rather than after a two-minute build produces 180 pages with a raw key on
|
||||
* them. Errors throw and stop the build; missing keys print and let it continue.
|
||||
*/
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const here = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
export async function checkCatalogs() {
|
||||
const result = spawnSync(process.execPath, [path.join(here, 'check-i18n.mjs')], {
|
||||
encoding: 'utf8',
|
||||
});
|
||||
|
||||
// Warnings and the summary go straight through, so a missing-key list is visible in
|
||||
// the build log where whoever is adding a language will actually read it.
|
||||
if (result.stdout) process.stdout.write(result.stdout);
|
||||
if (result.stderr) process.stderr.write(result.stderr);
|
||||
|
||||
if (result.status !== 0) {
|
||||
throw new Error(
|
||||
'check-i18n failed. Fix the keys listed above, or run `pnpm check:i18n` to see them again.',
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user