feat: refactor and test tools steps utilities (#42693)

This commit is contained in:
Victor Duarte
2021-07-06 19:22:12 -05:00
committed by GitHub
parent 9e883e49ba
commit 82d09bd593
36 changed files with 855 additions and 207 deletions

View File

@ -1,39 +1,10 @@
const fs = require('fs');
const path = require('path');
const { getProjectPath } = require('./helpers/get-project-path');
const {
reorderSteps,
createStepFile,
getChallengeSeeds,
getProjectPath
} = require('./utils');
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.`;
}
return {
nextStepNum: lastStepFileNum + 1,
challengeSeeds: getChallengeSeeds(projectPath + fileName)
};
};
getLastStepFileContent
} = require('./helpers/get-last-step-file-content');
const { reorderSteps, createStepFile } = require('./utils');
const projectPath = getProjectPath();
const { nextStepNum, challengeSeeds } = getLastStepFileContent();
createStepFile({ stepNum: nextStepNum, projectPath, challengeSeeds });