feat: update challenge helpers to handle id filenames (#44769)
* refactor: light tweaks for readability * refactor: simplify metadata functions * fix: most tests * test: fix utils tests * test: simplify mocks * WIP: update get-last-step-file-content * feat: finish create-next-step * fix: type error * test: provide mock meta.json for test * refactor: get meta path from project path * refactor: get project name from path * refactor: simplify getProjectMetaPath further Also removes some excessive mocking * refactor: remove more mocks, always clear .env * feat: update create-next-step * feat: update create-empty steps Also refactors slightly, so it's easier to insert steps into the meta * docs: update challenge-helper-script docs * feat: create-step-between * refactor: allow metadata parse errors to propagate * fix: convert reorderSteps to renameSteps * refactor: create-step-between -> insert-step * feat: update delete-step * refactor: consolidate commands into commands.ts * refactor: clean up and consolidation * refactor: more cleanup * fix: make cli args consistent Everything accepts a single integer and nothing else * refactor: renameSteps -> updateStepTitles * docs: update with the names and args * feat: add step validating meta + files are synced
This commit is contained in:
committed by
GitHub
parent
16e7cdedb1
commit
339c6713d2
@ -1,38 +1,6 @@
|
||||
import { getArgValues } from './helpers/get-arg-values';
|
||||
import { getExistingStepNums } from './helpers/get-existing-step-nums';
|
||||
import { getProjectPath } from './helpers/get-project-path';
|
||||
import { createStepFile, reorderSteps } from './utils';
|
||||
import { getArgValue } from './helpers/get-arg-value';
|
||||
import { createEmptySteps } from './commands';
|
||||
import { validateMetaData } from './helpers/project-metadata';
|
||||
|
||||
const anyStepExists = (steps: number[], stepsToFind: number[]) =>
|
||||
stepsToFind.some(num => steps.includes(num));
|
||||
|
||||
const projectPath = getProjectPath();
|
||||
const args = getArgValues(process.argv);
|
||||
|
||||
const { num: numString, start: startString } = args;
|
||||
if (!startString) {
|
||||
throw `No steps created. start arg val must be specified.`;
|
||||
}
|
||||
if (!numString) {
|
||||
throw `No steps created. num arg val must be specified.`;
|
||||
}
|
||||
const num = parseInt(numString, 10);
|
||||
const stepStart = parseInt(startString, 10);
|
||||
|
||||
if (num < 1 || num > 1000) {
|
||||
throw `No steps created. arg 'num' must be between 1 and 1000 inclusive`;
|
||||
}
|
||||
|
||||
const maxStepNum = stepStart + num - 1;
|
||||
|
||||
const existingSteps = getExistingStepNums(projectPath);
|
||||
|
||||
if (anyStepExists(existingSteps, [stepStart, maxStepNum])) {
|
||||
throw `Step not created. At least one of the steps specified between ${startString} and ${maxStepNum} already exists.`;
|
||||
}
|
||||
|
||||
for (let stepNum = stepStart; stepNum <= maxStepNum; stepNum++) {
|
||||
createStepFile({ stepNum, projectPath });
|
||||
}
|
||||
console.log(`Sucessfully added ${numString} steps`);
|
||||
reorderSteps();
|
||||
validateMetaData();
|
||||
createEmptySteps(getArgValue(process.argv));
|
||||
|
Reference in New Issue
Block a user