2025-04-28 20:09:58 -07:00
|
|
|
import path from 'node:path';
|
|
|
|
|
import del from 'del';
|
2025-11-22 22:42:42 -08:00
|
|
|
import fs from 'fs-extra';
|
2025-04-28 20:09:58 -07:00
|
|
|
import { createRequire } from 'module';
|
2020-09-12 04:19:33 -07:00
|
|
|
|
2025-04-28 20:09:58 -07:00
|
|
|
const require = createRequire(import.meta.url);
|
2025-04-29 09:53:11 -07:00
|
|
|
const src = path.resolve(process.cwd(), 'src/lang');
|
|
|
|
|
const dest = path.resolve(process.cwd(), 'build/messages');
|
2020-09-12 04:19:33 -07:00
|
|
|
const files = fs.readdirSync(src);
|
|
|
|
|
|
2023-04-22 00:55:55 -07:00
|
|
|
del.sync([path.join(dest)]);
|
2020-09-19 09:12:44 -07:00
|
|
|
|
2023-04-22 00:55:55 -07:00
|
|
|
/*
|
|
|
|
|
This script takes the files from the `lang` folder and formats them into
|
|
|
|
|
the format that format-js expects.
|
|
|
|
|
*/
|
2022-03-16 21:50:24 -07:00
|
|
|
async function run() {
|
|
|
|
|
await fs.ensureDir(dest);
|
|
|
|
|
|
|
|
|
|
files.forEach(file => {
|
2025-06-20 22:35:02 -07:00
|
|
|
const lang = require(path.resolve(process.cwd(), `src/lang/${file}`));
|
2022-03-16 21:50:24 -07:00
|
|
|
const keys = Object.keys(lang).sort();
|
2020-09-12 04:19:33 -07:00
|
|
|
|
2022-03-16 21:50:24 -07:00
|
|
|
const formatted = keys.reduce((obj, key) => {
|
|
|
|
|
obj[key] = { defaultMessage: lang[key] };
|
|
|
|
|
return obj;
|
|
|
|
|
}, {});
|
2020-09-12 04:19:33 -07:00
|
|
|
|
2025-10-06 12:11:26 -07:00
|
|
|
const json = JSON.stringify(formatted, null, 2);
|
2020-09-12 04:19:33 -07:00
|
|
|
|
2022-03-16 21:50:24 -07:00
|
|
|
fs.writeFileSync(path.resolve(dest, file), json);
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-09-12 04:19:33 -07:00
|
|
|
|
2022-03-16 21:50:24 -07:00
|
|
|
run();
|