forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createPathMigrationMap.js
60 lines (55 loc) · 1.76 KB
/
createPathMigrationMap.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
58
59
60
require('babel-register');
const { getChallenges } = require('@freecodecamp/curriculum');
const fs = require('fs');
const path = require('path');
const { Observable } = require('rx');
const { dasherize } = require('../server/utils');
let pathMap = {};
function createPathMigrationMap() {
return new Promise(resolve => {
Observable.of(getChallenges())
.map(blocks => {
blocks.forEach(block => {
const {name: blockName, superBlock, challenges } = block;
if (!(dasherize(superBlock) in pathMap)) {
pathMap[dasherize(superBlock)] = {};
}
if (!(dasherize(blockName) in pathMap[superBlock])) {
pathMap[dasherize(superBlock)][dasherize(blockName)] = challenges
.map(({ title, challengeType }) => ({
dashedName: dasherize(title),
challengeType
}));
}
});
})
.subscribe(() => {}, console.error, () => {
const migMap = Object.keys(pathMap)
.filter(key => !key.includes('certificate'))
.map(superBlock => {
return Object.keys(pathMap[superBlock])
.map(block => {
return pathMap[superBlock][block]
.reduce((map, {dashedName, challengeType}) => ({
...map,
[dashedName]: challengeType === 7 ?
`/${superBlock}/${block}` :
`/${superBlock}/${block}/${dashedName}`
}), {});
}).reduce((acc, current) => ({
...acc,
...current
}), {});
}).reduce((acc, current) => ({
...acc,
...current
}), {});
fs.writeFileSync(
path.resolve(__dirname, '../server/resources/pathMigration.json'),
JSON.stringify(migMap, null, 2)
);
resolve();
});
});
}
exports.createPathMigrationMap = createPathMigrationMap;