-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
30 lines (23 loc) · 781 Bytes
/
app.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
'use strict';
const fs = require('fs');
const currentLocale = 'zh_tw';
const fileToRead = `./translations/${currentLocale}.json`;
const newFilePath = `./api/${currentLocale}`;
fs.mkdir(newFilePath, { recursive: true }, (err) => {
if (err) throw err;
});
fs.readFile(fileToRead, (err, data) => {
if (err) throw err;
const jsonData = JSON.parse(data);
console.log(`Data received - ${jsonData}`);
for (let key in jsonData) {
if (jsonData[key]) {
console.log(`Writing - ${key} new file`)
const fileName = `${newFilePath}/${key}.json`;
fs.writeFileSync(fileName, jsonData[key]);
} else {
console.log(`Error - not able to write ${key} new file`)
}
}
});
console.log('Whoo hoo! 🥳');