-
Notifications
You must be signed in to change notification settings - Fork 0
/
joinJson.js
57 lines (46 loc) · 1.4 KB
/
joinJson.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const fs = require('fs'); //.promises;
const path = require('path');
// async function myReaddir() {
// const files = await fs.readdir(dir);
// files.forEach((file) => {
// console.log(file);
// });
// }
// myReaddir();
// (dir, (err, files) => {
// if (err) console.log('error', err);
// files.forEach((file) => {
// console.log(file);
// });
// });
const dir = path.join(__dirname, 'File', process.argv[2]);
let finalContent = [];
const read_directory = async (dir) =>
fs.readdirSync(dir).reduce((finalContent, file) => {
filePath = path.join(dir, file);
let content = require(filePath);
finalContent = [...finalContent, ...content];
return finalContent;
}, finalContent);
read_directory(dir).then((data) => {
fs.writeFileSync(
path.join(__dirname, 'File', `${process.argv[2]}-final.json`),
JSON.stringify(data)
);
console.log('👉👉👉finished!!!👈👈👈');
});
// fs.readdir(dir, (err, files) => {
// return new Promise((resolve, reject) => {
// if (err) reject(err);
// files.forEach((file) => {
// console.log(file);
// let content = require(`${dir}${file}`);
// data['passed'] += content.passed;
// data['fixtures'] = data['fixtures'].concat(content['fixtures']);
// });
// resolve(data);
// }).then((data) => {
// fs.writeFileSync('./final.json', JSON.stringify(data));
// });
// });
// node joinJson Data