fix(curriculum): validate straight after parsing (#38896)

This commit is contained in:
Oliver Eyton-Williams
2020-05-27 13:29:58 +02:00
committed by GitHub
parent db08ab2965
commit 4d176bf2fb

View File

@ -81,17 +81,12 @@ async function buildCurriculum(file, curriculum, validate) {
}
const { meta } = challengeBlock;
const challenge = await createChallenge(fullPath, meta);
const challenge = await createChallenge(fullPath, meta, validate);
const result = validate(challenge);
if (result.error) {
console.log(result.value);
throw new Error(result.error);
}
challengeBlock.challenges = [...challengeBlock.challenges, challenge];
}
async function createChallenge(fullPath, maybeMeta) {
async function createChallenge(fullPath, maybeMeta, validate) {
let meta;
if (maybeMeta) {
meta = maybeMeta;
@ -104,6 +99,11 @@ async function createChallenge(fullPath, maybeMeta) {
}
const { name: superBlock } = superBlockInfoFromFullPath(fullPath);
const challenge = await parseMarkdown(fullPath);
const result = validate(challenge);
if (result.error) {
console.log(result.value);
throw new Error(result.error);
}
const challengeOrder = findIndex(
meta.challengeOrder,
([id]) => id === challenge.id