feat(euler): allow the challenge name to be passed into the generate command

-
This commit is contained in:
newt 2024-10-09 18:02:42 +01:00
parent bd6470879a
commit caacc47e72

View file

@ -5,6 +5,9 @@ const { root, src, thoughts: thoughtsDir } = require('../constants');
const axios = require('axios');
const cheerio = require('cheerio');
process.argv.shift();
process.argv.shift();
const readmeContent = fs.readFileSync(path.join(root, 'readme.md')).toString();
const problems = readmeContent.match(/^- \[.] (?:\[(.*)\]|(.*))/gm).map(res => {
@ -12,9 +15,10 @@ const problems = readmeContent.match(/^- \[.] (?:\[(.*)\]|(.*))/gm).map(res =>
return sanitised.match(/[0-9]* - (.*)/)[1];
});
inquirer
.prompt([
{
const questions = [];
if (isNaN(process.argv[0]))
questions.push({
name: 'problemNumber',
message: 'Which problem would you like to solve?',
type: 'number',
@ -33,7 +37,11 @@ inquirer
else return true;
}
}
},
});
inquirer
.prompt([
...questions,
{
name: 'thoughts',
message: 'Should I generate a thoughts document for you?',
@ -42,6 +50,7 @@ inquirer
}
])
.then(({ problemNumber, thoughts }) => {
if (!problemNumber) problemNumber = parseInt(process.argv[0]);
const fileName = `${problemNumber} - ${problems[problemNumber - 1]}`;
// Fetch the problem data off of projecteuler.net