@evandu/super-pi 0.1.96 → 0.1.97
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/super-pi.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { execFile, spawn } from "node:child_process";
|
|
3
|
-
import { existsSync } from "node:fs";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
4
|
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
5
5
|
import { homedir } from "node:os";
|
|
6
6
|
import { dirname, join, resolve } from "node:path";
|
|
@@ -15,6 +15,31 @@ const home = process.env.SUPER_PI_AUTOSTART_HOME ?? homedir();
|
|
|
15
15
|
const envPort = Number(process.env.SUPER_PI_PORT ?? 3080);
|
|
16
16
|
const defaultPort = Number.isInteger(envPort) && envPort > 0 ? envPort : 3080;
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* This installation's own version.
|
|
20
|
+
*
|
|
21
|
+
* READ AT RUN TIME, not baked in, because there can be more than one Super Pi on a machine and the one
|
|
22
|
+
* that matters is the one that is RUNNING. The two usual places are the global npm install - which is
|
|
23
|
+
* what the `super_pi` command runs - and the Pi extension's own install - which is what the
|
|
24
|
+
* `/super_pi` slash command loads. They are separate installations on purpose (Super Pi must not
|
|
25
|
+
* require Pi to be installed first), so their versions can differ, and a person comparing the two needs
|
|
26
|
+
* to see which is which. A bare version number cannot say that; a version number AND a path can.
|
|
27
|
+
*/
|
|
28
|
+
function ownVersion() {
|
|
29
|
+
try {
|
|
30
|
+
const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
31
|
+
return { version: pkg.version ?? "unknown", location: root };
|
|
32
|
+
} catch {
|
|
33
|
+
return { version: "unknown", location: root };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The line that names what is running, so two installations can be told apart at a glance. */
|
|
38
|
+
function runningBanner(url) {
|
|
39
|
+
const { version, location } = ownVersion();
|
|
40
|
+
return `Super Pi v${version} is running at ${url}\n installed at ${location}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
18
43
|
function options(args) {
|
|
19
44
|
const value = { port: defaultPort, host: process.env.SUPER_PI_HOST ?? "0.0.0.0", browser: true };
|
|
20
45
|
for (let i = 0; i < args.length; i += 1) {
|
|
@@ -57,12 +82,12 @@ const command = implicitStart ? "start" : raw?.toLowerCase();
|
|
|
57
82
|
const args = implicitStart ? [raw, ...rest] : rest;
|
|
58
83
|
try {
|
|
59
84
|
if (command === "help" || command === "--help" || command === "-h") { usage(); process.exit(0); }
|
|
60
|
-
if (!command) { const value = options(args); await start(value); const url = `http://127.0.0.1:${value.port}`; if (value.browser) openBrowser(url); console.log(value.browser ? `Opened ${url}` :
|
|
85
|
+
if (!command) { const value = options(args); await start(value); const url = `http://127.0.0.1:${value.port}`; if (value.browser) openBrowser(url); console.log(value.browser ? `Opened ${url}\n${runningBanner(url)}` : runningBanner(url)); process.exit(0); }
|
|
61
86
|
if (command === "autostart" || command === "startup") { const action = args.shift()?.toLowerCase() ?? "status"; const value = options(args); if (action === "enable") await enable(value); else if (action === "disable") await disable(); else if (action === "status") await status(); else throw new Error("Autostart action must be enable, disable, or status."); process.exit(0); }
|
|
62
87
|
if (!["start", "stop", "restart", "update"].includes(command)) throw new Error(`Unknown command: ${command}`);
|
|
63
88
|
if (command === "update") { const npm = platform === "win32" ? "npm.cmd" : "npm"; const args = prefix ? ["install", "--prefix", prefix, "@evandu/super-pi"] : ["install", "-g", "@evandu/super-pi"]; const child = spawn(npm, args, { stdio: "inherit", shell: platform === "win32", env: process.env }); const code = await new Promise((resolve) => child.on("close", resolve)); if (code !== 0) process.exit(code ?? 1); }
|
|
64
89
|
const value = options(args);
|
|
65
90
|
if (command === "stop") { console.log(await running(value.port) ? (await stop(value.port) ? `Shutdown requested on port ${value.port}.` : "Shutdown request failed.") : `Super Pi is not running on port ${value.port}.`); process.exit(0); }
|
|
66
91
|
if ((command === "restart" || command === "update") && await running(value.port)) { await stop(value.port); await new Promise((resolve) => setTimeout(resolve, 600)); }
|
|
67
|
-
await start(value); const url = `http://127.0.0.1:${value.port}`; if (value.browser) openBrowser(url); console.log(value.browser ? `Opened ${url}` :
|
|
68
|
-
} catch (error) { console.error(error instanceof Error ? error.message : String(error)); usage(); process.exit(1); }
|
|
92
|
+
await start(value); const url = `http://127.0.0.1:${value.port}`; if (value.browser) openBrowser(url); console.log(value.browser ? `Opened ${url}\n${runningBanner(url)}` : runningBanner(url));
|
|
93
|
+
} catch (error) { console.error(error instanceof Error ? error.message : String(error)); usage(); process.exit(1); }
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"src/client/types.ts": "6487df00c164370550b5977f9b23b17e22aff4bfb59dfe1e52200042340e3769",
|
|
25
25
|
"src/client/vite-env.d.ts": "65996936fbb042915f7b74a200fcdde7e410f32a669b1ab9597cfaa4b0faddb5"
|
|
26
26
|
},
|
|
27
|
-
"recordedAt": "2026-10-
|
|
27
|
+
"recordedAt": "2026-10-20T17:20:14.918Z"
|
|
28
28
|
}
|