fix(client): ensure validation works during watch (#38936)

This commit is contained in:
Oliver Eyton-Williams 2020-05-28 17:24:29 +02:00 committed by GitHub
parent 3567813c51
commit d233cb35a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 11 deletions

View File

@ -34,7 +34,7 @@ module.exports = {
options: {
name: 'challenges',
source: buildChallenges,
onSourceChange: replaceChallengeNode,
onSourceChange: replaceChallengeNode(config.locale),
curriculumPath: localeChallengesRootDir
}
},

View File

@ -14,10 +14,10 @@ const arrToString = arr =>
exports.localeChallengesRootDir = getChallengesDirForLang(locale);
exports.replaceChallengeNode = async function replaceChallengeNode(
fullFilePath
) {
return prepareChallenge(await createChallenge(fullFilePath));
exports.replaceChallengeNode = locale => {
return async function replaceChallengeNode(fullFilePath) {
return prepareChallenge(await createChallenge(fullFilePath, null, locale));
};
};
exports.buildChallenges = async function buildChallenges() {

View File

@ -28,7 +28,6 @@ exports.getMetaForBlock = getMetaForBlock;
exports.getChallengesForLang = function getChallengesForLang(lang) {
let curriculum = {};
const validate = challengeSchemaValidator(lang);
return new Promise(resolve => {
let running = 1;
function done() {
@ -39,13 +38,13 @@ exports.getChallengesForLang = function getChallengesForLang(lang) {
readDirP({ root: getChallengesDirForLang(lang) })
.on('data', file => {
running++;
buildCurriculum(file, curriculum, validate).then(done);
buildCurriculum(file, curriculum, lang).then(done);
})
.on('end', done);
});
};
async function buildCurriculum(file, curriculum, validate) {
async function buildCurriculum(file, curriculum, lang) {
const { name, depth, path: filePath, fullPath, stat } = file;
if (depth === 1 && stat.isDirectory()) {
// extract the superBlock info
@ -81,12 +80,12 @@ async function buildCurriculum(file, curriculum, validate) {
}
const { meta } = challengeBlock;
const challenge = await createChallenge(fullPath, meta, validate);
const challenge = await createChallenge(fullPath, meta, lang);
challengeBlock.challenges = [...challengeBlock.challenges, challenge];
}
async function createChallenge(fullPath, maybeMeta, validate) {
async function createChallenge(fullPath, maybeMeta, lang) {
let meta;
if (maybeMeta) {
meta = maybeMeta;
@ -99,7 +98,7 @@ async function createChallenge(fullPath, maybeMeta, validate) {
}
const { name: superBlock } = superBlockInfoFromFullPath(fullPath);
const challenge = await parseMarkdown(fullPath);
const result = validate(challenge);
const result = challengeSchemaValidator(lang)(challenge);
if (result.error) {
console.log(result.value);
throw new Error(result.error);