@babylen/legion 0.1.0 → 0.1.2
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 +54 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -23,6 +23,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
mod
|
|
24
24
|
));
|
|
25
25
|
|
|
26
|
+
// src/index.ts
|
|
27
|
+
var import_child_process = require("child_process");
|
|
28
|
+
|
|
29
|
+
// package.json
|
|
30
|
+
var version = "0.1.2";
|
|
31
|
+
|
|
26
32
|
// src/index.ts
|
|
27
33
|
var import_socket = require("socket.io-client");
|
|
28
34
|
var os3 = __toESM(require("os"));
|
|
@@ -259,11 +265,55 @@ var Log;
|
|
|
259
265
|
})(Log || (Log = {}));
|
|
260
266
|
|
|
261
267
|
// src/index.ts
|
|
262
|
-
|
|
268
|
+
if (process.argv.includes("--version") || process.argv.includes("-v")) {
|
|
269
|
+
console.log(version);
|
|
270
|
+
process.exit(0);
|
|
271
|
+
}
|
|
272
|
+
function checkForUpdates() {
|
|
273
|
+
setTimeout(async () => {
|
|
274
|
+
try {
|
|
275
|
+
const packageName = "@babylen/legion";
|
|
276
|
+
const command = `npm view ${packageName} version`;
|
|
277
|
+
const timeout = 3e3;
|
|
278
|
+
const latestVersion = (0, import_child_process.execSync)(command, {
|
|
279
|
+
encoding: "utf-8",
|
|
280
|
+
timeout,
|
|
281
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
282
|
+
}).trim();
|
|
283
|
+
if (latestVersion !== version) {
|
|
284
|
+
console.warn(`
|
|
285
|
+
\u26A0\uFE0F Update available: ${version} \u2192 ${latestVersion}`);
|
|
286
|
+
console.warn(` Run: npm install -g ${packageName}@latest
|
|
287
|
+
`);
|
|
288
|
+
}
|
|
289
|
+
} catch (error) {
|
|
290
|
+
}
|
|
291
|
+
}, 100);
|
|
292
|
+
}
|
|
263
293
|
async function main() {
|
|
294
|
+
let log = null;
|
|
295
|
+
const safeLog = {
|
|
296
|
+
info: (message, extra) => {
|
|
297
|
+
if (log) log.info(message, extra);
|
|
298
|
+
else console.log(message, extra);
|
|
299
|
+
},
|
|
300
|
+
error: (message, extra) => {
|
|
301
|
+
if (log) log.error(message, extra);
|
|
302
|
+
else console.error(message, extra);
|
|
303
|
+
},
|
|
304
|
+
warn: (message, extra) => {
|
|
305
|
+
if (log) log.warn(message, extra);
|
|
306
|
+
else console.warn(message, extra);
|
|
307
|
+
},
|
|
308
|
+
debug: (message, extra) => {
|
|
309
|
+
if (log) log.debug(message, extra);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
264
312
|
try {
|
|
313
|
+
log = Log.create({ service: "legion" });
|
|
314
|
+
checkForUpdates();
|
|
265
315
|
await Global.init();
|
|
266
|
-
log.info(
|
|
316
|
+
log.info(`\u{1F6E1}\uFE0F Legion v${version} starting...`);
|
|
267
317
|
const config2 = await getConfig();
|
|
268
318
|
log.info("\u{1F517} Connecting to server", { serverUrl: config2.serverUrl });
|
|
269
319
|
const socket = (0, import_socket.io)(config2.serverUrl, {
|
|
@@ -343,7 +393,7 @@ async function main() {
|
|
|
343
393
|
});
|
|
344
394
|
} catch (error) {
|
|
345
395
|
if (error instanceof Error) {
|
|
346
|
-
|
|
396
|
+
safeLog.error("Failed to start Legion", {
|
|
347
397
|
message: error.message,
|
|
348
398
|
stack: error.stack
|
|
349
399
|
});
|
|
@@ -352,7 +402,7 @@ async function main() {
|
|
|
352
402
|
console.error(" - Set LEGION_TOKEN environment variable, or");
|
|
353
403
|
console.error(" - Create ~/.tanuki/config.json with your token");
|
|
354
404
|
} else {
|
|
355
|
-
|
|
405
|
+
safeLog.error("Failed to start Legion", { error });
|
|
356
406
|
console.error("\n\u274C Unknown error occurred");
|
|
357
407
|
}
|
|
358
408
|
process.exit(1);
|