This repository was archived by the owner on May 31, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmergeChallenges.js
More file actions
50 lines (45 loc) · 1.19 KB
/
mergeChallenges.js
File metadata and controls
50 lines (45 loc) · 1.19 KB
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
/* eslint-disable import/unambiguous */
/*
* CLI Node utility to generate a
* merge of all challenge data.
* */
const fs = require('fs');
const path = require('path');
const { promisify } = require('util');
const { format } = require('prettier');
const readDirAsync = promisify(fs.readdir);
const readFileAsync = promisify(fs.readFile);
const challengesPath = path.resolve('./src/challenges');
let topics = [];
readDirAsync(challengesPath)
.then(subjects =>
Promise.all(
subjects.map(dir => {
topics.push(dir);
return readDirAsync(path.join(challengesPath, dir));
})
)
)
.then(fileNames =>
Promise.all(
topics.map((topic, i) =>
Promise.all(
fileNames[i].map(y =>
readFileAsync(path.join(challengesPath, topic, y), 'utf8')
)
)
)
)
)
.then(challenges => {
const dataObj = {};
topics.forEach((topic, i) => {
dataObj[topic] = challenges[i].map(c => JSON.parse(c));
});
const dataPath = path.resolve(challengesPath, '../', 'data.json');
fs.writeFileSync(
dataPath,
format(JSON.stringify(dataObj), { parser: 'json' })
);
})
.catch(err => console.log(err));