create-medan-app 0.1.4 → 0.1.5
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/dist/templates.js +16 -18
- package/package.json +1 -1
package/dist/templates.js
CHANGED
|
@@ -25,7 +25,7 @@ import { createServer } from "node:http";
|
|
|
25
25
|
import { networkInterfaces } from "node:os";
|
|
26
26
|
|
|
27
27
|
const PORT = ${DEV_PORT};
|
|
28
|
-
|
|
28
|
+
const clients = new Set();
|
|
29
29
|
|
|
30
30
|
function fmtMs(ms) {
|
|
31
31
|
return ms >= 1000 ? (ms / 1000).toFixed(1) + "s" : Math.round(ms) + "ms";
|
|
@@ -49,39 +49,37 @@ function build(quiet) {
|
|
|
49
49
|
console.error("\\n✗ gagal compile, benerin dulu terus save lagi.\\n");
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
|
-
version++;
|
|
53
52
|
console.log(\`✓ Compiled in \${fmtMs(Date.now() - start)}\`);
|
|
53
|
+
for (const res of clients) res.write("data: reload\\n\\n");
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
const RELOAD_SCRIPT = \`
|
|
57
57
|
<script>
|
|
58
58
|
(function () {
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
fetch("/__medan-version")
|
|
62
|
-
.then(function (r) { return r.text(); })
|
|
63
|
-
.then(function (v) {
|
|
64
|
-
if (current === null) current = v;
|
|
65
|
-
else if (v !== current) location.reload();
|
|
66
|
-
})
|
|
67
|
-
.catch(function () {});
|
|
68
|
-
}, 400);
|
|
59
|
+
var es = new EventSource("/__medan-events");
|
|
60
|
+
es.onmessage = function () { location.reload(); };
|
|
69
61
|
})();
|
|
70
62
|
</script>
|
|
71
63
|
\`;
|
|
72
64
|
|
|
73
65
|
const server = createServer((req, res) => {
|
|
66
|
+
if (req.url === "/__medan-events") {
|
|
67
|
+
res.writeHead(200, {
|
|
68
|
+
"content-type": "text/event-stream",
|
|
69
|
+
"cache-control": "no-cache",
|
|
70
|
+
"connection": "keep-alive",
|
|
71
|
+
});
|
|
72
|
+
res.write(\`retry: 500\\n\\n\`);
|
|
73
|
+
clients.add(res);
|
|
74
|
+
req.on("close", () => clients.delete(res));
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
74
78
|
const start = Date.now();
|
|
75
79
|
res.on("finish", () => {
|
|
76
80
|
console.log(\` \${req.method} \${req.url} \${res.statusCode} in \${fmtMs(Date.now() - start)}\`);
|
|
77
81
|
});
|
|
78
82
|
|
|
79
|
-
if (req.url === "/__medan-version") {
|
|
80
|
-
res.writeHead(200, { "content-type": "text/plain" });
|
|
81
|
-
res.end(String(version));
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
83
|
if (!existsSync("landing.html")) {
|
|
86
84
|
res.writeHead(200, { "content-type": "text/html" });
|
|
87
85
|
res.end("<p>lagi nge-generate landing.html, tunggu bentar terus refresh...</p>");
|