fix(client): handle challenge creation (#42272)
This lets us create new challenges/steps without having to restart the client
This commit is contained in:
committed by
GitHub
parent
052173e502
commit
1db9a123ae
@ -1,4 +1,6 @@
|
||||
const path = require('path');
|
||||
const chokidar = require('chokidar');
|
||||
const readdirp = require('readdirp');
|
||||
|
||||
const { createChallengeNode } = require('./create-challenge-nodes');
|
||||
|
||||
@ -28,6 +30,7 @@ exports.sourceNodes = function sourceChallengesSourceNodes(
|
||||
const { createNode } = actions;
|
||||
const watcher = chokidar.watch(curriculumPath, {
|
||||
ignored: /(^|[\/\\])\../,
|
||||
ignoreInitial: true,
|
||||
persistent: true,
|
||||
usePolling: true,
|
||||
cwd: curriculumPath
|
||||
@ -55,6 +58,43 @@ File changed at ${filePath}, replacing challengeNode id ${challenge.id}
|
||||
: null
|
||||
);
|
||||
|
||||
// if a file is added, that might change the order of the challenges in the
|
||||
// containing block, so we recreate them all
|
||||
watcher.on('add', filePath => {
|
||||
if (/\.md?$/.test(filePath)) {
|
||||
const blockPath = path.dirname(filePath);
|
||||
const fullBlockPath = path.join(
|
||||
__dirname,
|
||||
'../../../curriculum/challenges/english/',
|
||||
blockPath
|
||||
);
|
||||
readdirp(fullBlockPath, { fileFilter: '*.md' })
|
||||
.on('data', entry => {
|
||||
const { path: siblingPath } = entry;
|
||||
const relativePath = path.join(blockPath, siblingPath);
|
||||
onSourceChange(relativePath)
|
||||
.then(challenge => {
|
||||
reporter.info(
|
||||
`
|
||||
File changed at ${relativePath}, replacing challengeNode id ${challenge.id}
|
||||
`
|
||||
);
|
||||
createVisibleChallenge(challenge);
|
||||
})
|
||||
.catch(e =>
|
||||
reporter.error(`fcc-replace-challenge
|
||||
attempting to replace ${relativePath}
|
||||
|
||||
${e.message}
|
||||
|
||||
`)
|
||||
);
|
||||
})
|
||||
.on('warn', error => console.error('non-fatal error', error))
|
||||
.on('error', error => console.error('fatal error', error));
|
||||
}
|
||||
});
|
||||
|
||||
function sourceAndCreateNodes() {
|
||||
return source()
|
||||
.then(challenges => Promise.all(challenges))
|
||||
|
Reference in New Issue
Block a user