diff options
Diffstat (limited to 'packages/pogen/src/pogen.ts')
-rw-r--r-- | packages/pogen/src/pogen.ts | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/packages/pogen/src/pogen.ts b/packages/pogen/src/pogen.ts new file mode 100644 index 000000000..72b7c81d7 --- /dev/null +++ b/packages/pogen/src/pogen.ts @@ -0,0 +1,48 @@ +import { potextract } from "./potextract.js"; +import * as child_process from "child_process"; +import * as fs from "fs"; +import glob = require("glob"); +import { po2ts } from "./po2ts.js"; + +function usage(): never { + console.log("usage: pogen <extract|merge|emit>"); + process.exit(1); +} + +export function main() { + const subcommand = process.argv[2]; + if (process.argv.includes("--help") || !subcommand) { + usage(); + } + switch (subcommand) { + case "extract": + potextract(); + break; + case "merge": { + const packageJson = JSON.parse( + fs.readFileSync("./package.json", { encoding: "utf-8" }), + ); + + const poDomain = packageJson.pogen?.domain; + if (!poDomain) { + console.error("missing 'pogen.domain' field in package.json"); + process.exit(1); + } + const files = glob.sync("src/i18n/*.po"); + console.log(files); + for (const f of files) { + console.log(`merging ${f}`); + child_process.execSync( + `msgmerge -o '${f}' '${f}' 'src/i18n/${poDomain}.pot'`, + ); + } + break; + } + case "emit": + po2ts(); + break; + default: + console.error(`unknown subcommand '${subcommand}'`); + usage(); + } +} |