-
Notifications
You must be signed in to change notification settings - Fork 83
/
build.js
35 lines (27 loc) · 1.06 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const fs = require('fs-extra');
const path = require('path');
const merge = require('deepmerge');
if (fs.existsSync('./dist')) {
fs.removeSync('./dist')
}
fs.mkdirSync('./dist');
const files = fs.readdirSync('./locales');
const defaults = JSON.parse(fs.readFileSync('./locales/en.json'));
files.forEach((file) => {
const lang = path.parse(file).name;
console.log(`Parsing lang ${lang}`)
const fullPath = path.resolve(__dirname, 'locales', file);
let json = JSON.parse(fs.readFileSync(fullPath));
const culture = lang.match(/^([A-Za-z]{2})\-[A-Za-z]{2}$/);
if (culture) {
// If we end up here, it means it's a specific locale such as `fr-FR`
const basePath = path.resolve(__dirname, 'locales', `${culture[1]}.json`);
if (fs.existsSync(basePath)) {
const baseJson = JSON.parse(fs.readFileSync(basePath));
json = merge(baseJson, json);
}
}
json = merge(defaults, json);
const content = JSON.stringify(json);
fs.writeFileSync(path.resolve(__dirname, 'dist', file), content);
});