Skip to content

Commit

Permalink
day02 and updating generator
Browse files Browse the repository at this point in the history
  • Loading branch information
TimHi committed Dec 1, 2023
1 parent 25df1b4 commit 48b7251
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Typescript/2023/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export function SolvePartTwo(): number {

const createTypeScriptFile = (day) => {
const renderedTemplate = nunjucks.renderString(dayTemplate, { day: day }); // Pass day as an object with key 'day'
const filename = path.join("src", `day${day}`, `day${day}.ts`);
const filename = path.join("src", "days", `day${day}`, `day${day}.ts`);
console.log(filename);
fs.writeFileSync(filename, renderedTemplate);
console.log(`Created TypeScript file: day${day}.ts`);
};

const createTestFile = (day) => {
const testTemplate = `
import { SolvePartOne, SolvePartTwo } from "../day{{ day }}";
import { SolvePartOne, SolvePartTwo } from "../day{{ day }}/day{{ day }}";
import { describe, expect, test } from "vitest";
describe("Day {{ day }} Part 01", () => {
Expand Down Expand Up @@ -58,7 +58,9 @@ describe("Day {{ day }} Part 02", () => {

const createDirectories = (filename) => {
const dir = path.dirname(filename);
console.log("Dir: " + dir);
if (!fs.existsSync(dir)) {
console.log("Does not exist");
fs.mkdirSync(dir, { recursive: true });
}
};
Expand All @@ -72,9 +74,12 @@ if (args.length < 1) {
}

const dayValue = args[0];
const folderPath = path.join("src", "days", `day${dayValue}`, `day${dayValue}.ts`);

createDirectories(path.join("src", "days", `${dayValue}`));
createDirectories(folderPath);
createDirectories(path.join("src", "days", "__test__", `${dayValue}.test.ts`));

createTypeScriptFile(dayValue);
createTestFile(dayValue);
fs.writeFileSync(path.join("src", "days", `day${dayValue}`, `full.txt`), "");
fs.writeFileSync(path.join("src", "days", `day${dayValue}`, `sample.txt`), "");
15 changes: 15 additions & 0 deletions Typescript/2023/src/days/__test__/day02.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

import { SolvePartOne, SolvePartTwo } from "../day02/day02";
import { describe, expect, test } from "vitest";

describe("Day 02 Part 01", () => {
test("Expected result", () => {
expect(SolvePartOne()).toBe(-1);
});
});

describe("Day 02 Part 02", () => {
test("Expected result", () => {
expect(SolvePartTwo()).toBe(-1);
});
});
14 changes: 14 additions & 0 deletions Typescript/2023/src/days/day02/day02.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

/// AOC 2023 Day 02
console.log("Day 02 Part 01:" + SolvePartOne());
console.log("Day 02 Part 02:" + SolvePartTwo());

export function SolvePartOne(): number {
console.log("TBD");
return 0;
}

export function SolvePartTwo(): number {
console.log("TBD");
return 0;
}
Empty file.

0 comments on commit 48b7251

Please sign in to comment.