From 5bc3e15e3aaeec9baf4db4a44314d6150874b658 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Wed, 20 May 2020 16:00:08 +0200 Subject: [PATCH] fix(client): DRY out challenge sourcing Also handles file changes the same way as the original sourcing. --- .../plugins/fcc-source-challenges/gatsby-node.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/client/plugins/fcc-source-challenges/gatsby-node.js b/client/plugins/fcc-source-challenges/gatsby-node.js index 388b3f7164..9aa432d8fe 100644 --- a/client/plugins/fcc-source-challenges/gatsby-node.js +++ b/client/plugins/fcc-source-challenges/gatsby-node.js @@ -41,9 +41,8 @@ exports.sourceNodes = function sourceChallengesSourceNodes( File changed at ${filePath}, replacing challengeNode id ${challenge.id} ` ); - return createChallengeNode(challenge, reporter); + createVisibleChallenge(challenge); }) - .then(createNode) .catch(e => reporter.error(`fcc-replace-challenge @@ -58,12 +57,7 @@ File changed at ${filePath}, replacing challengeNode id ${challenge.id} return source() .then(challenges => Promise.all(challenges)) .then(challenges => - challenges - .filter( - challenge => challenge.superBlock.toLowerCase() !== 'certificates' - ) - .map(challenge => createChallengeNode(challenge, reporter)) - .map(node => createNode(node)) + challenges.map(challenge => createVisibleChallenge(challenge)) ) .catch(e => reporter.panic(`fcc-source-challenges @@ -74,6 +68,11 @@ File changed at ${filePath}, replacing challengeNode id ${challenge.id} ); } + function createVisibleChallenge(challenge) { + if (challenge.superBlock.toLowerCase() === 'certificates') return; + createNode(createChallengeNode(challenge, reporter)); + } + return new Promise((resolve, reject) => { watcher.on('ready', () => sourceAndCreateNodes().then(resolve, reject)); });