chore: implement init on cli and init day 2

This commit is contained in:
2023-12-02 10:39:25 +01:00
parent 29a5fa493b
commit 33cc4cf464
5 changed files with 21 additions and 8 deletions

View File

@@ -6,10 +6,14 @@ To install dependencies:
bun install bun install
``` ```
To run: To get the input file:
```bash ```bash
bun run index.ts bun run cli input 1
``` ```
This project was created using `bun init` in bun v1.0.2. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. To run files:
```bash
bun run cli run 1 -p 2
```

View File

@@ -1,4 +1,4 @@
import { readdir } from "fs/promises"; import { readdir, mkdir } from "fs/promises";
import * as commander from 'commander'; import * as commander from 'commander';
import logger from "./util/logger.ts"; import logger from "./util/logger.ts";
@@ -31,5 +31,14 @@ program
await Bun.write(`./src/days/${day}/input.txt`, input); await Bun.write(`./src/days/${day}/input.txt`, input);
logger('success', `Fetched input for day ${day}`); logger('success', `Fetched input for day ${day}`);
}); });
program
.command('init <day>')
.description('Initializes a new day')
.action(async (day) => {
await mkdir(`./src/days/${day}`);
await Bun.write(`./src/days/${day}/1.ts`, `import getInput from '../../util/getInput.js';\n\n`);
await Bun.write(`./src/days/${day}/2.ts`, `import getInput from '../../util/getInput.js';\n\n`);
logger('success', `Initialized day ${day}! Happy hacking!`)
});
program.parse(process.argv); program.parse(process.argv);

View File

@@ -1,9 +1,6 @@
import getInput from "../../util/getInput.ts" import getInput from "../../util/getInput.ts"
// REALLY UNCLEAN CODE BUT IT WORKS
const regex = /\D/g const regex = /\D/g
const array: Array<number> = [] const array: Array<number> = []
let file = await getInput(1) let file = await getInput(1)
file = file.replaceAll("twone", "21") file = file.replaceAll("twone", "21")
file = file.replaceAll("sevenine", "79") file = file.replaceAll("sevenine", "79")
@@ -23,7 +20,6 @@ file = file.replaceAll("seven", "7")
file = file.replaceAll("eight", "8") file = file.replaceAll("eight", "8")
file = file.replaceAll("nine", "9") file = file.replaceAll("nine", "9")
const fileSplit = file.split("\n"); const fileSplit = file.split("\n");
fileSplit.forEach((line) => { fileSplit.forEach((line) => {
let arr = Array.from(line.replace(regex, '')).map(Number) let arr = Array.from(line.replace(regex, '')).map(Number)
if (arr.length === 0) return if (arr.length === 0) return

2
2023/src/days/2/1.ts Normal file
View File

@@ -0,0 +1,2 @@
import getInput from '../../util/getInput.js';

2
2023/src/days/2/2.ts Normal file
View File

@@ -0,0 +1,2 @@
import getInput from '../../util/getInput.js';