-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstart_all.js
68 lines (54 loc) · 2.74 KB
/
start_all.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import fs from "node:fs";
import path from "node:path";
import { execSync } from "node:child_process";
import { fileURLToPath } from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// ========================= //
// = Copyright (c) NullDev = //
// ========================= //
/* eslint-disable curly */
let YEARS = [process.argv[2]].filter(e => !!e);
let DAY = process.argv[3] || "";
if (YEARS[0] === "today"){
YEARS = [String(new Date().getFullYear())];
DAY = String(new Date().getDate());
}
if (!YEARS.length) YEARS = fs.readdirSync(__dirname, { withFileTypes: true })
.filter(d => d.isDirectory() && d.name.startsWith("2"))
.map(d => d.name);
const BC = "\x1b[42m\x1b[30m ✓ \x1b[0m\x1b[32m ";
const MC = "\x1b[32m - \x1b[0m(took ";
YEARS.forEach(y => {
console.log(`\n\x1b[32m █████╗ ██████╗ ██████╗
██╔══██╗██╔═══██╗██╔════╝
███████║██║ ██║██║
██╔══██║██║ ██║██║
██║ ██║╚██████╔╝╚██████╗
╚═╝ ╚═╝ ╚═════╝ ╚═════╝
\x1b[33m -----------------------------\n ---= \x1b[36mAdvent of Code ${y}\x1b[33m =---
-----------------------------\x1b[0m\n`,
);
const dirs = fs.readdirSync(path.join(__dirname, y), { withFileTypes: true })
.filter(dirEnt => dirEnt.isDirectory() && String(dirEnt.name).toLowerCase().includes("day_"))
.map(dirEnt => dirEnt.name);
const DIRECTORIES = !!DAY
? dirs.filter(d => {
const dayNum = Number(d.replace("Day_", ""));
return dayNum === Number(DAY);
})
: dirs;
DIRECTORIES.forEach(element => {
const day = element.replace("Day_", "");
const PART1 = path.join(__dirname, y, element, "part_1.js");
const PART2 = path.join(__dirname, y, element, "part_2.js");
console.log(`\x1b[36m---====[ DAY ${day} ]====---\x1b[0m\n`);
const part1Out = fs.existsSync(PART1)
? String(execSync("node " + PART1 + " t", { stdio: "pipe" })).split("\n").filter(e => !!e)
: ["PART 1 NOT IMPLEMENTED YET", 0];
const part2Out = fs.existsSync(PART2)
? String(execSync("node " + PART2 + " t", { stdio: "pipe" })).split("\n").filter(e => !!e)
: ["PART 2 NOT IMPLEMENTED YET", 0];
console.log(`${BC}PART 1: \x1b[0m${String(part1Out[0]).replace(/\r?\n|\r/g, "")}${MC}\x1b[32m${Number(part1Out[1]).toFixed(4)}\x1b[0m ms)`);
console.log(`${BC}PART 2: \x1b[0m${String(part2Out[0]).replace(/\r?\n|\r/g, "")}${MC}\x1b[32m${Number(part2Out[1]).toFixed(4)}\x1b[0m ms)\n`);
});
});