@nexiq/cli 1.0.6 → 1.1.0
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/package.json +10 -2
- package/CHANGELOG.md +0 -19
- package/src/cli.tsx +0 -107
- package/src/components/CacheApp.tsx +0 -187
- package/src/components/HelpApp.tsx +0 -90
- package/src/components/StartApp.tsx +0 -125
- package/src/components/StatusApp.tsx +0 -116
- package/src/components/StopApp.tsx +0 -90
- package/src/components/ui.tsx +0 -128
- package/src/server-process.ts +0 -392
- package/src/ws.d.ts +0 -9
- package/tsconfig.json +0 -16
- package/tsup.config.ts +0 -49
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexiq/cli",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "CLI for the nexiq React analysis server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"meow": "^13.2.0",
|
|
24
24
|
"react": "^18.3.1",
|
|
25
25
|
"ws": "^8.20.0",
|
|
26
|
-
"@nexiq/server": "1.0
|
|
26
|
+
"@nexiq/server": "1.1.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^25.5.0",
|
|
@@ -31,6 +31,14 @@
|
|
|
31
31
|
"tsup": "^8.5.1",
|
|
32
32
|
"typescript": "^5.7.3"
|
|
33
33
|
},
|
|
34
|
+
"private": false,
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=20"
|
|
40
|
+
},
|
|
41
|
+
"prepublishOnly": "pnpm build",
|
|
34
42
|
"scripts": {
|
|
35
43
|
"build": "tsup",
|
|
36
44
|
"dev": "tsup --watch",
|
package/CHANGELOG.md
DELETED
package/src/cli.tsx
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* nexiq CLI entry point.
|
|
3
|
-
*
|
|
4
|
-
* Usage:
|
|
5
|
-
* nexiq start [--port 3030]
|
|
6
|
-
* nexiq stop
|
|
7
|
-
* nexiq status
|
|
8
|
-
* nexiq cache [clear [--force]]
|
|
9
|
-
* nexiq --help
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import React from "react";
|
|
13
|
-
import { render } from "ink";
|
|
14
|
-
import { StartApp } from "./components/StartApp.js";
|
|
15
|
-
import { StopApp } from "./components/StopApp.js";
|
|
16
|
-
import { StatusApp } from "./components/StatusApp.js";
|
|
17
|
-
import { CacheApp } from "./components/CacheApp.js";
|
|
18
|
-
import { HelpApp } from "./components/HelpApp.js";
|
|
19
|
-
import { startServerForeground, BACKEND_PORT } from "./server-process.js";
|
|
20
|
-
|
|
21
|
-
// ---------------------------------------------------------------------------
|
|
22
|
-
// Argument parsing (no external dependency)
|
|
23
|
-
// ---------------------------------------------------------------------------
|
|
24
|
-
|
|
25
|
-
const args = process.argv.slice(2);
|
|
26
|
-
|
|
27
|
-
function hasFlag(...flags: string[]): boolean {
|
|
28
|
-
return flags.some((f) => args.includes(f));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function getFlagValue(flag: string): string | undefined {
|
|
32
|
-
const idx = args.indexOf(flag);
|
|
33
|
-
if (idx !== -1 && idx + 1 < args.length) {
|
|
34
|
-
return args[idx + 1];
|
|
35
|
-
}
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Parse port from --port or PORT env var
|
|
40
|
-
const portStr = getFlagValue("--port") ?? process.env.PORT;
|
|
41
|
-
const port = portStr ? parseInt(portStr, 10) : BACKEND_PORT;
|
|
42
|
-
|
|
43
|
-
// ---------------------------------------------------------------------------
|
|
44
|
-
// Subcommand routing
|
|
45
|
-
// ---------------------------------------------------------------------------
|
|
46
|
-
|
|
47
|
-
async function run() {
|
|
48
|
-
const [command, subcommand] = args.filter((a) => !a.startsWith("-"));
|
|
49
|
-
|
|
50
|
-
// Foreground mode: used by Electron — skips the ink UI entirely so the
|
|
51
|
-
// process stays alive and writes directly to inherited stdio.
|
|
52
|
-
if (hasFlag("--foreground")) {
|
|
53
|
-
// Only valid for `start`
|
|
54
|
-
await startServerForeground(port);
|
|
55
|
-
process.exit(0);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (hasFlag("--help", "-h") || !command) {
|
|
59
|
-
const { waitUntilExit } = render(<HelpApp />);
|
|
60
|
-
await waitUntilExit();
|
|
61
|
-
process.exit(0);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
switch (command) {
|
|
65
|
-
case "start": {
|
|
66
|
-
const { waitUntilExit } = render(<StartApp port={port} />);
|
|
67
|
-
await waitUntilExit();
|
|
68
|
-
process.exit(0);
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
case "stop": {
|
|
73
|
-
const { waitUntilExit } = render(<StopApp port={port} />);
|
|
74
|
-
await waitUntilExit();
|
|
75
|
-
process.exit(0);
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
case "status": {
|
|
80
|
-
const { waitUntilExit } = render(<StatusApp port={port} />);
|
|
81
|
-
await waitUntilExit();
|
|
82
|
-
process.exit(0);
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
case "cache": {
|
|
87
|
-
const clear = subcommand === "clear";
|
|
88
|
-
const force = hasFlag("--force", "-f");
|
|
89
|
-
const { waitUntilExit } = render(<CacheApp clear={clear} force={force} />);
|
|
90
|
-
await waitUntilExit();
|
|
91
|
-
process.exit(0);
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
default: {
|
|
96
|
-
process.stderr.write(`Unknown command: ${command}\n\n`);
|
|
97
|
-
const { waitUntilExit } = render(<HelpApp />);
|
|
98
|
-
await waitUntilExit();
|
|
99
|
-
process.exit(1);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
run().catch((err) => {
|
|
105
|
-
console.error(err);
|
|
106
|
-
process.exit(1);
|
|
107
|
-
});
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
2
|
-
import { Box, Text, useApp, useInput } from "ink";
|
|
3
|
-
import Spinner from "ink-spinner";
|
|
4
|
-
import {
|
|
5
|
-
getCacheEntries,
|
|
6
|
-
clearCacheEntries,
|
|
7
|
-
formatBytes,
|
|
8
|
-
type CacheEntry,
|
|
9
|
-
} from "../server-process.js";
|
|
10
|
-
import {
|
|
11
|
-
COLORS,
|
|
12
|
-
NexiqBanner,
|
|
13
|
-
Divider,
|
|
14
|
-
SectionTitle,
|
|
15
|
-
} from "./ui.js";
|
|
16
|
-
|
|
17
|
-
interface CacheAppProps {
|
|
18
|
-
/** If true, clear cache without confirmation (use --force flag) */
|
|
19
|
-
clear?: boolean;
|
|
20
|
-
force?: boolean;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type Phase =
|
|
24
|
-
| "loading"
|
|
25
|
-
| "list"
|
|
26
|
-
| "confirm-clear"
|
|
27
|
-
| "clearing"
|
|
28
|
-
| "cleared"
|
|
29
|
-
| "no-cache"
|
|
30
|
-
| "error";
|
|
31
|
-
|
|
32
|
-
export function CacheApp({ clear = false, force = false }: CacheAppProps) {
|
|
33
|
-
const { exit } = useApp();
|
|
34
|
-
|
|
35
|
-
const [phase, setPhase] = useState<Phase>("loading");
|
|
36
|
-
const [entries, setEntries] = useState<CacheEntry[]>([]);
|
|
37
|
-
const [errorMsg, setErrorMsg] = useState("");
|
|
38
|
-
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
try {
|
|
41
|
-
const found = getCacheEntries();
|
|
42
|
-
setEntries(found);
|
|
43
|
-
|
|
44
|
-
if (found.length === 0) {
|
|
45
|
-
setPhase("no-cache");
|
|
46
|
-
setTimeout(() => exit(), 600);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (clear) {
|
|
51
|
-
if (force) {
|
|
52
|
-
// Clear immediately
|
|
53
|
-
setPhase("clearing");
|
|
54
|
-
clearCacheEntries(found);
|
|
55
|
-
setPhase("cleared");
|
|
56
|
-
setTimeout(() => exit(), 800);
|
|
57
|
-
} else {
|
|
58
|
-
setPhase("confirm-clear");
|
|
59
|
-
}
|
|
60
|
-
} else {
|
|
61
|
-
setPhase("list");
|
|
62
|
-
// Auto-exit after display
|
|
63
|
-
setTimeout(() => exit(), 5000);
|
|
64
|
-
}
|
|
65
|
-
} catch (e) {
|
|
66
|
-
setErrorMsg(e instanceof Error ? e.message : String(e));
|
|
67
|
-
setPhase("error");
|
|
68
|
-
setTimeout(() => exit(), 1200);
|
|
69
|
-
}
|
|
70
|
-
}, []);
|
|
71
|
-
|
|
72
|
-
// Handle keyboard for confirmation
|
|
73
|
-
useInput((input, key) => {
|
|
74
|
-
if (phase !== "confirm-clear") return;
|
|
75
|
-
|
|
76
|
-
if (input.toLowerCase() === "y") {
|
|
77
|
-
setPhase("clearing");
|
|
78
|
-
try {
|
|
79
|
-
clearCacheEntries(entries);
|
|
80
|
-
setPhase("cleared");
|
|
81
|
-
setTimeout(() => exit(), 800);
|
|
82
|
-
} catch (e) {
|
|
83
|
-
setErrorMsg(e instanceof Error ? e.message : String(e));
|
|
84
|
-
setPhase("error");
|
|
85
|
-
setTimeout(() => exit(), 1200);
|
|
86
|
-
}
|
|
87
|
-
} else if (input.toLowerCase() === "n" || key.escape) {
|
|
88
|
-
setPhase("list");
|
|
89
|
-
setTimeout(() => exit(), 600);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
const totalBytes = entries.reduce((sum, e) => sum + e.sizeBytes, 0);
|
|
94
|
-
|
|
95
|
-
return (
|
|
96
|
-
<Box flexDirection="column" padding={1}>
|
|
97
|
-
<NexiqBanner />
|
|
98
|
-
<SectionTitle title="Cache" />
|
|
99
|
-
|
|
100
|
-
{phase === "loading" && (
|
|
101
|
-
<Box gap={1}>
|
|
102
|
-
<Text color={COLORS.cyan}>
|
|
103
|
-
<Spinner type="dots" />
|
|
104
|
-
</Text>
|
|
105
|
-
<Text> Scanning cache…</Text>
|
|
106
|
-
</Box>
|
|
107
|
-
)}
|
|
108
|
-
|
|
109
|
-
{phase === "no-cache" && (
|
|
110
|
-
<Box marginTop={1}>
|
|
111
|
-
<Text color={COLORS.muted}>No cache entries found in ~/.nexiq/</Text>
|
|
112
|
-
</Box>
|
|
113
|
-
)}
|
|
114
|
-
|
|
115
|
-
{(phase === "list" || phase === "confirm-clear") && (
|
|
116
|
-
<Box flexDirection="column" marginTop={1}>
|
|
117
|
-
{entries.map((entry, i) => (
|
|
118
|
-
<Box key={i} flexDirection="column" marginBottom={0}>
|
|
119
|
-
<Box gap={2}>
|
|
120
|
-
<Box flexGrow={1}>
|
|
121
|
-
<Text color={COLORS.white} wrap="truncate">
|
|
122
|
-
{entry.label}
|
|
123
|
-
</Text>
|
|
124
|
-
</Box>
|
|
125
|
-
<Text color={COLORS.muted}>{formatBytes(entry.sizeBytes)}</Text>
|
|
126
|
-
<Text color={COLORS.muted}>
|
|
127
|
-
{entry.lastModified.toLocaleDateString()}
|
|
128
|
-
</Text>
|
|
129
|
-
</Box>
|
|
130
|
-
</Box>
|
|
131
|
-
))}
|
|
132
|
-
|
|
133
|
-
<Divider />
|
|
134
|
-
<Box gap={2}>
|
|
135
|
-
<Text color={COLORS.cyan} bold>
|
|
136
|
-
{entries.length} entries
|
|
137
|
-
</Text>
|
|
138
|
-
<Text color={COLORS.muted}>{formatBytes(totalBytes)} total</Text>
|
|
139
|
-
</Box>
|
|
140
|
-
|
|
141
|
-
{phase === "confirm-clear" && (
|
|
142
|
-
<Box flexDirection="column" marginTop={1}>
|
|
143
|
-
<Text color={COLORS.yellow} bold>
|
|
144
|
-
⚠ Clear all cache? This cannot be undone. (y/N)
|
|
145
|
-
</Text>
|
|
146
|
-
</Box>
|
|
147
|
-
)}
|
|
148
|
-
|
|
149
|
-
{phase === "list" && !clear && (
|
|
150
|
-
<Box marginTop={1}>
|
|
151
|
-
<Text color={COLORS.muted}>
|
|
152
|
-
Run{" "}
|
|
153
|
-
<Text color={COLORS.accent} bold>
|
|
154
|
-
nexiq cache clear
|
|
155
|
-
</Text>{" "}
|
|
156
|
-
to remove all entries.
|
|
157
|
-
</Text>
|
|
158
|
-
</Box>
|
|
159
|
-
)}
|
|
160
|
-
</Box>
|
|
161
|
-
)}
|
|
162
|
-
|
|
163
|
-
{phase === "clearing" && (
|
|
164
|
-
<Box gap={1} marginTop={1}>
|
|
165
|
-
<Text color={COLORS.cyan}>
|
|
166
|
-
<Spinner type="dots" />
|
|
167
|
-
</Text>
|
|
168
|
-
<Text> Clearing…</Text>
|
|
169
|
-
</Box>
|
|
170
|
-
)}
|
|
171
|
-
|
|
172
|
-
{phase === "cleared" && (
|
|
173
|
-
<Box marginTop={1}>
|
|
174
|
-
<Text color={COLORS.green} bold>
|
|
175
|
-
✓ Cache cleared ({entries.length} entries, {formatBytes(totalBytes)})
|
|
176
|
-
</Text>
|
|
177
|
-
</Box>
|
|
178
|
-
)}
|
|
179
|
-
|
|
180
|
-
{phase === "error" && (
|
|
181
|
-
<Box marginTop={1}>
|
|
182
|
-
<Text color={COLORS.red}>{errorMsg}</Text>
|
|
183
|
-
</Box>
|
|
184
|
-
)}
|
|
185
|
-
</Box>
|
|
186
|
-
);
|
|
187
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from "react";
|
|
2
|
-
import { Box, Text, useApp } from "ink";
|
|
3
|
-
import { COLORS, NexiqBanner, Divider } from "./ui.js";
|
|
4
|
-
|
|
5
|
-
interface Command {
|
|
6
|
-
usage: string;
|
|
7
|
-
description: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const COMMANDS: Command[] = [
|
|
11
|
-
{
|
|
12
|
-
usage: "nexiq start",
|
|
13
|
-
description: "Start the nexiq backend server (runs in background)",
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
usage: "nexiq stop",
|
|
17
|
-
description: "Stop the running backend server",
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
usage: "nexiq status",
|
|
21
|
-
description: "Show server health, port, PID, and uptime",
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
usage: "nexiq cache",
|
|
25
|
-
description: "List all project cache entries and their disk usage",
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
usage: "nexiq cache clear",
|
|
29
|
-
description: "Remove all project caches (prompts for confirmation)",
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
usage: "nexiq cache clear --force",
|
|
33
|
-
description: "Remove all project caches without confirmation",
|
|
34
|
-
},
|
|
35
|
-
];
|
|
36
|
-
|
|
37
|
-
export function HelpApp() {
|
|
38
|
-
const { exit } = useApp();
|
|
39
|
-
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
setTimeout(() => exit(), 8000);
|
|
42
|
-
}, []);
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<Box flexDirection="column" padding={1}>
|
|
46
|
-
<NexiqBanner />
|
|
47
|
-
|
|
48
|
-
<Box marginBottom={1}>
|
|
49
|
-
<Text color={COLORS.muted}>
|
|
50
|
-
React component analysis server — CLI management tool
|
|
51
|
-
</Text>
|
|
52
|
-
</Box>
|
|
53
|
-
|
|
54
|
-
<Divider />
|
|
55
|
-
|
|
56
|
-
<Box flexDirection="column" marginTop={1} gap={0}>
|
|
57
|
-
{COMMANDS.map((cmd, i) => (
|
|
58
|
-
<Box key={i} flexDirection="column" marginBottom={1}>
|
|
59
|
-
<Text color={COLORS.accent} bold>
|
|
60
|
-
{cmd.usage}
|
|
61
|
-
</Text>
|
|
62
|
-
<Box marginLeft={2}>
|
|
63
|
-
<Text color={COLORS.muted}>{cmd.description}</Text>
|
|
64
|
-
</Box>
|
|
65
|
-
</Box>
|
|
66
|
-
))}
|
|
67
|
-
</Box>
|
|
68
|
-
|
|
69
|
-
<Divider />
|
|
70
|
-
|
|
71
|
-
<Box marginTop={1} flexDirection="column" gap={0}>
|
|
72
|
-
<Text color={COLORS.cyan} bold>
|
|
73
|
-
Environment variables
|
|
74
|
-
</Text>
|
|
75
|
-
<Box marginLeft={2} flexDirection="column">
|
|
76
|
-
<Box gap={1}>
|
|
77
|
-
<Text color={COLORS.yellow}>REACT_MAP_SERVER_PATH</Text>
|
|
78
|
-
<Text color={COLORS.muted}>Override path to server dist/index.js</Text>
|
|
79
|
-
</Box>
|
|
80
|
-
<Box gap={1}>
|
|
81
|
-
<Text color={COLORS.yellow}>PORT</Text>
|
|
82
|
-
<Text color={COLORS.muted}>
|
|
83
|
-
WebSocket port (default: 3030)
|
|
84
|
-
</Text>
|
|
85
|
-
</Box>
|
|
86
|
-
</Box>
|
|
87
|
-
</Box>
|
|
88
|
-
</Box>
|
|
89
|
-
);
|
|
90
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
2
|
-
import { Box, Text, useApp } from "ink";
|
|
3
|
-
import Spinner from "ink-spinner";
|
|
4
|
-
import {
|
|
5
|
-
isServerAlive,
|
|
6
|
-
startServerDetached,
|
|
7
|
-
BACKEND_PORT,
|
|
8
|
-
} from "../server-process.js";
|
|
9
|
-
import { COLORS, NexiqBanner, KvRow, StatusDot } from "./ui.js";
|
|
10
|
-
|
|
11
|
-
interface StartAppProps {
|
|
12
|
-
port?: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
type Phase = "checking" | "starting" | "done" | "error";
|
|
16
|
-
|
|
17
|
-
export function StartApp({ port = BACKEND_PORT }: StartAppProps) {
|
|
18
|
-
const { exit } = useApp();
|
|
19
|
-
|
|
20
|
-
const [phase, setPhase] = useState<Phase>("checking");
|
|
21
|
-
const [message, setMessage] = useState("");
|
|
22
|
-
const [pid, setPid] = useState<number | undefined>();
|
|
23
|
-
const [alreadyRunning, setAlreadyRunning] = useState(false);
|
|
24
|
-
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
let cancelled = false;
|
|
27
|
-
|
|
28
|
-
async function run() {
|
|
29
|
-
// Phase 1: check if already alive
|
|
30
|
-
const alive = await isServerAlive(port);
|
|
31
|
-
if (cancelled) return;
|
|
32
|
-
|
|
33
|
-
if (alive) {
|
|
34
|
-
setAlreadyRunning(true);
|
|
35
|
-
setPhase("done");
|
|
36
|
-
setMessage(`Server is already running on ws://localhost:${port}`);
|
|
37
|
-
setTimeout(() => exit(), 600);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Phase 2: start detached
|
|
42
|
-
setPhase("starting");
|
|
43
|
-
const result = await startServerDetached(port);
|
|
44
|
-
if (cancelled) return;
|
|
45
|
-
|
|
46
|
-
if (result.ok) {
|
|
47
|
-
setPid(result.pid);
|
|
48
|
-
setPhase("done");
|
|
49
|
-
setMessage(`Server started on ws://localhost:${port}`);
|
|
50
|
-
} else {
|
|
51
|
-
setPhase("error");
|
|
52
|
-
setMessage(result.error ?? "Unknown error");
|
|
53
|
-
}
|
|
54
|
-
setTimeout(() => exit(), result.ok ? 800 : 1200);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
run().catch((e) => {
|
|
58
|
-
if (!cancelled) {
|
|
59
|
-
setPhase("error");
|
|
60
|
-
setMessage(e instanceof Error ? e.message : String(e));
|
|
61
|
-
setTimeout(() => exit(), 1200);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return () => {
|
|
66
|
-
cancelled = true;
|
|
67
|
-
};
|
|
68
|
-
}, []);
|
|
69
|
-
|
|
70
|
-
return (
|
|
71
|
-
<Box flexDirection="column" padding={1}>
|
|
72
|
-
<NexiqBanner />
|
|
73
|
-
|
|
74
|
-
{phase === "checking" && (
|
|
75
|
-
<Box>
|
|
76
|
-
<Text color={COLORS.cyan}>
|
|
77
|
-
<Spinner type="dots" />
|
|
78
|
-
</Text>
|
|
79
|
-
<Text> Checking server…</Text>
|
|
80
|
-
</Box>
|
|
81
|
-
)}
|
|
82
|
-
|
|
83
|
-
{phase === "starting" && (
|
|
84
|
-
<Box>
|
|
85
|
-
<Text color={COLORS.cyan}>
|
|
86
|
-
<Spinner type="dots" />
|
|
87
|
-
</Text>
|
|
88
|
-
<Text> Starting server on port {port}…</Text>
|
|
89
|
-
</Box>
|
|
90
|
-
)}
|
|
91
|
-
|
|
92
|
-
{phase === "done" && (
|
|
93
|
-
<Box flexDirection="column" gap={0}>
|
|
94
|
-
<Box gap={1}>
|
|
95
|
-
<StatusDot running={true} />
|
|
96
|
-
<Text color={COLORS.green} bold>
|
|
97
|
-
{alreadyRunning ? "Already running" : "Server started"}
|
|
98
|
-
</Text>
|
|
99
|
-
</Box>
|
|
100
|
-
<KvRow label="Address" value={`ws://localhost:${port}`} />
|
|
101
|
-
{pid !== undefined && (
|
|
102
|
-
<KvRow label="PID" value={String(pid)} />
|
|
103
|
-
)}
|
|
104
|
-
<Box marginTop={1}>
|
|
105
|
-
<Text color={COLORS.muted}>{message}</Text>
|
|
106
|
-
</Box>
|
|
107
|
-
</Box>
|
|
108
|
-
)}
|
|
109
|
-
|
|
110
|
-
{phase === "error" && (
|
|
111
|
-
<Box flexDirection="column" gap={0}>
|
|
112
|
-
<Box gap={1}>
|
|
113
|
-
<StatusDot running={false} />
|
|
114
|
-
<Text color={COLORS.red} bold>
|
|
115
|
-
Failed to start server
|
|
116
|
-
</Text>
|
|
117
|
-
</Box>
|
|
118
|
-
<Box marginTop={1}>
|
|
119
|
-
<Text color={COLORS.red}>{message}</Text>
|
|
120
|
-
</Box>
|
|
121
|
-
</Box>
|
|
122
|
-
)}
|
|
123
|
-
</Box>
|
|
124
|
-
);
|
|
125
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
2
|
-
import { Box, Text, useApp } from "ink";
|
|
3
|
-
import Spinner from "ink-spinner";
|
|
4
|
-
import {
|
|
5
|
-
getServerStatus,
|
|
6
|
-
resolveServerDist,
|
|
7
|
-
BACKEND_PORT,
|
|
8
|
-
formatDuration,
|
|
9
|
-
type ServerStatus,
|
|
10
|
-
} from "../server-process.js";
|
|
11
|
-
import {
|
|
12
|
-
COLORS,
|
|
13
|
-
NexiqBanner,
|
|
14
|
-
KvRow,
|
|
15
|
-
StatusDot,
|
|
16
|
-
Divider,
|
|
17
|
-
SectionTitle,
|
|
18
|
-
} from "./ui.js";
|
|
19
|
-
|
|
20
|
-
interface StatusAppProps {
|
|
21
|
-
port?: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function StatusApp({ port = BACKEND_PORT }: StatusAppProps) {
|
|
25
|
-
const { exit } = useApp();
|
|
26
|
-
|
|
27
|
-
const [status, setStatus] = useState<ServerStatus | null>(null);
|
|
28
|
-
const [loading, setLoading] = useState(true);
|
|
29
|
-
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
let cancelled = false;
|
|
32
|
-
|
|
33
|
-
getServerStatus(port).then((s) => {
|
|
34
|
-
if (!cancelled) {
|
|
35
|
-
setStatus(s);
|
|
36
|
-
setLoading(false);
|
|
37
|
-
setTimeout(() => exit(), 800);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
return () => {
|
|
42
|
-
cancelled = true;
|
|
43
|
-
};
|
|
44
|
-
}, []);
|
|
45
|
-
|
|
46
|
-
return (
|
|
47
|
-
<Box flexDirection="column" padding={1}>
|
|
48
|
-
<NexiqBanner />
|
|
49
|
-
<SectionTitle title="Server Status" />
|
|
50
|
-
|
|
51
|
-
{loading && (
|
|
52
|
-
<Box gap={1}>
|
|
53
|
-
<Text color={COLORS.cyan}>
|
|
54
|
-
<Spinner type="dots" />
|
|
55
|
-
</Text>
|
|
56
|
-
<Text> Checking…</Text>
|
|
57
|
-
</Box>
|
|
58
|
-
)}
|
|
59
|
-
|
|
60
|
-
{!loading && status && (
|
|
61
|
-
<Box flexDirection="column" marginTop={1}>
|
|
62
|
-
{/* Running indicator */}
|
|
63
|
-
<Box gap={1} marginBottom={1}>
|
|
64
|
-
<StatusDot running={status.running} />
|
|
65
|
-
<Text color={status.running ? COLORS.green : COLORS.red} bold>
|
|
66
|
-
{status.running ? "Running" : "Stopped"}
|
|
67
|
-
</Text>
|
|
68
|
-
</Box>
|
|
69
|
-
|
|
70
|
-
<Divider />
|
|
71
|
-
|
|
72
|
-
{status.running && (
|
|
73
|
-
<>
|
|
74
|
-
{status.port !== undefined && (
|
|
75
|
-
<KvRow
|
|
76
|
-
label="Port"
|
|
77
|
-
value={String(status.port)}
|
|
78
|
-
valueColor={COLORS.cyan}
|
|
79
|
-
/>
|
|
80
|
-
)}
|
|
81
|
-
{status.pid !== undefined && (
|
|
82
|
-
<KvRow label="PID" value={String(status.pid)} />
|
|
83
|
-
)}
|
|
84
|
-
{status.uptimeMs !== undefined && (
|
|
85
|
-
<KvRow
|
|
86
|
-
label="Uptime"
|
|
87
|
-
value={formatDuration(status.uptimeMs)}
|
|
88
|
-
valueColor={COLORS.green}
|
|
89
|
-
/>
|
|
90
|
-
)}
|
|
91
|
-
</>
|
|
92
|
-
)}
|
|
93
|
-
|
|
94
|
-
<KvRow
|
|
95
|
-
label="Server dist"
|
|
96
|
-
value={status.serverDist ?? "(not found)"}
|
|
97
|
-
valueColor={status.serverDist ? COLORS.muted : COLORS.red}
|
|
98
|
-
/>
|
|
99
|
-
<KvRow label="Log file" value={status.logFile} valueColor={COLORS.muted} />
|
|
100
|
-
|
|
101
|
-
{!status.running && (
|
|
102
|
-
<Box marginTop={1}>
|
|
103
|
-
<Text color={COLORS.muted}>
|
|
104
|
-
Run{" "}
|
|
105
|
-
<Text color={COLORS.accent} bold>
|
|
106
|
-
nexiq start
|
|
107
|
-
</Text>{" "}
|
|
108
|
-
to launch the server.
|
|
109
|
-
</Text>
|
|
110
|
-
</Box>
|
|
111
|
-
)}
|
|
112
|
-
</Box>
|
|
113
|
-
)}
|
|
114
|
-
</Box>
|
|
115
|
-
);
|
|
116
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
2
|
-
import { Box, Text, useApp } from "ink";
|
|
3
|
-
import Spinner from "ink-spinner";
|
|
4
|
-
import { stopServer, BACKEND_PORT } from "../server-process.js";
|
|
5
|
-
import { COLORS, NexiqBanner, StatusDot } from "./ui.js";
|
|
6
|
-
|
|
7
|
-
interface StopAppProps {
|
|
8
|
-
port?: number;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
type Phase = "stopping" | "done" | "error";
|
|
12
|
-
|
|
13
|
-
export function StopApp({ port = BACKEND_PORT }: StopAppProps) {
|
|
14
|
-
const { exit } = useApp();
|
|
15
|
-
|
|
16
|
-
const [phase, setPhase] = useState<Phase>("stopping");
|
|
17
|
-
const [message, setMessage] = useState("");
|
|
18
|
-
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
let cancelled = false;
|
|
21
|
-
|
|
22
|
-
async function run() {
|
|
23
|
-
const result = await stopServer();
|
|
24
|
-
if (cancelled) return;
|
|
25
|
-
|
|
26
|
-
if (result.ok) {
|
|
27
|
-
setPhase("done");
|
|
28
|
-
} else {
|
|
29
|
-
setPhase("error");
|
|
30
|
-
}
|
|
31
|
-
setMessage(result.message);
|
|
32
|
-
setTimeout(() => exit(), 800);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
run().catch((e) => {
|
|
36
|
-
if (!cancelled) {
|
|
37
|
-
setPhase("error");
|
|
38
|
-
setMessage(e instanceof Error ? e.message : String(e));
|
|
39
|
-
setTimeout(() => exit(), 1000);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
return () => {
|
|
44
|
-
cancelled = true;
|
|
45
|
-
};
|
|
46
|
-
}, []);
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<Box flexDirection="column" padding={1}>
|
|
50
|
-
<NexiqBanner />
|
|
51
|
-
|
|
52
|
-
{phase === "stopping" && (
|
|
53
|
-
<Box>
|
|
54
|
-
<Text color={COLORS.cyan}>
|
|
55
|
-
<Spinner type="dots" />
|
|
56
|
-
</Text>
|
|
57
|
-
<Text> Stopping server…</Text>
|
|
58
|
-
</Box>
|
|
59
|
-
)}
|
|
60
|
-
|
|
61
|
-
{phase === "done" && (
|
|
62
|
-
<Box flexDirection="column">
|
|
63
|
-
<Box gap={1}>
|
|
64
|
-
<StatusDot running={false} />
|
|
65
|
-
<Text color={COLORS.green} bold>
|
|
66
|
-
Stopped
|
|
67
|
-
</Text>
|
|
68
|
-
</Box>
|
|
69
|
-
<Box marginTop={1}>
|
|
70
|
-
<Text color={COLORS.muted}>{message}</Text>
|
|
71
|
-
</Box>
|
|
72
|
-
</Box>
|
|
73
|
-
)}
|
|
74
|
-
|
|
75
|
-
{phase === "error" && (
|
|
76
|
-
<Box flexDirection="column">
|
|
77
|
-
<Box gap={1}>
|
|
78
|
-
<StatusDot running={false} />
|
|
79
|
-
<Text color={COLORS.red} bold>
|
|
80
|
-
Error
|
|
81
|
-
</Text>
|
|
82
|
-
</Box>
|
|
83
|
-
<Box marginTop={1}>
|
|
84
|
-
<Text color={COLORS.red}>{message}</Text>
|
|
85
|
-
</Box>
|
|
86
|
-
</Box>
|
|
87
|
-
)}
|
|
88
|
-
</Box>
|
|
89
|
-
);
|
|
90
|
-
}
|
package/src/components/ui.tsx
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared Ink UI primitives — colours, badges, borders.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import React from "react";
|
|
6
|
-
import { Box, Text } from "ink";
|
|
7
|
-
|
|
8
|
-
// ---------------------------------------------------------------------------
|
|
9
|
-
// Colour palette
|
|
10
|
-
// ---------------------------------------------------------------------------
|
|
11
|
-
export const COLORS = {
|
|
12
|
-
green: "#22c55e",
|
|
13
|
-
red: "#ef4444",
|
|
14
|
-
yellow: "#eab308",
|
|
15
|
-
blue: "#3b82f6",
|
|
16
|
-
cyan: "#06b6d4",
|
|
17
|
-
muted: "#6b7280",
|
|
18
|
-
white: "#f9fafb",
|
|
19
|
-
accent: "#a855f7",
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// ---------------------------------------------------------------------------
|
|
23
|
-
// Badge
|
|
24
|
-
// ---------------------------------------------------------------------------
|
|
25
|
-
|
|
26
|
-
interface BadgeProps {
|
|
27
|
-
label: string;
|
|
28
|
-
color: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function Badge({ label, color }: BadgeProps) {
|
|
32
|
-
return (
|
|
33
|
-
<Box>
|
|
34
|
-
<Text color={color} bold>
|
|
35
|
-
{" "}
|
|
36
|
-
{label}{" "}
|
|
37
|
-
</Text>
|
|
38
|
-
</Box>
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// ---------------------------------------------------------------------------
|
|
43
|
-
// Status dot
|
|
44
|
-
// ---------------------------------------------------------------------------
|
|
45
|
-
|
|
46
|
-
interface StatusDotProps {
|
|
47
|
-
running: boolean;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function StatusDot({ running }: StatusDotProps) {
|
|
51
|
-
return (
|
|
52
|
-
<Text color={running ? COLORS.green : COLORS.red} bold>
|
|
53
|
-
{running ? "●" : "○"}
|
|
54
|
-
</Text>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// ---------------------------------------------------------------------------
|
|
59
|
-
// Section title
|
|
60
|
-
// ---------------------------------------------------------------------------
|
|
61
|
-
|
|
62
|
-
interface SectionTitleProps {
|
|
63
|
-
title: string;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function SectionTitle({ title }: SectionTitleProps) {
|
|
67
|
-
return (
|
|
68
|
-
<Box marginTop={1} marginBottom={0}>
|
|
69
|
-
<Text color={COLORS.cyan} bold>
|
|
70
|
-
── {title} ──
|
|
71
|
-
</Text>
|
|
72
|
-
</Box>
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// ---------------------------------------------------------------------------
|
|
77
|
-
// Key-value row
|
|
78
|
-
// ---------------------------------------------------------------------------
|
|
79
|
-
|
|
80
|
-
interface KvRowProps {
|
|
81
|
-
label: string;
|
|
82
|
-
value: string;
|
|
83
|
-
labelWidth?: number;
|
|
84
|
-
valueColor?: string;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function KvRow({ label, value, labelWidth = 14, valueColor = COLORS.white }: KvRowProps) {
|
|
88
|
-
return (
|
|
89
|
-
<Box>
|
|
90
|
-
<Box width={labelWidth}>
|
|
91
|
-
<Text color={COLORS.muted}>{label}</Text>
|
|
92
|
-
</Box>
|
|
93
|
-
<Text color={valueColor}>{value}</Text>
|
|
94
|
-
</Box>
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// ---------------------------------------------------------------------------
|
|
99
|
-
// Header banner
|
|
100
|
-
// ---------------------------------------------------------------------------
|
|
101
|
-
|
|
102
|
-
export function NexiqBanner() {
|
|
103
|
-
return (
|
|
104
|
-
<Box flexDirection="column" marginBottom={1}>
|
|
105
|
-
<Text color={COLORS.accent} bold>
|
|
106
|
-
╔══════════════════════════╗
|
|
107
|
-
</Text>
|
|
108
|
-
<Text color={COLORS.accent} bold>
|
|
109
|
-
║ nexiq server CLI ║
|
|
110
|
-
</Text>
|
|
111
|
-
<Text color={COLORS.accent} bold>
|
|
112
|
-
╚══════════════════════════╝
|
|
113
|
-
</Text>
|
|
114
|
-
</Box>
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// ---------------------------------------------------------------------------
|
|
119
|
-
// Divider
|
|
120
|
-
// ---------------------------------------------------------------------------
|
|
121
|
-
|
|
122
|
-
export function Divider() {
|
|
123
|
-
return (
|
|
124
|
-
<Box marginY={0}>
|
|
125
|
-
<Text color={COLORS.muted}>{"─".repeat(36)}</Text>
|
|
126
|
-
</Box>
|
|
127
|
-
);
|
|
128
|
-
}
|
package/src/server-process.ts
DELETED
|
@@ -1,392 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utilities for managing the nexiq backend server process:
|
|
3
|
-
* - Resolving the server binary path
|
|
4
|
-
* - Starting / stopping the server (foreground or detached)
|
|
5
|
-
* - Querying health via WebSocket ping
|
|
6
|
-
* - Cache inspection / clearing
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import fs from "node:fs";
|
|
10
|
-
import path from "node:path";
|
|
11
|
-
import os from "node:os";
|
|
12
|
-
import { spawn, execSync } from "node:child_process";
|
|
13
|
-
import { createRequire } from "node:module";
|
|
14
|
-
import { WebSocket } from "ws";
|
|
15
|
-
import net from "node:net";
|
|
16
|
-
|
|
17
|
-
export const BACKEND_PORT = 3030;
|
|
18
|
-
|
|
19
|
-
// ~/.nexiq/ is the global cache root used by the server
|
|
20
|
-
const GLOBAL_NEXIQ_DIR = path.join(os.homedir(), ".nexiq");
|
|
21
|
-
const PID_FILE = path.join(GLOBAL_NEXIQ_DIR, "server.pid");
|
|
22
|
-
const LOG_FILE = path.join(GLOBAL_NEXIQ_DIR, "server.log");
|
|
23
|
-
|
|
24
|
-
// ---------------------------------------------------------------------------
|
|
25
|
-
// Server binary resolution
|
|
26
|
-
// ---------------------------------------------------------------------------
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Resolve the path to the compiled server `index.js`.
|
|
30
|
-
*/
|
|
31
|
-
export function resolveServerDist(): string | null {
|
|
32
|
-
// 1. Env override
|
|
33
|
-
if (process.env.REACT_MAP_SERVER_PATH) {
|
|
34
|
-
return process.env.REACT_MAP_SERVER_PATH;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// 2. Monorepo sibling path
|
|
38
|
-
// We try multiple ways to get the current file directory
|
|
39
|
-
let currentDir = "";
|
|
40
|
-
try {
|
|
41
|
-
currentDir = path.dirname(new URL(import.meta.url).pathname);
|
|
42
|
-
} catch {
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
currentDir = typeof __dirname !== "undefined" ? __dirname : process.cwd();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const siblingPath = path.resolve(
|
|
48
|
-
currentDir,
|
|
49
|
-
"../../..", // dist/cli.js -> dist -> cli -> packages -> nexiq root
|
|
50
|
-
"server",
|
|
51
|
-
"dist",
|
|
52
|
-
"index.js",
|
|
53
|
-
);
|
|
54
|
-
if (fs.existsSync(siblingPath)) {
|
|
55
|
-
return siblingPath;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// 3. Resolve from installed @nexiq/server package
|
|
59
|
-
try {
|
|
60
|
-
const require = createRequire(import.meta.url || `file://${process.cwd()}/index.js`);
|
|
61
|
-
const resolved = require.resolve("@nexiq/server");
|
|
62
|
-
if (fs.existsSync(resolved)) return resolved;
|
|
63
|
-
} catch {
|
|
64
|
-
// not installed
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// ---------------------------------------------------------------------------
|
|
71
|
-
// Port check
|
|
72
|
-
// ---------------------------------------------------------------------------
|
|
73
|
-
|
|
74
|
-
export async function isPortOpen(port: number, host = "127.0.0.1"): Promise<boolean> {
|
|
75
|
-
return new Promise((resolve) => {
|
|
76
|
-
const socket = new net.Socket();
|
|
77
|
-
const onError = () => {
|
|
78
|
-
socket.destroy();
|
|
79
|
-
resolve(false);
|
|
80
|
-
};
|
|
81
|
-
socket.setTimeout(400);
|
|
82
|
-
socket.once("error", onError);
|
|
83
|
-
socket.once("timeout", onError);
|
|
84
|
-
socket.connect(port, host, () => {
|
|
85
|
-
socket.destroy();
|
|
86
|
-
resolve(true);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export async function isServerAlive(port: number = BACKEND_PORT): Promise<boolean> {
|
|
92
|
-
return new Promise((resolve) => {
|
|
93
|
-
const ws = new WebSocket(`ws://127.0.0.1:${port}`);
|
|
94
|
-
const timeout = setTimeout(() => {
|
|
95
|
-
ws.terminate();
|
|
96
|
-
resolve(false);
|
|
97
|
-
}, 600);
|
|
98
|
-
|
|
99
|
-
ws.on("open", () => {
|
|
100
|
-
clearTimeout(timeout);
|
|
101
|
-
ws.terminate();
|
|
102
|
-
resolve(true);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
ws.on("error", () => {
|
|
106
|
-
clearTimeout(timeout);
|
|
107
|
-
resolve(false);
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// ---------------------------------------------------------------------------
|
|
113
|
-
// PID file helpers
|
|
114
|
-
// ---------------------------------------------------------------------------
|
|
115
|
-
|
|
116
|
-
function ensureNexiqDir() {
|
|
117
|
-
if (!fs.existsSync(GLOBAL_NEXIQ_DIR)) {
|
|
118
|
-
fs.mkdirSync(GLOBAL_NEXIQ_DIR, { recursive: true });
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function writePid(pid: number) {
|
|
123
|
-
ensureNexiqDir();
|
|
124
|
-
fs.writeFileSync(PID_FILE, `${pid}\n`, "utf8");
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function readPid(): number | null {
|
|
128
|
-
if (!fs.existsSync(PID_FILE)) return null;
|
|
129
|
-
const raw = fs.readFileSync(PID_FILE, "utf8").trim();
|
|
130
|
-
const pid = parseInt(raw, 10);
|
|
131
|
-
return isNaN(pid) ? null : pid;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function clearPid() {
|
|
135
|
-
if (fs.existsSync(PID_FILE)) {
|
|
136
|
-
fs.unlinkSync(PID_FILE);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function isPidAlive(pid: number): boolean {
|
|
141
|
-
try {
|
|
142
|
-
// Signal 0 = check existence without sending a real signal
|
|
143
|
-
process.kill(pid, 0);
|
|
144
|
-
return true;
|
|
145
|
-
} catch {
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function pidFileModifiedAt(): Date | null {
|
|
151
|
-
if (!fs.existsSync(PID_FILE)) return null;
|
|
152
|
-
return fs.statSync(PID_FILE).mtime;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// ---------------------------------------------------------------------------
|
|
156
|
-
// Start / Stop
|
|
157
|
-
// ---------------------------------------------------------------------------
|
|
158
|
-
|
|
159
|
-
export interface StartResult {
|
|
160
|
-
ok: boolean;
|
|
161
|
-
pid?: number;
|
|
162
|
-
port?: number;
|
|
163
|
-
alreadyRunning?: boolean;
|
|
164
|
-
error?: string;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Start the server in the foreground (no detach).
|
|
169
|
-
* The process stays alive as long as the CLI is running.
|
|
170
|
-
* Callers that want daemon mode should use startDetached().
|
|
171
|
-
*/
|
|
172
|
-
export async function startServerForeground(port: number = BACKEND_PORT): Promise<never> {
|
|
173
|
-
const serverDist = resolveServerDist();
|
|
174
|
-
if (!serverDist) {
|
|
175
|
-
console.error("Could not find the nexiq server. Please build it first (pnpm build).");
|
|
176
|
-
process.exit(1);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const child = spawn("node", [serverDist], {
|
|
180
|
-
stdio: ["inherit", "inherit", "inherit", "ipc"],
|
|
181
|
-
env: { ...process.env, PORT: String(port), NODE_ENV: "production" },
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
child.on("error", (err) => {
|
|
185
|
-
console.error("Server failed to start:", err.message);
|
|
186
|
-
process.exit(1);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
await new Promise<void>((_, reject) =>
|
|
190
|
-
child.on("exit", (code) => reject(new Error(`Server exited with code ${code}`))),
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
process.exit(0);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Start the server detached (daemon mode) — writes PID file.
|
|
198
|
-
*/
|
|
199
|
-
export async function startServerDetached(port: number = BACKEND_PORT): Promise<StartResult> {
|
|
200
|
-
// Already alive?
|
|
201
|
-
if (await isServerAlive(port)) {
|
|
202
|
-
const pid = readPid();
|
|
203
|
-
return { ok: true, alreadyRunning: true, pid: pid ?? undefined, port };
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const serverDist = resolveServerDist();
|
|
207
|
-
if (!serverDist) {
|
|
208
|
-
return { ok: false, error: "Could not find the nexiq server binary. Run `pnpm build` in packages/server first." };
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
ensureNexiqDir();
|
|
212
|
-
|
|
213
|
-
const logStream = fs.openSync(LOG_FILE, "a");
|
|
214
|
-
|
|
215
|
-
const child = spawn("node", [serverDist], {
|
|
216
|
-
detached: true,
|
|
217
|
-
stdio: ["ignore", logStream, logStream, "ipc"],
|
|
218
|
-
env: { ...process.env, PORT: String(port), NODE_ENV: "production" },
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
const pid = child.pid;
|
|
222
|
-
if (!pid) {
|
|
223
|
-
return { ok: false, error: "Failed to get PID from spawned process" };
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
child.unref();
|
|
227
|
-
writePid(pid);
|
|
228
|
-
|
|
229
|
-
// Wait up to 4s for the server to be reachable
|
|
230
|
-
const start = Date.now();
|
|
231
|
-
while (Date.now() - start < 4000) {
|
|
232
|
-
await sleep(300);
|
|
233
|
-
if (await isServerAlive(port)) {
|
|
234
|
-
return { ok: true, pid, port };
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// Server didn't come up — clean up
|
|
239
|
-
clearPid();
|
|
240
|
-
return { ok: false, error: "Server started but did not become reachable within 4s. Check ~/.nexiq/server.log" };
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export interface StopResult {
|
|
244
|
-
ok: boolean;
|
|
245
|
-
message: string;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export async function stopServer(): Promise<StopResult> {
|
|
249
|
-
const pid = readPid();
|
|
250
|
-
|
|
251
|
-
if (!pid) {
|
|
252
|
-
// Check if something is on the port even without a PID file
|
|
253
|
-
if (await isServerAlive()) {
|
|
254
|
-
return { ok: false, message: "Server appears to be running but no PID file found. Stop it manually." };
|
|
255
|
-
}
|
|
256
|
-
return { ok: true, message: "Server is not running." };
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
if (!isPidAlive(pid)) {
|
|
260
|
-
clearPid();
|
|
261
|
-
return { ok: true, message: `Server (PID ${pid}) was already stopped. Cleaned up PID file.` };
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
try {
|
|
265
|
-
process.kill(pid, "SIGTERM");
|
|
266
|
-
// Wait up to 3s for it to die
|
|
267
|
-
const start = Date.now();
|
|
268
|
-
while (Date.now() - start < 3000) {
|
|
269
|
-
await sleep(200);
|
|
270
|
-
if (!isPidAlive(pid)) break;
|
|
271
|
-
}
|
|
272
|
-
clearPid();
|
|
273
|
-
return { ok: true, message: `Server (PID ${pid}) stopped.` };
|
|
274
|
-
} catch (err) {
|
|
275
|
-
return { ok: false, message: `Failed to stop server: ${err instanceof Error ? err.message : String(err)}` };
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
export interface ServerStatus {
|
|
280
|
-
running: boolean;
|
|
281
|
-
pid?: number;
|
|
282
|
-
port?: number;
|
|
283
|
-
uptimeMs?: number;
|
|
284
|
-
serverDist: string | null;
|
|
285
|
-
logFile: string;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
export async function getServerStatus(port: number = BACKEND_PORT): Promise<ServerStatus> {
|
|
289
|
-
const pid = readPid();
|
|
290
|
-
const alive = await isServerAlive(port);
|
|
291
|
-
const startedAt = pidFileModifiedAt();
|
|
292
|
-
|
|
293
|
-
return {
|
|
294
|
-
running: alive,
|
|
295
|
-
pid: pid ?? undefined,
|
|
296
|
-
port: alive ? port : undefined,
|
|
297
|
-
uptimeMs: alive && startedAt ? Date.now() - startedAt.getTime() : undefined,
|
|
298
|
-
serverDist: resolveServerDist(),
|
|
299
|
-
logFile: LOG_FILE,
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// ---------------------------------------------------------------------------
|
|
304
|
-
// Cache inspection
|
|
305
|
-
// ---------------------------------------------------------------------------
|
|
306
|
-
|
|
307
|
-
export interface CacheEntry {
|
|
308
|
-
/** Project path (dir name inside ~/.nexiq/<hash>/<projectPath>) */
|
|
309
|
-
label: string;
|
|
310
|
-
/** Absolute path to the cache dir */
|
|
311
|
-
cachePath: string;
|
|
312
|
-
/** Total size in bytes */
|
|
313
|
-
sizeBytes: number;
|
|
314
|
-
/** Last modified time */
|
|
315
|
-
lastModified: Date;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
function dirSizeBytes(dirPath: string): number {
|
|
319
|
-
let total = 0;
|
|
320
|
-
try {
|
|
321
|
-
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
322
|
-
for (const entry of entries) {
|
|
323
|
-
const full = path.join(dirPath, entry.name);
|
|
324
|
-
if (entry.isDirectory()) {
|
|
325
|
-
total += dirSizeBytes(full);
|
|
326
|
-
} else {
|
|
327
|
-
try {
|
|
328
|
-
total += fs.statSync(full).size;
|
|
329
|
-
} catch {
|
|
330
|
-
// ignore
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
} catch {
|
|
335
|
-
// ignore unreadable dirs
|
|
336
|
-
}
|
|
337
|
-
return total;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
export function getCacheEntries(): CacheEntry[] {
|
|
341
|
-
if (!fs.existsSync(GLOBAL_NEXIQ_DIR)) return [];
|
|
342
|
-
|
|
343
|
-
const entries: CacheEntry[] = [];
|
|
344
|
-
|
|
345
|
-
// The server stores project caches directly in ~/.nexiq/<encoded-project-path>/
|
|
346
|
-
const items = fs.readdirSync(GLOBAL_NEXIQ_DIR, { withFileTypes: true });
|
|
347
|
-
for (const item of items) {
|
|
348
|
-
if (!item.isDirectory()) continue;
|
|
349
|
-
const fullPath = path.join(GLOBAL_NEXIQ_DIR, item.name);
|
|
350
|
-
const stat = fs.statSync(fullPath);
|
|
351
|
-
const sizeBytes = dirSizeBytes(fullPath);
|
|
352
|
-
entries.push({
|
|
353
|
-
label: decodeURIComponent(item.name.replace(/_/g, "/")),
|
|
354
|
-
cachePath: fullPath,
|
|
355
|
-
sizeBytes,
|
|
356
|
-
lastModified: stat.mtime,
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
return entries.sort((a, b) => b.lastModified.getTime() - a.lastModified.getTime());
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
export function clearCacheEntries(entries: CacheEntry[]): void {
|
|
364
|
-
for (const entry of entries) {
|
|
365
|
-
fs.rmSync(entry.cachePath, { recursive: true, force: true });
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
// ---------------------------------------------------------------------------
|
|
370
|
-
// Helpers
|
|
371
|
-
// ---------------------------------------------------------------------------
|
|
372
|
-
|
|
373
|
-
function sleep(ms: number) {
|
|
374
|
-
return new Promise((r) => setTimeout(r, ms));
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
export function formatBytes(bytes: number): string {
|
|
378
|
-
if (bytes < 1024) return `${bytes} B`;
|
|
379
|
-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
380
|
-
if (bytes < 1024 * 1024 * 1024) return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
381
|
-
return `${(bytes / 1024 / 1024 / 1024).toFixed(2)} GB`;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
export function formatDuration(ms: number): string {
|
|
385
|
-
if (ms < 1000) return `${ms}ms`;
|
|
386
|
-
const s = Math.floor(ms / 1000);
|
|
387
|
-
if (s < 60) return `${s}s`;
|
|
388
|
-
const m = Math.floor(s / 60);
|
|
389
|
-
if (m < 60) return `${m}m ${s % 60}s`;
|
|
390
|
-
const h = Math.floor(m / 60);
|
|
391
|
-
return `${h}h ${m % 60}m`;
|
|
392
|
-
}
|
package/src/ws.d.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ESNext",
|
|
4
|
-
"module": "NodeNext",
|
|
5
|
-
"moduleResolution": "NodeNext",
|
|
6
|
-
"jsx": "react-jsx",
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"outDir": "dist",
|
|
9
|
-
"rootDir": "src",
|
|
10
|
-
"strict": true,
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"skipLibCheck": true,
|
|
13
|
-
"forceConsistentCasingInFileNames": true
|
|
14
|
-
},
|
|
15
|
-
"include": ["src"]
|
|
16
|
-
}
|
package/tsup.config.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "tsup";
|
|
2
|
-
|
|
3
|
-
export default defineConfig((options) => ({
|
|
4
|
-
entry: ["src/cli.tsx"],
|
|
5
|
-
format: ["esm"],
|
|
6
|
-
target: "node18",
|
|
7
|
-
clean: true,
|
|
8
|
-
minify: true,
|
|
9
|
-
dts: false,
|
|
10
|
-
define: {
|
|
11
|
-
"process.env.MODE": JSON.stringify(options.env?.MODE || "production"),
|
|
12
|
-
},
|
|
13
|
-
banner: {
|
|
14
|
-
js: `#!/usr/bin/env node
|
|
15
|
-
import { createRequire as __createRequire } from 'node:module';
|
|
16
|
-
const require = __createRequire(import.meta.url);
|
|
17
|
-
`,
|
|
18
|
-
},
|
|
19
|
-
// Bundle only the ones that cause version conflicts or need to be standalone
|
|
20
|
-
noExternal: [
|
|
21
|
-
"ink",
|
|
22
|
-
"ink-spinner",
|
|
23
|
-
"react",
|
|
24
|
-
"react-dom",
|
|
25
|
-
"react-reconciler",
|
|
26
|
-
"meow",
|
|
27
|
-
"signal-exit",
|
|
28
|
-
],
|
|
29
|
-
// Exclude node built-ins and problematic native/peer deps
|
|
30
|
-
external: [
|
|
31
|
-
"ws",
|
|
32
|
-
"react-devtools-core",
|
|
33
|
-
"yoga-layout",
|
|
34
|
-
"yoga-wasm-web",
|
|
35
|
-
"assert",
|
|
36
|
-
"buffer",
|
|
37
|
-
"child_process",
|
|
38
|
-
"crypto",
|
|
39
|
-
"events",
|
|
40
|
-
"fs",
|
|
41
|
-
"module",
|
|
42
|
-
"net",
|
|
43
|
-
"os",
|
|
44
|
-
"path",
|
|
45
|
-
"stream",
|
|
46
|
-
"url",
|
|
47
|
-
"util",
|
|
48
|
-
],
|
|
49
|
-
}));
|