create-medan-app 0.1.3 → 0.1.4

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.
Files changed (2) hide show
  1. package/dist/templates.js +34 -7
  2. package/package.json +1 -1
package/dist/templates.js CHANGED
@@ -22,18 +22,35 @@ export const DEV_MJS = `// dev.mjs
22
22
  import { spawnSync } from "node:child_process";
23
23
  import { watch, readFileSync, existsSync } from "node:fs";
24
24
  import { createServer } from "node:http";
25
+ import { networkInterfaces } from "node:os";
25
26
 
26
27
  const PORT = ${DEV_PORT};
27
28
  let version = 0;
28
29
 
29
- function build() {
30
- console.log("\\n[medan] generate landing.html ...");
30
+ function fmtMs(ms) {
31
+ return ms >= 1000 ? (ms / 1000).toFixed(1) + "s" : Math.round(ms) + "ms";
32
+ }
33
+
34
+ function localIp() {
35
+ const nets = networkInterfaces();
36
+ for (const name of Object.keys(nets)) {
37
+ for (const net of nets[name] ?? []) {
38
+ if (net.family === "IPv4" && !net.internal) return net.address;
39
+ }
40
+ }
41
+ return null;
42
+ }
43
+
44
+ function build(quiet) {
45
+ const start = Date.now();
46
+ if (!quiet) console.log("○ compiling main.medan ...");
31
47
  const result = spawnSync("medan", ["main.medan"], { stdio: "inherit" });
32
48
  if (result.status !== 0) {
33
- console.error("[medan] ada error di atas, benerin dulu terus save lagi.");
49
+ console.error("\\n✗ gagal compile, benerin dulu terus save lagi.\\n");
34
50
  return;
35
51
  }
36
52
  version++;
53
+ console.log(\`✓ Compiled in \${fmtMs(Date.now() - start)}\`);
37
54
  }
38
55
 
39
56
  const RELOAD_SCRIPT = \`
@@ -54,6 +71,11 @@ const RELOAD_SCRIPT = \`
54
71
  \`;
55
72
 
56
73
  const server = createServer((req, res) => {
74
+ const start = Date.now();
75
+ res.on("finish", () => {
76
+ console.log(\` \${req.method} \${req.url} \${res.statusCode} in \${fmtMs(Date.now() - start)}\`);
77
+ });
78
+
57
79
  if (req.url === "/__medan-version") {
58
80
  res.writeHead(200, { "content-type": "text/plain" });
59
81
  res.end(String(version));
@@ -71,16 +93,21 @@ const server = createServer((req, res) => {
71
93
  res.end(html);
72
94
  });
73
95
 
74
- build();
96
+ const bootStart = Date.now();
97
+ build(true);
98
+
75
99
  server.listen(PORT, () => {
76
- console.log(\`\\n[medan] jalan di http://localhost:\${PORT}\`);
77
- console.log("[medan] mantau main.medan, ctrl+c buat berhenti...");
100
+ const ip = localIp();
101
+ console.log("\\n▲ Medan-lang dev");
102
+ console.log(\` - Local: http://localhost:\${PORT}\`);
103
+ if (ip) console.log(\` - Network: http://\${ip}:\${PORT}\`);
104
+ console.log(\`\\n✓ Ready in \${fmtMs(Date.now() - bootStart)}\\n\`);
78
105
  });
79
106
 
80
107
  let timer;
81
108
  watch("main.medan", () => {
82
109
  clearTimeout(timer);
83
- timer = setTimeout(build, 100);
110
+ timer = setTimeout(() => build(false), 100);
84
111
  });
85
112
  `;
86
113
  export function mainMedan(name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-medan-app",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Scaffold project Medan-lang baru, kayak 'npx create-next-app'.",
5
5
  "author": "Wilbert Law",
6
6
  "license": "MIT",