2020-08-25 02:35:46 -07:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
|
2020-08-27 18:57:51 -07:00
|
|
|
const {
|
|
|
|
reorderSteps,
|
|
|
|
createStepFile,
|
|
|
|
getChallengeSeed,
|
|
|
|
getProjectPath
|
|
|
|
} = require('./utils');
|
2020-08-25 02:35:46 -07:00
|
|
|
|
|
|
|
const getLastStepFileContent = () => {
|
|
|
|
const filesArr = [];
|
|
|
|
fs.readdirSync(projectPath).forEach(fileName => {
|
|
|
|
if (
|
|
|
|
path.extname(fileName).toLowerCase() === '.md' &&
|
|
|
|
!fileName.endsWith('final.md')
|
|
|
|
) {
|
|
|
|
filesArr.push(fileName);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const fileName = filesArr[filesArr.length - 1];
|
|
|
|
let lastStepFileNum = fileName.split('.')[0].split('-')[1];
|
|
|
|
lastStepFileNum = parseInt(lastStepFileNum, 10);
|
|
|
|
if (filesArr.length !== lastStepFileNum) {
|
|
|
|
throw `Error: The last file step is ${lastStepFileNum} and there are ${filesArr.length} files.`;
|
|
|
|
}
|
2020-08-27 18:57:51 -07:00
|
|
|
|
2020-08-25 02:35:46 -07:00
|
|
|
return {
|
|
|
|
nextStepNum: lastStepFileNum + 1,
|
2020-08-27 18:57:51 -07:00
|
|
|
challengeSeed: getChallengeSeed(projectPath + fileName)
|
2020-08-25 02:35:46 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-08-27 18:57:51 -07:00
|
|
|
const projectPath = getProjectPath();
|
2020-08-25 02:35:46 -07:00
|
|
|
|
|
|
|
const { nextStepNum, challengeSeed } = getLastStepFileContent();
|
|
|
|
|
|
|
|
createStepFile({ stepNum: nextStepNum, projectPath, challengeSeed });
|
|
|
|
console.log(`Sucessfully added step #${nextStepNum}`);
|
|
|
|
reorderSteps();
|