chore(learn): Merge learn in to the client app
This commit is contained in:
@ -0,0 +1,38 @@
|
||||
const crypto = require('crypto');
|
||||
|
||||
function createChallengeNodes(challenge, reporter) {
|
||||
if (typeof challenge.description[0] !== 'string') {
|
||||
reporter.warn(`
|
||||
|
||||
${challenge.title} has a description that will break things!
|
||||
|
||||
`);
|
||||
}
|
||||
const contentDigest = crypto
|
||||
.createHash('md5')
|
||||
.update(JSON.stringify(challenge))
|
||||
.digest('hex');
|
||||
const internal = {
|
||||
contentDigest,
|
||||
type: 'ChallengeNode'
|
||||
};
|
||||
|
||||
/* eslint-disable prefer-object-spread/prefer-object-spread */
|
||||
return JSON.parse(
|
||||
JSON.stringify(
|
||||
Object.assign(
|
||||
{},
|
||||
{
|
||||
id: challenge.id + ' >>>> ChallengeNode',
|
||||
children: [],
|
||||
parent: null,
|
||||
internal,
|
||||
sourceInstanceName: 'challenge'
|
||||
},
|
||||
challenge
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
exports.createChallengeNodes = createChallengeNodes;
|
27
client/plugins/fcc-source-challenges/gatsby-node.js
Normal file
27
client/plugins/fcc-source-challenges/gatsby-node.js
Normal file
@ -0,0 +1,27 @@
|
||||
const { createChallengeNodes } = require('./create-Challenge-nodes');
|
||||
|
||||
exports.sourceNodes = ({ actions, reporter }, pluginOptions) => {
|
||||
if (typeof pluginOptions.source !== 'function') {
|
||||
reporter.panic(`
|
||||
"source" is a required option for fcc-source-challenges. It must be a function
|
||||
that delivers challenge files to the plugin
|
||||
`);
|
||||
}
|
||||
// TODO: Add live seed updates
|
||||
const { createNode } = actions;
|
||||
|
||||
const { source } = pluginOptions;
|
||||
return source().subscribe(
|
||||
challenges =>
|
||||
challenges
|
||||
.filter(challenge => challenge.superBlock !== 'Certificates')
|
||||
.map(challenge => createChallengeNodes(challenge, reporter))
|
||||
.map(node => createNode(node)),
|
||||
e =>
|
||||
reporter.panic(`fcc-sourec-challenges
|
||||
|
||||
${e.message}
|
||||
|
||||
`)
|
||||
);
|
||||
};
|
1
client/plugins/fcc-source-challenges/package.json
Normal file
1
client/plugins/fcc-source-challenges/package.json
Normal file
@ -0,0 +1 @@
|
||||
{"name": "fcc-source-challenges"}
|
Reference in New Issue
Block a user