* feat: allow more 1000 steps to be created at once * refactor: start migrating to typescript * refactor: delete-step to ts * refactor: migrated some helpers * refactor: migrate create-empty-steps * refactor: migrate create-step-between * refactor: finish migrating to TS * refactor: migrate tests * fix: ensure mock.restore is done after each test * fix: prevent double-tscing * fix: repair the tests * chore: use ts-node for scripts We don't need the performance boost of incremental compilation and ts-node is easier to work with * refactor: consolidate tsconfigs * refactor: replace gulp * fix: use ts-node for build-curriculum * fix: allow ts compilation of config * feat: create and use create:config script * fix: add /config to eslint projects * fix: remove gulp script
31 lines
894 B
TypeScript
31 lines
894 B
TypeScript
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
// Generates an array with the output of processing filenames with an expected
|
|
// format (`step-###.md`).
|
|
// ['step-001.md', 'step-002.md'] => [1, 2]
|
|
function getExistingStepNums(projectPath: string): number[] {
|
|
return fs.readdirSync(projectPath).reduce((stepNums, fileName) => {
|
|
if (
|
|
path.extname(fileName).toLowerCase() === '.md' &&
|
|
!fileName.endsWith('final.md')
|
|
) {
|
|
const stepNumString = fileName.split('.')[0].split('-')[1];
|
|
|
|
if (!/^\d{3}$/.test(stepNumString)) {
|
|
throw (
|
|
`Step not created. File ${fileName} has a step number containing non-digits.` +
|
|
' Please run reorder-steps script first.'
|
|
);
|
|
}
|
|
|
|
const stepNum = parseInt(stepNumString, 10);
|
|
stepNums.push(stepNum);
|
|
}
|
|
|
|
return stepNums;
|
|
}, [] as number[]);
|
|
}
|
|
|
|
export { getExistingStepNums };
|