Skip to content

Commit

Permalink
fix(schema): change schema and unpack script
Browse files Browse the repository at this point in the history
  • Loading branch information
scissorsneedfoodtoo authored and raisedadead committed Sep 20, 2018
1 parent 0db6aeb commit b014b23
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 32 deletions.
7 changes: 6 additions & 1 deletion getChallenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand All @@ -63,6 +66,8 @@ module.exports = function getChallenges(challengesDir) {
'react',
'reactRedux',
'redux',
'releasedOn',
unpackFlag ? undefined : 'translations',
'type'
])
);
Expand Down
10 changes: 1 addition & 9 deletions schema/challengeSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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) {
Expand Down
27 changes: 13 additions & 14 deletions unpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
}
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -104,7 +103,7 @@ function unpackChallengeBlock(challengeBlock) {
}

createUnpackedBundle();
let challenges = getChallenges();
let challenges = getChallenges(null, true);
challenges.forEach(challengeBlock => {
unpackChallengeBlock(challengeBlock);
});
8 changes: 0 additions & 8 deletions unpackedChallenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand Down

0 comments on commit b014b23

Please sign in to comment.