Switched to type: module.

This commit is contained in:
Mike Cao 2025-04-29 14:36:52 -07:00
parent 615a6d444f
commit 4e37e10b6d
20 changed files with 25 additions and 50 deletions

36
scripts/format-lang.js Normal file
View file

@ -0,0 +1,36 @@
import path from 'node:path';
import fs from 'fs-extra';
import del from 'del';
import prettier from 'prettier';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const src = path.resolve(process.cwd(), 'src/lang');
const dest = path.resolve(process.cwd(), 'build/messages');
const files = fs.readdirSync(src);
del.sync([path.join(dest)]);
/*
This script takes the files from the `lang` folder and formats them into
the format that format-js expects.
*/
async function run() {
await fs.ensureDir(dest);
files.forEach(file => {
const lang = require(path.resolve(process.cwd()`src/lang/${file}`));
const keys = Object.keys(lang).sort();
const formatted = keys.reduce((obj, key) => {
obj[key] = { defaultMessage: lang[key] };
return obj;
}, {});
const json = prettier.format(JSON.stringify(formatted), { parser: 'json' });
fs.writeFileSync(path.resolve(dest, file), json);
});
}
run();