generated from MJGTwo/advent-of-code-nodets-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.ts
39 lines (34 loc) · 897 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
38
39
import { copyTemplate } from './copy-template.ts'
const solutionId = process.argv[2];
import fs from "fs";
const runSolution = (day) =>
import(`./solutions/${solutionId}/solution.ts`).then((module) => module.run(day));
const copyCodeTemplate = async () => {
try {
await copyTemplate();
await runSolution(solutionId);
} catch (ex: any) {
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();