This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repack.js
51 lines (42 loc) · 1.62 KB
/
repack.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
/* eslint-disable no-eval, no-process-exit */
import fs from 'fs-extra';
import path from 'path';
import {UnpackedChallenge, ChallengeFile} from './unpackedChallenge';
// Repack all challenges from all
// seed/unpacked/00-foo/bar/000-xxx-id.html files
// into
// seed/challenges/00-foo/bar.json files
let unpackedRoot = path.join(__dirname, 'unpacked');
let seedChallengesRoot = path.join(__dirname, 'challenges');
function directoriesIn(parentDir) {
return fs.readdirSync(parentDir)
.filter(entry => fs.statSync(path.join(parentDir, entry)).isDirectory());
}
let superBlocks = directoriesIn(unpackedRoot);
superBlocks.forEach(superBlock => {
let superBlockPath = path.join(unpackedRoot, superBlock);
console.log(`Repacking ${superBlockPath}...`);
let blocks = directoriesIn(superBlockPath);
blocks.forEach(blockName => {
let blockPath = path.join(superBlockPath, blockName);
let blockFilePath = path.join(blockPath, blockName + '.json');
let block = require(blockFilePath);
let index = 0;
block.challenges.forEach(challengeJson => {
let unpackedChallenge =
new UnpackedChallenge(blockPath, challengeJson, index);
let unpackedFile = unpackedChallenge.challengeFile();
let chunks = unpackedFile.readChunks();
Object.assign(block.challenges[ index ], chunks);
index += 1;
});
let outputFilePath =
path.join(seedChallengesRoot, superBlock, blockName + '.json');
// todo: async
fs.writeFileSync(outputFilePath, JSON.stringify(block, null, 2));
});
});
// let challenges = getChallenges();
// challenges.forEach(challengeBlock => {
// console.log()
// });