forked from anmolitor/protoc-gen-elm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.js
33 lines (28 loc) · 872 Bytes
/
debug.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
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const Elm = require("./elm.debug.js").Elm;
const app = Elm.DebugMain.init({
flags: {},
});
app.ports.debug.subscribe((msg) => {
fs.appendFileSync("debug.log", `\n[${new Date().toISOString()}]: ${msg}`);
});
function sendToGenerator(request) {
return new Promise((resolve) => {
const responseHandler = (response) => {
resolve(Buffer.from(response, "base64"));
app.ports.response.unsubscribe(responseHandler);
};
app.ports.response.subscribe(responseHandler);
app.ports.request.send(request.toString("base64"));
});
}
const chunks = [];
process.stdin.on("data", (chunk) => {
chunks.push(chunk);
});
process.stdin.on("end", () => {
const request = Buffer.concat(chunks);
sendToGenerator(request).then((response) => process.stdout.write(response));
});