umami/scripts/format-lang.js

31 lines
751 B
JavaScript
Raw Normal View History

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');
const del = require('del');
2020-09-12 13:19:33 +02:00
const prettier = require('prettier');
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);
2022-08-02 02:14:36 +02:00
del.sync([path.join(dest, '*.json')]);
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
run();