@renbostudios/edge-ota 0.3.0 → 0.3.1
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/index.js +66 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* edge-ota keygen — Generate a new ECDSA key pair (prints to stdout)
|
|
14
14
|
*/
|
|
15
15
|
import { Command } from "commander";
|
|
16
|
-
import { spawn } from "child_process";
|
|
16
|
+
import { execSync, spawn } from "child_process";
|
|
17
17
|
import fs from "fs";
|
|
18
18
|
import os from "os";
|
|
19
19
|
import path from "path";
|
|
@@ -154,6 +154,70 @@ try {
|
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
catch { /* fallback */ }
|
|
157
|
+
// ─── Auto Update Check ────────────────────────────────────────────────────────
|
|
158
|
+
const UPDATE_CHECK_FILE = path.join(GLOBAL_CONFIG_DIR, "update-check.json");
|
|
159
|
+
function isNewerVersion(current, latest) {
|
|
160
|
+
const cParts = current.split(".").map(Number);
|
|
161
|
+
const lParts = latest.split(".").map(Number);
|
|
162
|
+
for (let i = 0; i < 3; i++) {
|
|
163
|
+
const cNum = cParts[i] || 0;
|
|
164
|
+
const lNum = lParts[i] || 0;
|
|
165
|
+
if (lNum > cNum)
|
|
166
|
+
return true;
|
|
167
|
+
if (lNum < cNum)
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
async function checkAndAutoUpdate() {
|
|
173
|
+
if (process.env.EDGE_OTA_UPDATING === "true")
|
|
174
|
+
return;
|
|
175
|
+
try {
|
|
176
|
+
const now = Date.now();
|
|
177
|
+
if (fs.existsSync(UPDATE_CHECK_FILE)) {
|
|
178
|
+
try {
|
|
179
|
+
const cache = JSON.parse(fs.readFileSync(UPDATE_CHECK_FILE, "utf-8"));
|
|
180
|
+
// Only check npm once every 15 minutes to keep CLI commands extremely fast
|
|
181
|
+
if (now - (cache.lastChecked || 0) < 15 * 60 * 1000) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
catch { /* ignore */ }
|
|
186
|
+
}
|
|
187
|
+
// Save timestamp immediately to prevent concurrent requests
|
|
188
|
+
fs.mkdirSync(GLOBAL_CONFIG_DIR, { recursive: true });
|
|
189
|
+
fs.writeFileSync(UPDATE_CHECK_FILE, JSON.stringify({ lastChecked: now }));
|
|
190
|
+
// Fetch latest version from registry with a short 1s timeout
|
|
191
|
+
const controller = new AbortController();
|
|
192
|
+
const timerId = setTimeout(() => controller.abort(), 1000);
|
|
193
|
+
const res = await fetch("https://registry.npmjs.org/@renbostudios/edge-ota/latest", {
|
|
194
|
+
signal: controller.signal
|
|
195
|
+
});
|
|
196
|
+
clearTimeout(timerId);
|
|
197
|
+
if (!res.ok)
|
|
198
|
+
return;
|
|
199
|
+
const data = (await res.json());
|
|
200
|
+
const latestVersion = data.version;
|
|
201
|
+
if (latestVersion && isNewerVersion(packageVersion, latestVersion)) {
|
|
202
|
+
console.log(`\n ${c.yellow}${c.reset} New version of ${c.bold}edge-ota${c.reset} available: ${c.green}${latestVersion}${c.reset} (current: ${c.dim}${packageVersion}${c.reset})`);
|
|
203
|
+
console.log(` ${c.blue}➜${c.reset} Auto-updating globally...`);
|
|
204
|
+
try {
|
|
205
|
+
execSync("npm install -g @renbostudios/edge-ota", {
|
|
206
|
+
stdio: "inherit",
|
|
207
|
+
env: { ...process.env, EDGE_OTA_UPDATING: "true" }
|
|
208
|
+
});
|
|
209
|
+
console.log(` ${c.green}✓${c.reset} Successfully auto-updated to ${c.bold}${latestVersion}${c.reset}!\n`);
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
console.error(` ${c.red}✗${c.reset} Auto-update failed: ${err.message}`);
|
|
213
|
+
console.error(` Please update manually: ${c.cyan}npm install -g @renbostudios/edge-ota${c.reset}\n`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
// Fail silently so CLI works offline
|
|
219
|
+
}
|
|
220
|
+
}
|
|
157
221
|
// ─── Banner ───────────────────────────────────────────────────────────────────
|
|
158
222
|
function printBanner() {
|
|
159
223
|
const sep = `${c.dim}${"─".repeat(52)}${c.reset}`;
|
|
@@ -869,4 +933,5 @@ program
|
|
|
869
933
|
console.log(sep);
|
|
870
934
|
console.log(keys.publicKey);
|
|
871
935
|
});
|
|
936
|
+
await checkAndAutoUpdate();
|
|
872
937
|
program.parse(process.argv);
|
package/package.json
CHANGED