@babylen/legion 0.1.0 → 0.1.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 +32 -18
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
// src/index.ts
|
|
27
27
|
var import_socket = require("socket.io-client");
|
|
28
28
|
var os3 = __toESM(require("os"));
|
|
29
|
+
var import_fs2 = require("fs");
|
|
30
|
+
var import_path4 = require("path");
|
|
29
31
|
|
|
30
32
|
// src/core/config.ts
|
|
31
33
|
var import_os = __toESM(require("os"));
|
|
@@ -259,13 +261,25 @@ var Log;
|
|
|
259
261
|
})(Log || (Log = {}));
|
|
260
262
|
|
|
261
263
|
// src/index.ts
|
|
262
|
-
var
|
|
264
|
+
var packageJsonPath = (0, import_path4.join)(__dirname, "..", "package.json");
|
|
265
|
+
var version = "0.0.0";
|
|
266
|
+
try {
|
|
267
|
+
const packageJson = JSON.parse((0, import_fs2.readFileSync)(packageJsonPath, "utf-8"));
|
|
268
|
+
version = packageJson.version;
|
|
269
|
+
} catch {
|
|
270
|
+
version = "0.0.0";
|
|
271
|
+
}
|
|
263
272
|
async function main() {
|
|
273
|
+
if (process.argv.includes("--version") || process.argv.includes("-v")) {
|
|
274
|
+
console.log(version);
|
|
275
|
+
process.exit(0);
|
|
276
|
+
}
|
|
264
277
|
try {
|
|
278
|
+
const log2 = Log.create({ service: "legion" });
|
|
265
279
|
await Global.init();
|
|
266
|
-
|
|
280
|
+
log2.info(`\u{1F6E1}\uFE0F Legion v${version} starting...`);
|
|
267
281
|
const config2 = await getConfig();
|
|
268
|
-
|
|
282
|
+
log2.info("\u{1F517} Connecting to server", { serverUrl: config2.serverUrl });
|
|
269
283
|
const socket = (0, import_socket.io)(config2.serverUrl, {
|
|
270
284
|
auth: {
|
|
271
285
|
id: config2.id,
|
|
@@ -281,7 +295,7 @@ async function main() {
|
|
|
281
295
|
reconnectionAttempts: Infinity
|
|
282
296
|
});
|
|
283
297
|
socket.on("connect", () => {
|
|
284
|
-
|
|
298
|
+
log2.info("\u2705 Connected to server", { socketId: socket.id });
|
|
285
299
|
const handshakeData = {
|
|
286
300
|
hostname: os3.hostname(),
|
|
287
301
|
platform: os3.platform(),
|
|
@@ -289,56 +303,56 @@ async function main() {
|
|
|
289
303
|
cwd: process.cwd()
|
|
290
304
|
};
|
|
291
305
|
socket.emit("legion:handshake", handshakeData);
|
|
292
|
-
|
|
306
|
+
log2.debug("\u{1F4E4} Sent handshake", handshakeData);
|
|
293
307
|
});
|
|
294
308
|
socket.on("connect_error", (err) => {
|
|
295
|
-
|
|
309
|
+
log2.error("\u274C Connection error", {
|
|
296
310
|
message: err.message,
|
|
297
311
|
type: err.type
|
|
298
312
|
});
|
|
299
313
|
if (err.message.includes("auth") || err.message.includes("token")) {
|
|
300
|
-
|
|
301
|
-
|
|
314
|
+
log2.error("\u{1F510} Authentication failed. Please check your token.");
|
|
315
|
+
log2.error("\u{1F4A1} Re-authenticate by updating ~/.tanuki/config.json or LEGION_TOKEN env var");
|
|
302
316
|
process.exit(1);
|
|
303
317
|
}
|
|
304
318
|
});
|
|
305
319
|
socket.on("disconnect", (reason) => {
|
|
306
|
-
|
|
320
|
+
log2.warn("\u26A0\uFE0F Disconnected from server", { reason });
|
|
307
321
|
if (reason === "io server disconnect") {
|
|
308
|
-
|
|
322
|
+
log2.error("\u{1F6AB} Server disconnected this client. Please check your token.");
|
|
309
323
|
process.exit(1);
|
|
310
324
|
}
|
|
311
325
|
});
|
|
312
326
|
socket.on("server:ping", (data2) => {
|
|
313
|
-
|
|
327
|
+
log2.debug("\u{1F4E9} Ping from server", data2);
|
|
314
328
|
socket.emit("legion:pong", { ts: Date.now() });
|
|
315
329
|
});
|
|
316
330
|
socket.on("reconnect", (attemptNumber) => {
|
|
317
|
-
|
|
331
|
+
log2.info("\u{1F504} Reconnected to server", { attempt: attemptNumber });
|
|
318
332
|
});
|
|
319
333
|
socket.on("reconnect_attempt", (attemptNumber) => {
|
|
320
|
-
|
|
334
|
+
log2.debug("\u{1F504} Reconnection attempt", { attempt: attemptNumber });
|
|
321
335
|
});
|
|
322
336
|
socket.on("reconnect_error", (error) => {
|
|
323
|
-
|
|
337
|
+
log2.error("\u{1F504} Reconnection error", { message: error.message });
|
|
324
338
|
});
|
|
325
339
|
socket.on("reconnect_failed", () => {
|
|
326
|
-
|
|
340
|
+
log2.error("\u{1F504} Reconnection failed after all attempts");
|
|
327
341
|
process.exit(1);
|
|
328
342
|
});
|
|
329
343
|
process.stdin.resume();
|
|
330
344
|
const shutdown = () => {
|
|
331
|
-
|
|
345
|
+
log2.info("\u{1F6D1} Shutting down...");
|
|
332
346
|
socket.disconnect();
|
|
333
347
|
process.exit(0);
|
|
334
348
|
};
|
|
335
349
|
process.on("SIGINT", shutdown);
|
|
336
350
|
process.on("SIGTERM", shutdown);
|
|
337
351
|
process.on("unhandledRejection", (reason) => {
|
|
338
|
-
|
|
352
|
+
log2.error("Unhandled rejection", { reason });
|
|
339
353
|
});
|
|
340
354
|
process.on("uncaughtException", (error) => {
|
|
341
|
-
|
|
355
|
+
log2.error("Uncaught exception", { error: error.message, stack: error.stack });
|
|
342
356
|
shutdown();
|
|
343
357
|
});
|
|
344
358
|
} catch (error) {
|