From b014b234042c8573660d1cb72ab105d2eeea819c Mon Sep 17 00:00:00 2001 From: Kristofer Koishigawa Date: Thu, 20 Sep 2018 22:24:45 +0900 Subject: [PATCH] fix(schema): change schema and unpack script --- getChallenges.js | 7 ++++++- schema/challengeSchema.js | 10 +--------- unpack.js | 27 +++++++++++++-------------- unpackedChallenge.js | 8 -------- 4 files changed, 20 insertions(+), 32 deletions(-) diff --git a/getChallenges.js b/getChallenges.js index b150e2d36..47d456c45 100644 --- a/getChallenges.js +++ b/getChallenges.js @@ -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' ]) ); diff --git a/schema/challengeSchema.js b/schema/challengeSchema.js index de96a6157..fede5e463 100644 --- a/schema/challengeSchema.js +++ b/schema/challengeSchema.js @@ -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) { diff --git a/unpack.js b/unpack.js index 4f3e460ff..5b0471a33 100644 --- a/unpack.js +++ b/unpack.js @@ -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); }); diff --git a/unpackedChallenge.js b/unpackedChallenge.js index ffa59af92..6936d2c85 100644 --- a/unpackedChallenge.js +++ b/unpackedChallenge.js @@ -357,14 +357,6 @@ class UnpackedChallenge { text.push(''); text.push(''); - text.push(''); - text.push('

Released On

'); - text.push('
'); - text.push(''); - text.push(this.challenge.releasedOn); - text.push(''); - text.push('
'); - text.push(''); text.push('

Files

'); text.push(`