-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathrun.ts
79 lines (68 loc) · 1.8 KB
/
run.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
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
69
70
71
72
73
74
75
76
77
78
79
import * as util from "./util/util";
import path from "path";
import * as LOGUTIL from "./util/log";
import * as TESTUTIL from "./util/test";
import chalk from "chalk";
const { log } = LOGUTIL;
let debug = false;
let help = false;
let noTests = false;
let year: number = 0;
let day: number = 0;
const args = process.argv.slice(2);
for (const arg of args) {
if (arg.trim() === "--debug" || arg.trim() === "-d") {
debug = true;
} else if (arg.trim() === "--help" || arg.trim() === "-h") {
help = true;
} else if (arg.trim() === "--no-test" || arg.trim() === "--no-tests" || arg.trim() === "-n") {
noTests = true;
} else {
const num = Number(arg);
if (Number.isInteger(num)) {
if (num >= 1 && num <= 25) {
day = num;
} else if (num >= 2015 && num < 2100) {
year = num;
} else {
usage();
}
} else {
usage();
}
}
}
if ((year === 0 && day !== 0) || (year !== 0 && day === 0)) {
usage();
}
if (help) {
usage();
}
LOGUTIL.setDebug(debug);
TESTUTIL.setNoTests(noTests);
if (year === 0 && day === 0) {
({ year, day } = util.getLatestPuzzleDate());
}
const puzzleFile = path.join(util.getDayRoot(day, year), "index");
log(chalk`\n== Running puzzle {cyan ${year}.${day}}${debug ? " [Debug ON]" : ""} ==\n`);
require(puzzleFile);
function usage() {
log(`
Runs your solution for the problem for the given <year, day>. If
executed without arguments, it will attempt to run the most
recently-released Advent of Code puzzle.
Usage:
ts-node run.ts [<year> <day>]
Arguments:
year: a 4-digit number greater than or equal to 2015
day: a number between 1 and 25, inclusive
Options:
--help, -h: Show this help message.
--debug, -d: Print debug/trace messages.
--no-tests, -n: Don't run tests.
Examples:
ts-node run.ts
ts-node run.ts 2018 22
`);
process.exit(0);
}