CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
ProdigyPNP

CoCalc is a real-time collaborative commercial alternative to JupyterHub and Overleaf that provides Jupyter Notebooks, LaTeX documents, and SageMath.

GitHub Repository: ProdigyPNP/ProdigyMathGameHacking
Path: blob/master/cheatGUI/hot-reload.mjs
Views: 713
1
import fs from "fs";
2
import { Server } from "socket.io";
3
import http from "http";
4
import { exec } from "child_process";
5
6
const app = http.createServer();
7
8
const io = new Server(app, {
9
cors: {
10
origin: "*",
11
methods: ["GET", "POST"],
12
}
13
});
14
15
fs.watch("./src/", { recursive: true }, () => {
16
exec("pnpm webpack --mode development", (error, stdout) => {
17
if (error) {
18
console.log(stdout);
19
throw error;
20
}
21
fs.readFile("./dist/bundle.js", (err, data) => {
22
if (err) throw err;
23
io.emit("update", data.toString());
24
});
25
});
26
});
27
28
app.listen(3001, () => console.log("Listening on port 3001"));
29
30