-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (48 loc) · 1.9 KB
/
index.js
File metadata and controls
58 lines (48 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env node
"use strict";
const fs = require("fs");
// Initialize logger first (needed for error handling)
const { fileLog, getLogFile, initLogger } = require("./src/utils/logger");
initLogger();
const { createApp } = require("./src/ui/tui");
const { createWebApp } = require("./src/ui/web");
// ── Global Error Handlers ────────────────────────────────────────────────────
process.on("uncaughtException", (err) => {
fileLog("ERROR", "Uncaught exception", err);
// Attempt to write a final message before exit
try {
const logFile = getLogFile();
if (logFile) {
fs.appendFileSync(logFile,
`[${new Date().toISOString()}] [FATAL] Process crashing due to uncaught exception\n`);
}
} catch {}
process.exit(1);
});
process.on("unhandledRejection", (reason) => {
fileLog("ERROR", "Unhandled promise rejection", reason instanceof Error ? reason : { reason });
});
// ── Entry Point ─────────────────────────────────────────────────────────────
const args = process.argv.slice(2);
const useWebUI = args.includes("--ui");
// Parse --port flag (only valid with --ui)
let port = 3000;
const portIndex = args.indexOf("--port");
if (portIndex !== -1 && args[portIndex + 1]) {
const parsedPort = parseInt(args[portIndex + 1], 10);
if (!isNaN(parsedPort) && parsedPort > 0 && parsedPort <= 65535) {
port = parsedPort;
} else {
console.error("Error: Invalid port number. Port must be between 1 and 65535.");
process.exit(1);
}
}
if (useWebUI) {
createWebApp(port).catch((err) => {
fileLog("ERROR", "Failed to start Web UI", err);
console.error("Failed to start Web UI:", err.message);
process.exit(1);
});
} else {
createApp();
}