This repository has been archived by the owner on May 5, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
79 lines (56 loc) · 1.78 KB
/
index.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const readline = require("readline");
const fs = require("fs");
const esbuild = require("esbuild");
const cssModulesPlugin = require('esbuild-css-modules-plugin');
const express = require("express");
const app = express();
const port = 1005;
const dashboard = (`
[OldGuard]
The old machine hums along... listen to the vibrations of the ancient one on :${port}
OldGuard Dashboard!
[B] - Rebuild the bundle
[X] - Shut down OldGuard
[J] - Dump the JavaScript bundle
[C] - Dump the CSS bundle
`);
app.use(express.static("dist"));
app.get("/", (req, res) => {
res.redirect("bundle.js");
});
app.listen(port, () => {
readline.emitKeypressEvents(process.stdin);
process.stdin.setRawMode(true);
console.log(dashboard);
});
process.stdin.on("keypress", (str, key) => {
const { name, ctrl } = key;
// exit
if (name === "x" || (name === "c" && ctrl)) {
console.log("[OldGuard] Exiting OldGuard...");
process.exit();
}
// build
if (name === "b") {
esbuild.build({
entryPoints: ["./src/app.jsx"],
bundle: true,
minifyWhitespace: true,
target: "chrome90",
outfile: "dist/bundle.js",
plugins: [cssModulesPlugin({inject: true})]
}).catch(err => console.error(err)); // lol error handling
console.log(`[OldGuard] Built OldGuard at ${Date.now()} (${Date()})`);
return;
}
if (name === "j") {
console.log(`[OldGuard] Dumping JavaScript bundle...`);
console.log(fs.readFileSync("dist/bundle.js", "utf8"));
return;
}
if (name === "c") {
console.log(`[OldGuard] Dumping CSS bundle...`);
console.log(fs.readFileSync("dist/bundle.css", "utf8"));
return;
}
});