* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
const readdirp = require('readdirp');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { getText } = require('./get-challenge-text');
|
|
const { challengeToString } = require('./create-challenge-string');
|
|
const { parseMD } = require('../../challenge-md-parser/mdx');
|
|
|
|
const challengeDir = '../../../curriculum/challenges/';
|
|
const enChalDir = path.resolve(__dirname, challengeDir, 'english');
|
|
const cnChalDir = path.resolve(__dirname, challengeDir, 'chinese');
|
|
|
|
module.exports.restore = async function restore(filePath) {
|
|
return generateTranscribableChallenge(filePath)
|
|
.then(challengeToString)
|
|
.catch(err => {
|
|
console.log('Error transforming');
|
|
console.log(filePath);
|
|
console.log(err);
|
|
});
|
|
};
|
|
|
|
async function generateTranscribableChallenge(filePath) {
|
|
const cnFullPath = path.resolve(cnChalDir, filePath);
|
|
const enFullPath = path.resolve(enChalDir, filePath);
|
|
const cnChal = await Promise.all([
|
|
parseMD(cnFullPath),
|
|
getText(cnFullPath)
|
|
]).then(results => ({
|
|
...results[0],
|
|
...results[1]
|
|
}));
|
|
const engChal = await parseMD(enFullPath);
|
|
return {
|
|
...cnChal,
|
|
files: engChal.files,
|
|
solutions: engChal.solutions,
|
|
dashedName: engChal.dashedName
|
|
};
|
|
}
|
|
|
|
readdirp(cnChalDir, { fileFilter: ['*.md'], type: 'files' }).on(
|
|
'data',
|
|
({ path: filePath }) => {
|
|
const cnFullPath = path.resolve(cnChalDir, filePath);
|
|
module.exports
|
|
.restore(filePath)
|
|
.then(text => fs.writeFileSync(cnFullPath, text))
|
|
.catch(e => {
|
|
console.log(filePath);
|
|
console.log(e);
|
|
});
|
|
}
|
|
);
|