refactor(multi) move preparation into curriculum
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
88de5bc602
commit
754a33970e
@ -1,5 +1,5 @@
|
||||
const path = require('path');
|
||||
const { findIndex } = require('lodash');
|
||||
const { findIndex, reduce, toString } = require('lodash');
|
||||
const readDirP = require('readdirp-walk');
|
||||
const { parseMarkdown } = require('../tools/challenge-md-parser');
|
||||
const fs = require('fs');
|
||||
@ -11,8 +11,10 @@ const {
|
||||
/* eslint-enable max-len*/
|
||||
const { COMMENT_TRANSLATIONS } = require('./comment-dictionary');
|
||||
|
||||
const { dasherize } = require('../utils/slugs');
|
||||
const { isAuditedCert } = require('../utils/is-audited');
|
||||
const { dasherize, nameify } = require('../utils/slugs');
|
||||
const { createPoly } = require('../utils/polyvinyl');
|
||||
const { blockNameify } = require('../utils/block-nameify');
|
||||
|
||||
const challengesDir = path.resolve(__dirname, './challenges');
|
||||
const metaDir = path.resolve(challengesDir, '_meta');
|
||||
@ -180,6 +182,43 @@ Trying to parse ${fullPath}`);
|
||||
challenge.template = template;
|
||||
challenge.time = time;
|
||||
|
||||
return prepareChallenge(challenge);
|
||||
}
|
||||
|
||||
// gets the challenge ready for sourcing into Gatsby
|
||||
function prepareChallenge(challenge) {
|
||||
challenge.name = nameify(challenge.title);
|
||||
if (challenge.files) {
|
||||
challenge.files = reduce(
|
||||
challenge.files,
|
||||
(map, file) => {
|
||||
map[file.key] = {
|
||||
...file,
|
||||
head: arrToString(file.head),
|
||||
contents: arrToString(file.contents),
|
||||
tail: arrToString(file.tail)
|
||||
};
|
||||
return map;
|
||||
},
|
||||
{}
|
||||
);
|
||||
// TODO: This should be something that can be folded into the above reduce
|
||||
challenge.files = Object.keys(challenge.files)
|
||||
.filter(key => challenge.files[key])
|
||||
.map(key => challenge.files[key])
|
||||
.reduce(
|
||||
(files, file) => ({
|
||||
...files,
|
||||
[file.key]: {
|
||||
...createPoly(file),
|
||||
seed: file.contents.slice(0)
|
||||
}
|
||||
}),
|
||||
{}
|
||||
);
|
||||
}
|
||||
challenge.block = dasherize(challenge.block);
|
||||
challenge.superBlock = blockNameify(challenge.superBlock);
|
||||
return challenge;
|
||||
}
|
||||
|
||||
@ -255,3 +294,7 @@ function getBlockNameFromFullPath(fullFilePath) {
|
||||
const [, block] = fullFilePath.split(path.sep).reverse();
|
||||
return block;
|
||||
}
|
||||
|
||||
function arrToString(arr) {
|
||||
return Array.isArray(arr) ? arr.join('\n') : toString(arr);
|
||||
}
|
||||
|
Reference in New Issue
Block a user