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) { if (!challengesDir) {
challengesDir = 'challenges'; challengesDir = 'challenges';
} }
@ -63,6 +66,8 @@ module.exports = function getChallenges(challengesDir) {
'react', 'react',
'reactRedux', 'reactRedux',
'redux', 'redux',
'releasedOn',
unpackFlag ? undefined : 'translations',
'type' 'type'
]) ])
); );

View File

@ -46,7 +46,6 @@ const schema = Joi.object().keys({
crossDomain: Joi.bool() crossDomain: Joi.bool()
}) })
), ),
releasedOn: Joi.string().allow(''),
solutions: Joi.array().items(Joi.string().optional()), solutions: Joi.array().items(Joi.string().optional()),
superBlock: Joi.string(), superBlock: Joi.string(),
superOrder: Joi.number(), superOrder: Joi.number(),
@ -67,14 +66,7 @@ const schema = Joi.object().keys({
), ),
template: Joi.string(), template: Joi.string(),
time: Joi.string().allow(''), 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) { exports.validateChallenge = function validateChallenge(challenge) {

View File

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

View File

@ -357,14 +357,6 @@ class UnpackedChallenge {
text.push('<!--end-->'); text.push('<!--end-->');
text.push('</div>'); 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('');
text.push('<h2>Files</h2>'); text.push('<h2>Files</h2>');
text.push(` text.push(`