From 0c69ceb612bba35a2228086831144119e0d26a88 Mon Sep 17 00:00:00 2001 From: Alix von Schirp Date: Tue, 11 Nov 2025 03:46:11 +0100 Subject: [PATCH] qol: Allow for testing with testinput.txt --- index.ts | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/index.ts b/index.ts index 88498e2..80b23b7 100644 --- a/index.ts +++ b/index.ts @@ -142,6 +142,80 @@ program runner(`./src/${year}/${day}/input.txt`); }); +program + .command("test [year] [day] [part]") + .description("Run the solution for the specified year and day") + .action(async (year, day, part) => { + if (!year) { + // Get list of years from 2015 to current + const currentYear = new Date().getFullYear(); + const years = []; + for (let y = currentYear; y >= 2015; y--) { + years.push(y.toString()); + } + + //Filter for existing directories + const yearExistenceChecks = await Promise.all( + years.map(async (value) => { + const exists = await existsDir(`src/${value}`); + return { value, exists }; + }), + ); + const fYears = yearExistenceChecks + .filter((item) => item.exists) + .map((item) => item.value); + + // Prompt user to select year + year = await select({ + message: "What year do you want to run?", + choices: fYears, + loop: false, + }); + } + + if (!day) { + // Get list of days from 1 to 25 or 12 depending on year + // Starting 2025 only 12 challenges will be available + const days = []; + for (let d = year < 2025 ? 25 : 12; d >= 1; d--) { + days.push(d.toString()); + } + + // Filter for existing directories + const dayExistenceChecks = await Promise.all( + days.map(async (value) => { + const exists = await existsDir(`src/${year}/${value}`); + return { value, exists }; + }), + ); + const fDays = dayExistenceChecks + .filter((item) => item.exists) + .map((item) => item.value); + + // Prompt user to select day + day = await select({ + message: "What day do you want to run?", + choices: fDays, + loop: false, + }); + } + + if (!part) { + // Prompt user to select part + part = await select({ + message: "What part do you want to run?", + choices: ["1", "2"], + loop: false, + }); + } + + const { default: runner } = await import( + `./src/${year}/${day}/${part}/index.ts` + ); + + runner(`./src/${year}/${day}/testinput.txt`); + }); + program.parse(process.argv); async function existsDir(path: string): Promise {