-
Notifications
You must be signed in to change notification settings - Fork 1
/
getDataFiles.js
29 lines (23 loc) · 915 Bytes
/
getDataFiles.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
module.exports = function (pathToFolder) {
try {
const fs = require('fs');
const path = require('path');
const shell = require("shelljs");
const createdConfig = new Promise((resolve) => {
const jsonInDir = fs.readdirSync(pathToFolder).filter(file => path.extname(file) === '.json');
const result = {};
jsonInDir.forEach(file => {
const fileData = fs.readFileSync(path.join(pathToFolder, file), 'utf8');
const json = JSON.parse(fileData.toString());
const fileName = path.parse(file).name;
result[fileName] = { ...json };
});
fs.writeFile(`${__dirname}/src/compare-json-translations.config.js`, `export default ${JSON.stringify(result)}`, (err) => { resolve() });
})
createdConfig.then(() => {
shell.exec(`cd ${__dirname} && npm run serve`);
});
} catch (err) {
console.log('\x1b[31m%s\x1b[0m', err);
}
}