-
-
Notifications
You must be signed in to change notification settings - Fork 660
Expand file tree
/
Copy pathgenerate-config-tree
More file actions
executable file
·35 lines (28 loc) · 880 Bytes
/
generate-config-tree
File metadata and controls
executable file
·35 lines (28 loc) · 880 Bytes
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
#!/usr/bin/env node
const { exercises } = require('../config.json');
const TAG_CORE = '__core';
const TAG_BONUS = '__bonus';
// node inter-opt exports
exports.TAG_CORE = TAG_CORE;
exports.TAG_BONUS = TAG_BONUS;
exports.tree = exercises.reduce((result, exercise) => {
const tag = exercise.slug;
const item = {
slug: tag,
difficulty: exercise.difficulty,
};
if (exercise.core) {
const current = result[TAG_CORE] || [];
if (result[tag]) {
console.warn(`${tag} is not ordered correctly in config.json`);
}
return {
...result,
__core: current.concat([item]),
[tag]: result[tag] || [],
};
}
const parent = exercise.unlocked_by || TAG_BONUS;
const current = result[parent] || [];
return { ...result, [parent]: current.concat([item]) };
}, {});