-
Notifications
You must be signed in to change notification settings - Fork 4
/
run.mjs
49 lines (41 loc) · 1.29 KB
/
run.mjs
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
import fs from "fs";
import path from "path";
import { ABAP } from "@abaplint/runtime";
async function run() {
const day = process.argv[2];
console.log("# Day " + day);
const files = fs
.readdirSync("output")
.filter((n) => n.includes("day" + day) && n.endsWith(".clas.mjs"));
if (files.length !== 1) {
throw "Class not found for this day";
}
const abap = new ABAP();
global.abap = abap;
const clas = await import("." + path.sep + "output" + path.sep + files[0]);
const inputFile = "." + path.sep + "input" + path.sep + "day" + day + ".txt";
const input = fs.readFileSync(inputFile).toString();
const className = Object.keys(clas)[0];
const instance = new clas[className]();
const methodName = Object.getOwnPropertyNames(
clas[className].prototype
).filter((m) => m.endsWith("$solve"))[0];
console.log("Class: " + className.toUpperCase());
console.log("Method: " + methodName.toUpperCase());
console.log("Input: " + inputFile);
const result = await instance[methodName]({ input: input });
const output = abap.console.get();
if (output && output !== "") {
console.dir(output);
}
console.log("\nResult:");
console.log(result);
}
run()
.then(() => {
process.exit();
})
.catch((err) => {
console.log(err);
process.exit(1);
});