@frumu/tandem-tui 0.3.6 → 0.3.11
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 +1 -7
- package/bin/tandem-tui.js +91 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,13 +25,7 @@ The installer downloads the release asset that matches this package version. Tag
|
|
|
25
25
|
|
|
26
26
|
## Quick Start
|
|
27
27
|
|
|
28
|
-
Start the
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
tandem-engine serve --hostname 127.0.0.1 --port 39731
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
Start the TUI in another terminal:
|
|
28
|
+
Start the TUI in your terminal:
|
|
35
29
|
|
|
36
30
|
```bash
|
|
37
31
|
tandem-tui
|
package/bin/tandem-tui.js
CHANGED
|
@@ -1,17 +1,102 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const path = require("path");
|
|
4
|
+
const https = require("https");
|
|
4
5
|
const { spawnSync } = require("child_process");
|
|
5
6
|
|
|
6
7
|
const binaryName = process.platform === "win32" ? "tandem-tui.exe" : "tandem-tui";
|
|
7
8
|
const binaryPath = path.join(__dirname, "native", binaryName);
|
|
8
9
|
|
|
9
|
-
const
|
|
10
|
+
const packageInfo = require("../package.json");
|
|
11
|
+
const UPDATE_CHECK_TIMEOUT_MS = 1200;
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
function parseVersion(version) {
|
|
14
|
+
const core = String(version || "").split("-")[0];
|
|
15
|
+
return core.split(".").map((part) => {
|
|
16
|
+
const value = Number.parseInt(part, 10);
|
|
17
|
+
return Number.isFinite(value) ? value : 0;
|
|
18
|
+
});
|
|
15
19
|
}
|
|
16
20
|
|
|
17
|
-
|
|
21
|
+
function isNewerVersion(latest, current) {
|
|
22
|
+
const a = parseVersion(latest);
|
|
23
|
+
const b = parseVersion(current);
|
|
24
|
+
const length = Math.max(a.length, b.length);
|
|
25
|
+
|
|
26
|
+
for (let i = 0; i < length; i += 1) {
|
|
27
|
+
const left = a[i] || 0;
|
|
28
|
+
const right = b[i] || 0;
|
|
29
|
+
if (left > right) return true;
|
|
30
|
+
if (left < right) return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function fetchLatestVersion(packageName, timeoutMs) {
|
|
37
|
+
return new Promise((resolve) => {
|
|
38
|
+
const encodedName = encodeURIComponent(packageName);
|
|
39
|
+
const url = `https://registry.npmjs.org/${encodedName}/latest`;
|
|
40
|
+
const request = https.get(url, { headers: { Accept: "application/json" } }, (response) => {
|
|
41
|
+
if (response.statusCode !== 200) {
|
|
42
|
+
response.resume();
|
|
43
|
+
resolve(null);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let body = "";
|
|
48
|
+
response.setEncoding("utf8");
|
|
49
|
+
response.on("data", (chunk) => {
|
|
50
|
+
body += chunk;
|
|
51
|
+
});
|
|
52
|
+
response.on("end", () => {
|
|
53
|
+
try {
|
|
54
|
+
const parsed = JSON.parse(body);
|
|
55
|
+
resolve(typeof parsed.version === "string" ? parsed.version : null);
|
|
56
|
+
} catch {
|
|
57
|
+
resolve(null);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
request.on("error", () => resolve(null));
|
|
63
|
+
request.setTimeout(timeoutMs, () => {
|
|
64
|
+
request.destroy();
|
|
65
|
+
resolve(null);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function notifyIfUpdateAvailable() {
|
|
71
|
+
const latestVersion = await fetchLatestVersion(packageInfo.name, UPDATE_CHECK_TIMEOUT_MS);
|
|
72
|
+
if (!latestVersion || !isNewerVersion(latestVersion, packageInfo.version)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
console.error(`[${packageInfo.name}] Update available: ${packageInfo.version} -> ${latestVersion}`);
|
|
77
|
+
console.error(`Run: npm i -g ${packageInfo.name}`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function main() {
|
|
81
|
+
await notifyIfUpdateAvailable();
|
|
82
|
+
|
|
83
|
+
const child = spawnSync(binaryPath, process.argv.slice(2), { stdio: "inherit" });
|
|
84
|
+
|
|
85
|
+
if (child.error) {
|
|
86
|
+
console.error("tandem-tui binary is missing. Reinstall with: npm i -g @frumu/tandem-tui");
|
|
87
|
+
console.error(child.error.message);
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
process.exit(child.status ?? 1);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
main().catch(() => {
|
|
95
|
+
const child = spawnSync(binaryPath, process.argv.slice(2), { stdio: "inherit" });
|
|
96
|
+
if (child.error) {
|
|
97
|
+
console.error("tandem-tui binary is missing. Reinstall with: npm i -g @frumu/tandem-tui");
|
|
98
|
+
console.error(child.error.message);
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
process.exit(child.status ?? 1);
|
|
102
|
+
});
|