-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjdsl.js
48 lines (38 loc) · 1.19 KB
/
jdsl.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
/*
Inspired by the true brilliance of Tom
*/
import { readFileSync } from "fs";
import { spawn } from "child_process";
function cmd(...command) {
let p = spawn(command[0], command.slice(1));
let result = "";
return new Promise((resolveFunc) => {
p.stdout.on("data", (x) => { result += x; });
p.stderr.on("data", (x) => { result += x; });
p.on("exit", (_) => { resolveFunc(result); });
});
}
const delay = (time) => new Promise(resolve => setTimeout(resolve, time));
const loadJSON = (path) => JSON.parse(readFileSync(new URL(path, import.meta.url)));
async function jdslLoad(dsl) {
const jdsl = loadJSON("./" + dsl + ".json");
for (const [key, value] of Object.entries(jdsl)) {
if (key == "__main__") {
console.log("JDSL<exec>", value);
global[value]();
} else {
console.log("JDSL<import>:", key, value);
await cmd("git", "checkout", value);
const mod = await import(`./${dsl}.js?v=${value}`);
global[key] = mod[key];
console.log("JDSL<loaded>:", global[key]);
}
}
}
async function jdsl() {
await jdslLoad("main");
await jdslLoad("lexer");
await jdslLoad("lexer.test");
await cmd("git", "checkout", "main");
}
jdsl();