Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Commit

Permalink
fix(scripts): fix unpack and repack scripts for the new challenge schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeraS authored and scissorsneedfoodtoo committed Jul 30, 2018
1 parent 2edb306 commit 52ed7cf
Show file tree
Hide file tree
Showing 3 changed files with 312 additions and 136 deletions.
69 changes: 32 additions & 37 deletions getChallenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ const hiddenFile = /(^(\.|\/\.))|(.md$)/g;

function getFilesFor(dir) {
let targetDir = path.join(__dirname, dir);
return fs.readdirSync(targetDir)
return fs
.readdirSync(targetDir)
.filter(file => !hiddenFile.test(file))
.map(function(file) {
let superBlock;
if (fs.statSync(path.join(targetDir, file)).isFile()) {
return {file: file};
return { file: file };
}
superBlock = file;
return getFilesFor(path.join(dir, superBlock))
.map(function(data) {
return {
file: path.join(superBlock, data.file),
superBlock: superBlock
};
});
return getFilesFor(path.join(dir, superBlock)).map(function(data) {
return {
file: path.join(superBlock, data.file),
superBlock: superBlock
};
});
})
.reduce(function(files, entry) {
return files.concat(entry);
Expand All @@ -33,7 +33,7 @@ function superblockInfo(filePath) {
let parts = (filePath || '').split('-');
let order = parseInt(parts[0], 10);
if (isNaN(order)) {
return {order: 0, name: filePath};
return { order: 0, name: filePath };
} else {
return {
order: order,
Expand All @@ -46,31 +46,26 @@ module.exports = function getChallenges(challengesDir) {
if (!challengesDir) {
challengesDir = 'challenges';
}
return getFilesFor(challengesDir)
.map(function(data) {
const challengeSpec = require('./' + challengesDir + '/' + data.file);
let superInfo = superblockInfo(data.superBlock);
challengeSpec.fileName = data.file;
challengeSpec.superBlock = superInfo.name;
challengeSpec.superOrder = superInfo.order;
challengeSpec.challenges = challengeSpec.challenges
.map(challenge => omit(
challenge,
[
'betaSolutions',
'betaTests',
'hints',
'MDNlinks',
'null',
'rawSolutions',
'react',
'reactRedux',
'redux',
'releasedOn',
'translations',
'type'
]
));
return challengeSpec;
});
return getFilesFor(challengesDir).map(function(data) {
const challengeSpec = require('./' + challengesDir + '/' + data.file);
let superInfo = superblockInfo(data.superBlock);
challengeSpec.fileName = data.file;
challengeSpec.superBlock = superInfo.name;
challengeSpec.superOrder = superInfo.order;
challengeSpec.challenges = challengeSpec.challenges.map(challenge =>
omit(challenge, [
'betaSolutions',
'betaTests',
'hints',
'MDNlinks',
'null',
'rawSolutions',
'react',
'reactRedux',
'redux',
'type'
])
);
return challengeSpec;
});
};
39 changes: 22 additions & 17 deletions schema/challengeSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,24 @@ Joi.objectId = require('joi-objectid')(Joi);
const schema = Joi.object().keys({
block: Joi.string(),
blockId: Joi.objectId(),
challengeType: Joi.number().min(0).max(9).required(),
challengeType: Joi.number()
.min(0)
.max(9)
.required(),
checksum: Joi.number(),
dashedName: Joi.string(),
description: Joi.array().items(
Joi.string().allow('')
).required(),
description: Joi.array()
.items(Joi.string().allow(''))
.required(),
fileName: Joi.string(),
files: Joi.object().pattern(
/(jsx?|html|css|sass)$/,
Joi.object().keys({
key: Joi.string(),
ext: Joi.string(),
name: Joi.string(),
head: [
Joi.array().items(Joi.string().allow('')),
Joi.string().allow('')
],
tail: [
Joi.array().items(Joi.string().allow('')),
Joi.string().allow('')
],
head: [Joi.array().items(Joi.string().allow('')), Joi.string().allow('')],
tail: [Joi.array().items(Joi.string().allow('')), Joi.string().allow('')],
contents: [
Joi.array().items(Joi.string().allow('')),
Joi.string().allow('')
Expand All @@ -49,17 +46,18 @@ const schema = Joi.object().keys({
crossDomain: Joi.bool()
})
),
solutions: Joi.array().items(
Joi.string().optional()
),
releasedOn: Joi.string().allow(''),
solutions: Joi.array().items(Joi.string().optional()),
superBlock: Joi.string(),
superOrder: Joi.number(),
suborder: Joi.number(),
tests: Joi.array().items(
// public challenges
Joi.object().keys({
text: Joi.string().required(),
testString: Joi.string().allow('').required()
testString: Joi.string()
.allow('')
.required()
}),
// our tests used in certification verification
Joi.object().keys({
Expand All @@ -69,7 +67,14 @@ const schema = Joi.object().keys({
),
template: Joi.string(),
time: Joi.string().allow(''),
title: Joi.string().required()
title: Joi.string().required(),
translations: Joi.object().pattern(
/\w+(-\w+)*/,
Joi.object().keys({
title: Joi.string(),
description: Joi.array().items(Joi.string().allow(''))
})
)
});

exports.validateChallenge = function validateChallenge(challenge) {
Expand Down
Loading

0 comments on commit 52ed7cf

Please sign in to comment.