-
Notifications
You must be signed in to change notification settings - Fork 1
/
copy-i18n.js
38 lines (34 loc) · 1.19 KB
/
copy-i18n.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
36
37
38
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
const dirs = [
['i18n/vi', '.locales/vi'],
['i18n/en', '.locales/en'],
];
dirs.map((dir) => {
const srcPath = path.join(__dirname, dir[0]);
const dstPath = path.join(__dirname, dir[1]);
// console.log(dstPath);
execSync(`mkdir -p ${dstPath}`);
execSync(`rm -f ${dstPath}/*.json`);
// create i18n.json
execSync(`rm -f ` + path.join(process.cwd(), `i18n.json`));
const i18n = require('./i18n');
fs.writeFileSync(path.join(process.cwd(), `i18n.json`), JSON.stringify(i18n, null, ' '), {
encoding: 'utf8',
flag: 'w',
});
const files = fs.readdirSync(srcPath);
files.forEach((fileName) => {
const fileInfo = path.parse(fileName);
// console.log(fileInfo);
if (fileInfo.ext === '.js') {
const contentObj = require(`./${dir[0]}/${fileName}`);
const contentString = JSON.stringify(contentObj, null, ' ');
// write to public folder
fs.writeFileSync(path.join(dstPath, `${fileInfo.name}.json`), contentString, { encoding: 'utf8', flag: 'w' });
}
});
});