forked from johnbeech/advent-of-code-nodejs-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.ts
37 lines (33 loc) · 832 Bytes
/
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
const solutionId = process.argv[2];
import fs from "fs";
const runSolution = (day) =>
require(`./solutions/${solutionId}/solution.ts`).run(day);
const copyCodeTemplate = async () => {
try {
await require("./copy-template.ts");
await runSolution(solutionId);
} catch (ex) {
console.error(
`Unable to run solution for '${solutionId}': ${ex}`,
ex.stack
);
}
};
const start = async () => {
try {
if (fs.existsSync(`./solutions/${solutionId}/solution.ts`)) {
await runSolution(solutionId);
} else {
await copyCodeTemplate();
}
} catch (ex) {
if (!solutionId) {
console.error(
"No solution ID provided; please re-run with an argument, e.g.: npm start day1, or: node run day1"
);
} else {
await copyCodeTemplate();
}
}
};
start();