freeCodeCamp/curriculum/tools/create-empty-steps.js
Randell Dawson 7565849d7d feat(learn): Added project-based curriculum tools (#39448)
* feat: added project-based curriculum tools

* fix: allow script to work /w or /wo npm run

* fix: moved console.log to reorder-steps function

* fix: integrated bson-objectid library
2020-09-16 11:54:12 +05:30

31 lines
873 B
JavaScript

const path = require('path');
const { reorderSteps, createStepFile } = require('./utils');
const projectPath = (process.env.CALLING_DIR || process.cwd()) + path.sep;
const argValuePairs = process.argv.slice(2);
const args = argValuePairs.reduce((argsObj, arg) => {
const [argument, value] = arg.replace(/\s/g, '').split('=');
if (!argument || !value) {
throw `Invalid argument/value specified: ${arg}`;
}
return { ...argsObj, [argument]: value };
}, {});
let { num, start } = args;
num = parseInt(num, 10);
const stepStart = parseInt(start, 10);
if (num > 20) {
throw 'No steps created. num arg val must be less than or equal to 20.';
}
const maxStepNum = stepStart + num - 1;
for (let stepNum = stepStart; stepNum <= maxStepNum; stepNum++) {
createStepFile({ stepNum, projectPath });
}
console.log(`Sucessfully added ${num} steps`);
reorderSteps();