@evandu/super-pi 0.1.49 → 0.1.51
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/README.md +13 -11
- package/bin/super-pi.js +80 -11
- package/dist/client/assets/index-Bx1HHVVh.js +53 -0
- package/dist/client/assets/index-DJD8mXiK.css +1 -0
- package/dist/client/index.html +2 -2
- package/dist/extension.js +2 -2
- package/package.json +1 -1
- package/dist/client/assets/index-BLvF3jif.js +0 -53
- package/dist/client/assets/index-Bm1n_96d.css +0 -1
package/README.md
CHANGED
|
@@ -19,15 +19,15 @@ pi install npm:@evandu/super-pi
|
|
|
19
19
|
Once installed, simply launch your Pi terminal as usual, and type:
|
|
20
20
|
|
|
21
21
|
```text
|
|
22
|
-
/
|
|
22
|
+
/super_pi
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
This will automatically start the background Super Pi server (port 3080) and open the Web UI in your default browser.
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
- `/
|
|
29
|
-
- `/
|
|
30
|
-
- `/
|
|
27
|
+
commands available inside pi:
|
|
28
|
+
- `/super_pi` — Open or launch Super Pi
|
|
29
|
+
- `/super_pi stop` — Stop the background Super Pi server
|
|
30
|
+
- `/super_pi restart` — Restart the Super Pi server
|
|
31
31
|
|
|
32
32
|
To update:
|
|
33
33
|
```bash
|
|
@@ -40,26 +40,28 @@ pi update --extensions
|
|
|
40
40
|
|
|
41
41
|
### Method 2: Run directly via npx / Node
|
|
42
42
|
|
|
43
|
-
You can also run Super Pi standalone:
|
|
43
|
+
You can also run Super Pi standalone without Pi:
|
|
44
44
|
|
|
45
45
|
```bash
|
|
46
|
-
npx @evandu/super-pi
|
|
46
|
+
npx @evandu/super-pi start
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
Or install globally:
|
|
50
50
|
|
|
51
51
|
```bash
|
|
52
52
|
npm install -g @evandu/super-pi
|
|
53
|
-
super-pi
|
|
53
|
+
super-pi start # Start server and open browser
|
|
54
|
+
super-pi stop # Stop the background server
|
|
55
|
+
super-pi restart # Restart the server
|
|
54
56
|
```
|
|
55
57
|
|
|
56
58
|
Then visit `http://127.0.0.1:3080` in your browser (or use the printed Network URL `http://<lan-ip>:3080` for LAN access).
|
|
57
59
|
|
|
58
|
-
Super Pi listens on `0.0.0.0` by default. You can customize the host and port
|
|
60
|
+
Super Pi listens on `0.0.0.0` by default. You can customize the host and port:
|
|
59
61
|
```bash
|
|
60
|
-
super-pi --host 0.0.0.0 --port 3080
|
|
62
|
+
super-pi start --host 0.0.0.0 --port 3080
|
|
61
63
|
# Restrict to local loopback only:
|
|
62
|
-
super-pi --host 127.0.0.1
|
|
64
|
+
super-pi start --host 127.0.0.1
|
|
63
65
|
```
|
|
64
66
|
|
|
65
67
|
---
|
package/bin/super-pi.js
CHANGED
|
@@ -3,15 +3,84 @@ import { spawn } from "node:child_process";
|
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
|
|
5
5
|
const entry = resolve(import.meta.dirname, "../dist/server/index.js");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
|
|
7
|
+
const sub = process.argv[2]?.toLowerCase();
|
|
8
|
+
const port = Number(process.env.SUPER_PI_PORT ?? 3080);
|
|
9
|
+
|
|
10
|
+
async function isRunning(port) {
|
|
11
|
+
try {
|
|
12
|
+
const res = await fetch(`http://127.0.0.1:${port}/api/health`, { signal: AbortSignal.timeout(1000) });
|
|
13
|
+
if (!res.ok) return false;
|
|
14
|
+
const data = await res.json();
|
|
15
|
+
return data?.service === "super-pi";
|
|
16
|
+
} catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function stop(port) {
|
|
22
|
+
try {
|
|
23
|
+
const res = await fetch(`http://127.0.0.1:${port}/api/shutdown`, {
|
|
24
|
+
method: "POST",
|
|
25
|
+
signal: AbortSignal.timeout(3000),
|
|
26
|
+
});
|
|
27
|
+
return res.ok || res.status === 202;
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function openBrowser(url) {
|
|
34
|
+
const platform = process.platform;
|
|
35
|
+
if (platform === "darwin") spawn("open", [url], { detached: true, stdio: "ignore" }).unref();
|
|
36
|
+
else if (platform === "win32") spawn("cmd.exe", ["/c", "start", "", url], { detached: true, stdio: "ignore" }).unref();
|
|
37
|
+
else spawn("xdg-open", [url], { detached: true, stdio: "ignore" }).unref();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (sub === "stop") {
|
|
41
|
+
const running = await isRunning(port);
|
|
42
|
+
if (!running) { console.log(`Super Pi is not running on port ${port}`); process.exit(0); }
|
|
43
|
+
console.log(`Stopping Super Pi on port ${port}...`);
|
|
44
|
+
const ok = await stop(port);
|
|
45
|
+
console.log(ok ? "Shutdown requested." : "Shutdown request failed (server may need an access token).");
|
|
46
|
+
process.exit(0);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (sub === "restart") {
|
|
50
|
+
if (await isRunning(port)) {
|
|
51
|
+
console.log(`Restarting Super Pi on port ${port}...`);
|
|
52
|
+
await stop(port);
|
|
53
|
+
await new Promise((r) => setTimeout(r, 600));
|
|
54
|
+
}
|
|
55
|
+
} else if (sub && sub !== "start") {
|
|
56
|
+
console.error(`Unknown command: ${sub}`);
|
|
57
|
+
console.error("Usage: super-pi [start|stop|restart]");
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const running = await isRunning(port);
|
|
62
|
+
if (!running) {
|
|
63
|
+
console.log("Starting Super Pi...");
|
|
64
|
+
const child = spawn(process.execPath, [entry, `--port=${port}`], {
|
|
65
|
+
detached: true,
|
|
66
|
+
stdio: "ignore",
|
|
67
|
+
env: process.env,
|
|
68
|
+
});
|
|
69
|
+
child.unref();
|
|
70
|
+
|
|
71
|
+
const deadline = Date.now() + 8000;
|
|
72
|
+
while (Date.now() < deadline) {
|
|
73
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
74
|
+
if (await isRunning(port)) break;
|
|
16
75
|
}
|
|
17
|
-
|
|
76
|
+
|
|
77
|
+
if (!(await isRunning(port))) {
|
|
78
|
+
console.error("Server did not respond within 8 seconds.");
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
console.log(`Super Pi is running at http://127.0.0.1:${port}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const url = `http://127.0.0.1:${port}`;
|
|
85
|
+
openBrowser(url);
|
|
86
|
+
console.log(`Opened ${url}`);
|