2022-01-25 11:34:16 +01:00
|
|
|
import fs from 'fs';
|
|
|
|
import { getArgValues } from './helpers/get-arg-values';
|
|
|
|
import { getExistingStepNums } from './helpers/get-existing-step-nums';
|
|
|
|
import { getProjectPath } from './helpers/get-project-path';
|
|
|
|
import { padWithLeadingZeros } from './helpers/pad-with-leading-zeros';
|
|
|
|
import { reorderSteps } from './utils';
|
2020-10-03 02:54:19 -07:00
|
|
|
|
2022-01-25 11:34:16 +01:00
|
|
|
const stepExists = (steps: number[], stepToFind: number) =>
|
|
|
|
steps.includes(stepToFind);
|
2020-10-03 02:54:19 -07:00
|
|
|
|
|
|
|
const projectPath = getProjectPath();
|
|
|
|
const args = getArgValues(process.argv);
|
|
|
|
|
2022-01-25 11:34:16 +01:00
|
|
|
const num = parseInt(args.num, 10);
|
2020-10-03 02:54:19 -07:00
|
|
|
|
|
|
|
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.`;
|
|
|
|
}
|
|
|
|
|
2021-10-21 10:07:52 -07:00
|
|
|
const stepFileToDelete = `${projectPath}step-${padWithLeadingZeros(num)}.md`;
|
2020-10-03 02:54:19 -07:00
|
|
|
try {
|
|
|
|
fs.unlinkSync(stepFileToDelete);
|
|
|
|
console.log(`Sucessfully deleted step #${num}`);
|
|
|
|
reorderSteps();
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|