olum-compiler 2.1.1 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/build.js +32 -0
- package/bin/dev.js +9 -12
- package/bin/server.js +1 -12
- package/lib/changes.txt +6 -1
- package/lib/websocket.js +2 -0
- package/package.json +1 -1
package/bin/build.js
CHANGED
|
@@ -4,6 +4,38 @@ const bundle = require("./bundle");
|
|
|
4
4
|
const compile = require("./compiler");
|
|
5
5
|
const copySrc = require("./copySrc");
|
|
6
6
|
const ssg = require("./ssg");
|
|
7
|
+
const colors = require("../lib/colors");
|
|
8
|
+
|
|
9
|
+
const lockFile = path.resolve(__dirname, "../.dev.lock");
|
|
10
|
+
const devPid = (() => {
|
|
11
|
+
try {
|
|
12
|
+
return Number(fs.readFileSync(lockFile, "utf8").trim());
|
|
13
|
+
} catch (e) {
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
})();
|
|
17
|
+
const devAlive = (() => {
|
|
18
|
+
try {
|
|
19
|
+
return !!devPid && !!process.kill(devPid, 0);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
return e.code === "EPERM";
|
|
22
|
+
}
|
|
23
|
+
})();
|
|
24
|
+
if (devAlive) {
|
|
25
|
+
console.error(
|
|
26
|
+
colors(
|
|
27
|
+
"red",
|
|
28
|
+
`A dev server is running (pid ${devPid}) — refusing to build.`,
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
console.error(
|
|
32
|
+
colors(
|
|
33
|
+
"white",
|
|
34
|
+
`The build would overwrite the files it serves and break the page in the browser.\nStop the dev server first, then build. # or delete ${lockFile} if that process is gone`,
|
|
35
|
+
),
|
|
36
|
+
);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
7
39
|
|
|
8
40
|
(async function () {
|
|
9
41
|
const bootAt = Date.now();
|
package/bin/dev.js
CHANGED
|
@@ -50,7 +50,7 @@ process.on("exit", () => read() === me && fs.rmSync(lockFile, { force: true }));
|
|
|
50
50
|
process.on(signal, () => process.exit(0)),
|
|
51
51
|
);
|
|
52
52
|
|
|
53
|
-
serve(entryPoint).then(({ server,
|
|
53
|
+
serve(entryPoint).then(({ server, PORT, log }) => {
|
|
54
54
|
const bootAt = Date.now();
|
|
55
55
|
copySrc()
|
|
56
56
|
.then(() => {
|
|
@@ -70,17 +70,14 @@ serve(entryPoint).then(({ server, wsPort, PORT, log, setWsPort }) => {
|
|
|
70
70
|
);
|
|
71
71
|
require("../lib/compiler");
|
|
72
72
|
|
|
73
|
-
(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
ws.send(JSON.stringify({ msg: "connected" })),
|
|
82
|
-
);
|
|
83
|
-
})(wsPort);
|
|
73
|
+
const wss = new WebSocket.Server({ server });
|
|
74
|
+
sockets = wss.clients;
|
|
75
|
+
wss.on("error", (e) => {
|
|
76
|
+
if (e.code !== "EADDRINUSE") console.error(e);
|
|
77
|
+
});
|
|
78
|
+
wss.on("connection", (ws) =>
|
|
79
|
+
ws.send(JSON.stringify({ msg: "connected" })),
|
|
80
|
+
);
|
|
84
81
|
});
|
|
85
82
|
})
|
|
86
83
|
.catch(console.error);
|
package/bin/server.js
CHANGED
|
@@ -6,11 +6,9 @@ const { parseDOM } = require("../lib/dom");
|
|
|
6
6
|
const colors = require("../lib/colors");
|
|
7
7
|
const mimes = require("./mimes.json");
|
|
8
8
|
const sitemapPath = path.resolve(__dirname, "../src/sitemap.js");
|
|
9
|
-
let wsPort = 8090;
|
|
10
9
|
|
|
11
10
|
function handleWsFile() {
|
|
12
11
|
let file = fs.readFileSync(path.resolve(__dirname, "./ws.js")).toString();
|
|
13
|
-
|
|
14
12
|
file = "<script>" + file + "</script>";
|
|
15
13
|
return file;
|
|
16
14
|
}
|
|
@@ -159,16 +157,7 @@ function serve(entry, port, mode = "development") {
|
|
|
159
157
|
}
|
|
160
158
|
const log = colors("cyan", "Serving ") + colors("green", "port " + PORT);
|
|
161
159
|
|
|
162
|
-
|
|
163
|
-
wsPort = port;
|
|
164
|
-
};
|
|
165
|
-
resolve({
|
|
166
|
-
server: server,
|
|
167
|
-
wsPort: wsPort,
|
|
168
|
-
PORT: PORT,
|
|
169
|
-
log: log,
|
|
170
|
-
setWsPort: setWsPort,
|
|
171
|
-
});
|
|
160
|
+
resolve({ server: server, PORT: PORT, log: log });
|
|
172
161
|
});
|
|
173
162
|
}
|
|
174
163
|
|
package/lib/changes.txt
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
change /home/eissapk/olum/template-compiler/src/
|
|
1
|
+
change /home/eissapk/olum/template-compiler/src/page.html
|
|
2
|
+
change /home/eissapk/olum/template-compiler/src/page.html
|
|
3
|
+
change /home/eissapk/olum/template-compiler/src/page.html
|
|
4
|
+
change /home/eissapk/olum/template-compiler/src/page.html
|
|
5
|
+
change /home/eissapk/olum/template-compiler/src/page.html
|
|
6
|
+
change /home/eissapk/olum/template-compiler/src/page.html
|
package/lib/websocket.js
CHANGED
|
@@ -290,6 +290,8 @@ class WebSocketServer extends EventEmitter {
|
|
|
290
290
|
}
|
|
291
291
|
|
|
292
292
|
handleUpgrade(req, socket, head, callback) {
|
|
293
|
+
if (socket.__olumUpgraded) return;
|
|
294
|
+
socket.__olumUpgraded = true;
|
|
293
295
|
socket.on("error", () => socket.destroy());
|
|
294
296
|
|
|
295
297
|
const key = req.headers["sec-websocket-key"];
|