2022-03-17 05:50:24 +01:00
|
|
|
const fs = require('fs-extra');
|
2020-09-12 13:19:33 +02:00
|
|
|
const path = require('path');
|
2020-09-19 18:12:44 +02:00
|
|
|
const del = require('del');
|
2020-09-12 13:19:33 +02:00
|
|
|
const prettier = require('prettier');
|
2020-09-19 18:12:44 +02:00
|
|
|
const chalk = require('chalk');
|
2020-09-12 13:19:33 +02:00
|
|
|
|
|
|
|
const src = path.resolve(__dirname, '../lang');
|
2020-09-14 04:01:02 +02:00
|
|
|
const dest = path.resolve(__dirname, '../build');
|
2020-09-12 13:19:33 +02:00
|
|
|
const files = fs.readdirSync(src);
|
|
|
|
|
2020-09-19 18:12:44 +02:00
|
|
|
const removed = del.sync([path.join(dest, '*.json')]);
|
|
|
|
|
|
|
|
if (removed.length) {
|
|
|
|
console.log(removed.map(n => `${n} ${chalk.redBright('✗')}`).join('\n'));
|
|
|
|
}
|
|
|
|
|
2022-03-17 05:50:24 +01:00
|
|
|
async function run() {
|
|
|
|
await fs.ensureDir(dest);
|
|
|
|
|
|
|
|
files.forEach(file => {
|
|
|
|
const lang = require(`../lang/${file}`);
|
|
|
|
const keys = Object.keys(lang).sort();
|
2020-09-12 13:19:33 +02:00
|
|
|
|
2022-03-17 05:50:24 +01:00
|
|
|
const formatted = keys.reduce((obj, key) => {
|
|
|
|
obj[key] = { defaultMessage: lang[key] };
|
|
|
|
return obj;
|
|
|
|
}, {});
|
2020-09-12 13:19:33 +02:00
|
|
|
|
2022-03-17 05:50:24 +01:00
|
|
|
const json = prettier.format(JSON.stringify(formatted), { parser: 'json' });
|
2020-09-12 13:19:33 +02:00
|
|
|
|
2022-03-17 05:50:24 +01:00
|
|
|
fs.writeFileSync(path.resolve(dest, file), json);
|
2020-09-12 13:19:33 +02:00
|
|
|
|
2022-03-17 05:50:24 +01:00
|
|
|
console.log(path.resolve(src, file), chalk.greenBright('->'), path.resolve(dest, file));
|
|
|
|
});
|
|
|
|
}
|
2020-09-12 13:19:33 +02:00
|
|
|
|
2022-03-17 05:50:24 +01:00
|
|
|
run();
|