feat(learn): Create tool to delete an existing project step in project-based curriculum (#39786)
* feat: created tool to delete step * docs: update README.md with delete-step instructions Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
35
tools/challenge-helper-scripts/delete-step.js
Normal file
35
tools/challenge-helper-scripts/delete-step.js
Normal file
@ -0,0 +1,35 @@
|
||||
const fs = require('fs');
|
||||
|
||||
const {
|
||||
reorderSteps,
|
||||
padWithLeadingZeros,
|
||||
getExistingStepNums,
|
||||
getProjectPath,
|
||||
getArgValues
|
||||
} = require('./utils');
|
||||
|
||||
const stepExists = (steps, stepToFind) => steps.includes(stepToFind);
|
||||
|
||||
const projectPath = getProjectPath();
|
||||
const args = getArgValues(process.argv);
|
||||
|
||||
let { num } = args;
|
||||
num = parseInt(num, 10);
|
||||
|
||||
if (!Number.isInteger(num) || num < 1) {
|
||||
throw 'Step not deleted. Step num must be a number greater than 0.';
|
||||
}
|
||||
|
||||
const existingSteps = getExistingStepNums(projectPath);
|
||||
if (!stepExists(existingSteps, num)) {
|
||||
throw `Step # ${num} not deleted because it does not exist.`;
|
||||
}
|
||||
|
||||
const stepFileToDelete = `${projectPath}part-${padWithLeadingZeros(num)}.md`;
|
||||
try {
|
||||
fs.unlinkSync(stepFileToDelete);
|
||||
console.log(`Sucessfully deleted step #${num}`);
|
||||
reorderSteps();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
Reference in New Issue
Block a user