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

Commit b014b23

Browse files
scissorsneedfoodtooraisedadead
authored andcommitted
fix(schema): change schema and unpack script
1 parent 0db6aeb commit b014b23

File tree

4 files changed

+20
-32
lines changed

4 files changed

+20
-32
lines changed

getChallenges.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ function superblockInfo(filePath) {
4242
}
4343
}
4444

45-
module.exports = function getChallenges(challengesDir) {
45+
// unpackFlag is an argument passed by the unpack script in unpack.js
46+
// which allows us to conditionall omit translations when running
47+
// the test suite and prevent schema related errors in the main fCC branch
48+
module.exports = function getChallenges(challengesDir, unpackFlag) {
4649
if (!challengesDir) {
4750
challengesDir = 'challenges';
4851
}
@@ -63,6 +66,8 @@ module.exports = function getChallenges(challengesDir) {
6366
'react',
6467
'reactRedux',
6568
'redux',
69+
'releasedOn',
70+
unpackFlag ? undefined : 'translations',
6671
'type'
6772
])
6873
);

schema/challengeSchema.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ const schema = Joi.object().keys({
4646
crossDomain: Joi.bool()
4747
})
4848
),
49-
releasedOn: Joi.string().allow(''),
5049
solutions: Joi.array().items(Joi.string().optional()),
5150
superBlock: Joi.string(),
5251
superOrder: Joi.number(),
@@ -67,14 +66,7 @@ const schema = Joi.object().keys({
6766
),
6867
template: Joi.string(),
6968
time: Joi.string().allow(''),
70-
title: Joi.string().required(),
71-
translations: Joi.object().pattern(
72-
/\w+(-\w+)*/,
73-
Joi.object().keys({
74-
title: Joi.string(),
75-
description: Joi.array().items(Joi.string().allow(''))
76-
})
77-
)
69+
title: Joi.string().required()
7870
});
7971

8072
exports.validateChallenge = function validateChallenge(challenge) {

unpack.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import fs from 'fs-extra';
33
import path from 'path';
44
import browserify from 'browserify';
55
import getChallenges from './getChallenges';
6-
import {UnpackedChallenge, ChallengeFile} from './unpackedChallenge';
6+
import { UnpackedChallenge, ChallengeFile } from './unpackedChallenge';
77

88
// Unpack all challenges
99
// from all seed/challenges/00-foo/bar.json files
1010
// into seed/unpacked/00-foo/bar/000-id.html files
1111
//
12-
// todo: unpack translations too
1312
// todo: use common/app/routes/Challenges/utils/index.js:15 maps
1413
// to determine format/style for non-JS tests
1514
// todo: figure out embedded images etc. served from elsewhere in the project
@@ -19,7 +18,7 @@ let unpackedDir = path.join(__dirname, 'unpacked');
1918

2019
// bundle up the test-running JS
2120
function createUnpackedBundle() {
22-
fs.mkdirp(unpackedDir, (err) => {
21+
fs.mkdirp(unpackedDir, err => {
2322
if (err && err.code !== 'EEXIST') {
2423
console.log(err);
2524
throw err;
@@ -28,8 +27,7 @@ function createUnpackedBundle() {
2827
let unpackedFile = path.join(__dirname, 'unpacked.js');
2928
let b = browserify(unpackedFile).bundle();
3029
b.on('error', console.error);
31-
let unpackedBundleFile =
32-
path.join(unpackedDir, 'unpacked-bundle.js');
30+
let unpackedBundleFile = path.join(unpackedDir, 'unpacked-bundle.js');
3331
const bundleFileStream = fs.createWriteStream(unpackedBundleFile);
3432
bundleFileStream.on('finish', () => {
3533
console.log('Wrote bundled JS into ' + unpackedBundleFile);
@@ -50,8 +48,9 @@ async function cleanUnpackedDir(unpackedChallengeBlockDir) {
5048
filePath = path.join(unpackedChallengeBlockDir, filePath);
5149
return new Promise(() => fs.unlink(filePath));
5250
};
53-
let promises = fs.readdirSync(unpackedChallengeBlockDir)
54-
.filter(filePath => (/\.html$/i).test(filePath))
51+
let promises = fs
52+
.readdirSync(unpackedChallengeBlockDir)
53+
.filter(filePath => /\.html$/i.test(filePath))
5554
.map(promiseToDelete);
5655
await Promise.all(promises);
5756
}
@@ -64,7 +63,7 @@ function unpackChallengeBlock(challengeBlock) {
6463
challengeBlockPath.name
6564
);
6665

67-
fs.mkdirp(unpackedChallengeBlockDir, (err) => {
66+
fs.mkdirp(unpackedChallengeBlockDir, err => {
6867
if (err && err.code !== 'EEXIST') {
6968
console.log(err);
7069
throw err;
@@ -83,11 +82,11 @@ function unpackChallengeBlock(challengeBlock) {
8382
delete challengeBlock.fileName;
8483
delete challengeBlock.superBlock;
8584
delete challengeBlock.superOrder;
86-
let challengeBlockCopy =
87-
new ChallengeFile(
88-
unpackedChallengeBlockDir,
89-
challengeBlockPath.name,
90-
'.json');
85+
let challengeBlockCopy = new ChallengeFile(
86+
unpackedChallengeBlockDir,
87+
challengeBlockPath.name,
88+
'.json'
89+
);
9190
challengeBlockCopy.write(JSON.stringify(challengeBlock, null, 2));
9291

9392
// unpack each challenge into an HTML file
@@ -104,7 +103,7 @@ function unpackChallengeBlock(challengeBlock) {
104103
}
105104

106105
createUnpackedBundle();
107-
let challenges = getChallenges();
106+
let challenges = getChallenges(null, true);
108107
challenges.forEach(challengeBlock => {
109108
unpackChallengeBlock(challengeBlock);
110109
});

unpackedChallenge.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,6 @@ class UnpackedChallenge {
357357
text.push('<!--end-->');
358358
text.push('</div>');
359359

360-
text.push('');
361-
text.push('<h2>Released On</h2>');
362-
text.push('<div class="unpacked">');
363-
text.push('<!--releasedOn-->');
364-
text.push(this.challenge.releasedOn);
365-
text.push('<!--end-->');
366-
text.push('</div>');
367-
368360
text.push('');
369361
text.push('<h2>Files</h2>');
370362
text.push(`

0 commit comments

Comments
 (0)