From 704ca26e2c29fc449aeee0341a8f98541a5b952c Mon Sep 17 00:00:00 2001 From: newt Date: Wed, 9 Oct 2024 18:02:41 +0100 Subject: [PATCH] feat(euler): offer to create a thoughts document as well - --- challenges/euler/constants.js | 3 ++- challenges/euler/scripts/generate.js | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/challenges/euler/constants.js b/challenges/euler/constants.js index 094850b..aa596f9 100644 --- a/challenges/euler/constants.js +++ b/challenges/euler/constants.js @@ -2,5 +2,6 @@ const path = require('path'); module.exports = { resources: path.join(__dirname, 'resources'), - src: path.join(__dirname, 'src') + src: path.join(__dirname, 'src'), + thoughts: path.join(__dirname, 'thoughts') }; diff --git a/challenges/euler/scripts/generate.js b/challenges/euler/scripts/generate.js index 9109bc5..95bfb87 100644 --- a/challenges/euler/scripts/generate.js +++ b/challenges/euler/scripts/generate.js @@ -1,7 +1,7 @@ const inquirer = require('inquirer'); const fs = require('fs'); const path = require('path'); -const { src } = require('../constants'); +const { src, thoughts: thoughtsDir } = require('../constants'); const axios = require('axios'); const cheerio = require('cheerio'); @@ -24,10 +24,16 @@ inquirer parseInt(input) > 100 ? 'Please make sure you choose a number between 1 and 100!' : true + }, + { + name: 'thoughts', + message: 'Should I generate a thoughts document for you?', + type: 'confirm', + default: false } ]) - .then(async ({ problemNumber }) => { - const problemName = problems[problemNumber - 1]; + .then(async ({ problemNumber, thoughts }) => { + const fileName = `${problemNumber} - ${problems[problemNumber - 1]}`; // Fetch the problem data off of projecteuler.net axios.get(`https://projecteuler.net/problem=${problemNumber}`).then(({ data }) => { @@ -40,12 +46,14 @@ inquirer .join('\n'); fs.writeFileSync( - path.join(src, `${problemNumber} - ${problemName}.ts`), + path.join(src, `${fileName}.ts`), `${problemContent} export = {}; // Output console.log();` ); + + if (thoughts) fs.writeFileSync(path.join(thoughtsDir, `${fileName}.md`), ''); }); });