-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-day.ts
30 lines (27 loc) · 847 Bytes
/
run-day.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import fs from "fs";
import { getDirname } from "./dirname-util.ts";
const { __dirname } = getDirname(import.meta.url);
const dirs = fs
.readdirSync(__dirname)
.filter((file) => fs.statSync(file).isDirectory())
.sort();
// find the day specified in the command line (if supplied)
if (process.argv.length > 2) {
const dir = dirs.find(
(file) =>
file === process.argv[2] || file.startsWith(`day${process.argv[2]}`) || file.startsWith(`day0${process.argv[2]}`),
);
if (dir) {
import(`./${dir}/index.ts`);
} else {
console.log(`Day ${process.argv[2]} not found`);
}
} else {
//find all dirs that start with day
const dayDirs = dirs.filter((file) => file.startsWith("day"));
if (dayDirs.length) {
import(`./${dayDirs[dayDirs.length - 1]}/index.ts`);
} else {
console.log("No day dirs found");
}
}