expxagents 0.14.3 → 0.14.4
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/cli/src/commands/server.js +45 -31
- package/package.json +1 -1
|
@@ -4,38 +4,52 @@ import fs from 'fs';
|
|
|
4
4
|
import { resolveServerPaths } from '../utils/server-paths.js';
|
|
5
5
|
import { findPackageRoot } from '../utils/config.js';
|
|
6
6
|
export async function serverCommand() {
|
|
7
|
-
const { serverEntry, dashboardDist } = resolveServerPaths();
|
|
8
7
|
const userProjectDir = process.cwd();
|
|
9
8
|
const port = process.env.PORT ?? '3001';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
pkgVersion =
|
|
9
|
+
let stopping = false;
|
|
10
|
+
function startServer() {
|
|
11
|
+
const { serverEntry, dashboardDist } = resolveServerPaths();
|
|
12
|
+
// Re-read version on each start (picks up updates)
|
|
13
|
+
let pkgVersion = '0.0.0';
|
|
14
|
+
try {
|
|
15
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(findPackageRoot(), 'package.json'), 'utf-8'));
|
|
16
|
+
pkgVersion = pkg.version ?? '0.0.0';
|
|
17
|
+
}
|
|
18
|
+
catch { /* ignore */ }
|
|
19
|
+
console.log(`Starting ExpxAgents server v${pkgVersion}...`);
|
|
20
|
+
const child = spawn('node', [serverEntry], {
|
|
21
|
+
cwd: userProjectDir,
|
|
22
|
+
stdio: 'inherit',
|
|
23
|
+
env: {
|
|
24
|
+
...process.env,
|
|
25
|
+
NODE_ENV: 'production',
|
|
26
|
+
DASHBOARD_DIST: dashboardDist,
|
|
27
|
+
SQUADS_DIR: path.join(userProjectDir, 'squads'),
|
|
28
|
+
DOTENV_PATH: path.join(userProjectDir, '.env'),
|
|
29
|
+
PORT: port,
|
|
30
|
+
EXPXAGENTS_VERSION: pkgVersion,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
child.on('error', (err) => {
|
|
34
|
+
console.error(`Failed to start server: ${err.message}`);
|
|
35
|
+
console.error('Make sure you have the latest expxagents package installed.');
|
|
36
|
+
process.exit(1);
|
|
37
|
+
});
|
|
38
|
+
child.on('exit', (code) => {
|
|
39
|
+
if (stopping) {
|
|
40
|
+
process.exit(code ?? 0);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// Exit code 0 = intentional restart (e.g. after auto-update)
|
|
44
|
+
if (code === 0) {
|
|
45
|
+
console.log('Server exited with code 0, restarting...');
|
|
46
|
+
setTimeout(() => startServer(), 1000);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
process.exit(code ?? 1);
|
|
50
|
+
});
|
|
51
|
+
process.on('SIGINT', () => { stopping = true; child.kill('SIGINT'); });
|
|
52
|
+
process.on('SIGTERM', () => { stopping = true; child.kill('SIGTERM'); });
|
|
15
53
|
}
|
|
16
|
-
|
|
17
|
-
console.log('Starting ExpxAgents server...');
|
|
18
|
-
const child = spawn('node', [serverEntry], {
|
|
19
|
-
cwd: userProjectDir,
|
|
20
|
-
stdio: 'inherit',
|
|
21
|
-
env: {
|
|
22
|
-
...process.env,
|
|
23
|
-
NODE_ENV: 'production',
|
|
24
|
-
DASHBOARD_DIST: dashboardDist,
|
|
25
|
-
SQUADS_DIR: path.join(userProjectDir, 'squads'),
|
|
26
|
-
DOTENV_PATH: path.join(userProjectDir, '.env'),
|
|
27
|
-
PORT: port,
|
|
28
|
-
EXPXAGENTS_VERSION: pkgVersion,
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
child.on('error', (err) => {
|
|
32
|
-
console.error(`Failed to start server: ${err.message}`);
|
|
33
|
-
console.error('Make sure you have the latest expxagents package installed.');
|
|
34
|
-
process.exit(1);
|
|
35
|
-
});
|
|
36
|
-
child.on('exit', (code) => {
|
|
37
|
-
process.exit(code ?? 0);
|
|
38
|
-
});
|
|
39
|
-
process.on('SIGINT', () => child.kill('SIGINT'));
|
|
40
|
-
process.on('SIGTERM', () => child.kill('SIGTERM'));
|
|
54
|
+
startServer();
|
|
41
55
|
}
|