fix(schema): change schema and unpack script

This commit is contained in:
Kristofer Koishigawa 2018-09-20 22:24:45 +09:00 committed by Mrugesh Mohapatra
parent 0db6aeb523
commit b014b23404
4 changed files with 20 additions and 32 deletions

View File

@ -42,7 +42,10 @@ function superblockInfo(filePath) {
}
}
module.exports = function getChallenges(challengesDir) {
// unpackFlag is an argument passed by the unpack script in unpack.js
// which allows us to conditionall omit translations when running
// the test suite and prevent schema related errors in the main fCC branch
module.exports = function getChallenges(challengesDir, unpackFlag) {
if (!challengesDir) {
challengesDir = 'challenges';
}
@ -63,6 +66,8 @@ module.exports = function getChallenges(challengesDir) {
'react',
'reactRedux',
'redux',
'releasedOn',
unpackFlag ? undefined : 'translations',
'type'
])
);

View File

@ -46,7 +46,6 @@ const schema = Joi.object().keys({
crossDomain: Joi.bool()
})
),
releasedOn: Joi.string().allow(''),
solutions: Joi.array().items(Joi.string().optional()),
superBlock: Joi.string(),
superOrder: Joi.number(),
@ -67,14 +66,7 @@ const schema = Joi.object().keys({
),
template: Joi.string(),
time: Joi.string().allow(''),
title: Joi.string().required(),
translations: Joi.object().pattern(
/\w+(-\w+)*/,
Joi.object().keys({
title: Joi.string(),
description: Joi.array().items(Joi.string().allow(''))
})
)
title: Joi.string().required()
});
exports.validateChallenge = function validateChallenge(challenge) {

View File

@ -3,13 +3,12 @@ import fs from 'fs-extra';
import path from 'path';
import browserify from 'browserify';
import getChallenges from './getChallenges';
import {UnpackedChallenge, ChallengeFile} from './unpackedChallenge';
import { UnpackedChallenge, ChallengeFile } from './unpackedChallenge';
// Unpack all challenges
// from all seed/challenges/00-foo/bar.json files
// into seed/unpacked/00-foo/bar/000-id.html files
//
// todo: unpack translations too
// todo: use common/app/routes/Challenges/utils/index.js:15 maps
// to determine format/style for non-JS tests
// todo: figure out embedded images etc. served from elsewhere in the project
@ -19,7 +18,7 @@ let unpackedDir = path.join(__dirname, 'unpacked');
// bundle up the test-running JS
function createUnpackedBundle() {
fs.mkdirp(unpackedDir, (err) => {
fs.mkdirp(unpackedDir, err => {
if (err && err.code !== 'EEXIST') {
console.log(err);
throw err;
@ -28,8 +27,7 @@ function createUnpackedBundle() {
let unpackedFile = path.join(__dirname, 'unpacked.js');
let b = browserify(unpackedFile).bundle();
b.on('error', console.error);
let unpackedBundleFile =
path.join(unpackedDir, 'unpacked-bundle.js');
let unpackedBundleFile = path.join(unpackedDir, 'unpacked-bundle.js');
const bundleFileStream = fs.createWriteStream(unpackedBundleFile);
bundleFileStream.on('finish', () => {
console.log('Wrote bundled JS into ' + unpackedBundleFile);
@ -50,8 +48,9 @@ async function cleanUnpackedDir(unpackedChallengeBlockDir) {
filePath = path.join(unpackedChallengeBlockDir, filePath);
return new Promise(() => fs.unlink(filePath));
};
let promises = fs.readdirSync(unpackedChallengeBlockDir)
.filter(filePath => (/\.html$/i).test(filePath))
let promises = fs
.readdirSync(unpackedChallengeBlockDir)
.filter(filePath => /\.html$/i.test(filePath))
.map(promiseToDelete);
await Promise.all(promises);
}
@ -64,7 +63,7 @@ function unpackChallengeBlock(challengeBlock) {
challengeBlockPath.name
);
fs.mkdirp(unpackedChallengeBlockDir, (err) => {
fs.mkdirp(unpackedChallengeBlockDir, err => {
if (err && err.code !== 'EEXIST') {
console.log(err);
throw err;
@ -83,11 +82,11 @@ function unpackChallengeBlock(challengeBlock) {
delete challengeBlock.fileName;
delete challengeBlock.superBlock;
delete challengeBlock.superOrder;
let challengeBlockCopy =
new ChallengeFile(
unpackedChallengeBlockDir,
challengeBlockPath.name,
'.json');
let challengeBlockCopy = new ChallengeFile(
unpackedChallengeBlockDir,
challengeBlockPath.name,
'.json'
);
challengeBlockCopy.write(JSON.stringify(challengeBlock, null, 2));
// unpack each challenge into an HTML file
@ -104,7 +103,7 @@ function unpackChallengeBlock(challengeBlock) {
}
createUnpackedBundle();
let challenges = getChallenges();
let challenges = getChallenges(null, true);
challenges.forEach(challengeBlock => {
unpackChallengeBlock(challengeBlock);
});

View File

@ -357,14 +357,6 @@ class UnpackedChallenge {
text.push('<!--end-->');
text.push('</div>');
text.push('');
text.push('<h2>Released On</h2>');
text.push('<div class="unpacked">');
text.push('<!--releasedOn-->');
text.push(this.challenge.releasedOn);
text.push('<!--end-->');
text.push('</div>');
text.push('');
text.push('<h2>Files</h2>');
text.push(`