-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathxyph.ts
More file actions
61 lines (54 loc) · 1.6 KB
/
xyph.ts
File metadata and controls
61 lines (54 loc) · 1.6 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
59
60
61
#!/usr/bin/env node
import { existsSync } from 'node:fs';
import { spawnSync } from 'node:child_process';
import { dirname, resolve } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
function resolveHelperModuleUrl(baseDir: string): string {
const builtPath = resolve(baseDir, 'src/cli/runtimeEntry.js');
if (existsSync(builtPath)) {
return pathToFileURL(builtPath).href;
}
const sourcePath = resolve(baseDir, 'src/cli/runtimeEntry.ts');
if (existsSync(sourcePath)) {
return pathToFileURL(sourcePath).href;
}
throw new Error(`Could not resolve runtimeEntry helper from ${baseDir}`);
}
const argv = process.argv.slice(2);
const runtimeDir = dirname(fileURLToPath(import.meta.url));
const {
resolveLocalTsxCliPath,
resolveRuntimeLaunchPlan,
shouldLaunchTui,
stripTuiFlag,
} = await import(resolveHelperModuleUrl(runtimeDir));
const forwardedArgs = stripTuiFlag(argv);
const launchTui = shouldLaunchTui(argv);
const launchPlan = resolveRuntimeLaunchPlan(
runtimeDir,
launchTui ? 'xyph-dashboard' : 'xyph-actuator',
);
if (launchPlan.kind === 'tsx') {
const tsxCli = resolveLocalTsxCliPath(runtimeDir);
const child = spawnSync(
process.execPath,
[
tsxCli,
launchPlan.scriptPath,
...(launchTui ? forwardedArgs : argv),
],
{
stdio: 'inherit',
},
);
if (child.error) {
throw child.error;
}
process.exit(child.status ?? 1);
}
if (launchTui) {
process.argv = [process.argv[0] ?? 'node', process.argv[1] ?? 'xyph', ...forwardedArgs];
await import(launchPlan.moduleUrl);
} else {
await import(launchPlan.moduleUrl);
}