@commandgarden/cli 1.1.5 → 1.2.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/main.js +30 -8
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -17244,6 +17244,7 @@ async function executeGuiStart(baseUrl, cgHome, appScript, opts) {
|
|
|
17244
17244
|
const pid = parseInt(readFileSync7(pidPath, "utf-8").trim(), 10);
|
|
17245
17245
|
if (isProcessAlive(pid)) {
|
|
17246
17246
|
const message = "GUI is already running.";
|
|
17247
|
+
if (!opts.noOpen) openBrowser(`http://127.0.0.1:${appPort}`, cgHome);
|
|
17247
17248
|
return opts.background ? { status: "already-running", message } : message;
|
|
17248
17249
|
}
|
|
17249
17250
|
unlinkSync3(pidPath);
|
|
@@ -17285,7 +17286,7 @@ async function executeGuiStart(baseUrl, cgHome, appScript, opts) {
|
|
|
17285
17286
|
intervalMs: 500
|
|
17286
17287
|
});
|
|
17287
17288
|
if (outcome === "ready") {
|
|
17288
|
-
openBrowser(appUrl);
|
|
17289
|
+
openBrowser(appUrl, cgHome);
|
|
17289
17290
|
return { status: "started", message: `GUI started (PID: ${child2.pid ?? "unknown"}).`, pid: child2.pid };
|
|
17290
17291
|
}
|
|
17291
17292
|
if (child2.pid) try {
|
|
@@ -17302,7 +17303,7 @@ async function executeGuiStart(baseUrl, cgHome, appScript, opts) {
|
|
|
17302
17303
|
if (!opts.noOpen) {
|
|
17303
17304
|
const appUrl = `http://127.0.0.1:${appPort}`;
|
|
17304
17305
|
const ready = await waitForServer(appUrl, child);
|
|
17305
|
-
if (ready) openBrowser(appUrl);
|
|
17306
|
+
if (ready) openBrowser(appUrl, cgHome);
|
|
17306
17307
|
}
|
|
17307
17308
|
await new Promise((resolve2) => child.on("exit", () => resolve2()));
|
|
17308
17309
|
return "GUI stopped.";
|
|
@@ -17347,13 +17348,28 @@ async function waitForServer(url, child) {
|
|
|
17347
17348
|
}
|
|
17348
17349
|
return false;
|
|
17349
17350
|
}
|
|
17350
|
-
function openBrowser(url) {
|
|
17351
|
-
|
|
17351
|
+
function openBrowser(url, cgHome) {
|
|
17352
|
+
console.error("Opening browser...");
|
|
17353
|
+
const logPath = join3(cgHome, "browser.log");
|
|
17354
|
+
const log = (line) => {
|
|
17355
|
+
try {
|
|
17356
|
+
writeFileSync3(logPath, `[${(/* @__PURE__ */ new Date()).toISOString()}] ${line}
|
|
17357
|
+
`, { flag: "a" });
|
|
17358
|
+
} catch {
|
|
17359
|
+
}
|
|
17360
|
+
};
|
|
17361
|
+
const [command, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", url]] : ["xdg-open", [url]];
|
|
17362
|
+
log(`platform=${process.platform} spawning: ${command} ${JSON.stringify(args)}`);
|
|
17363
|
+
const child = spawn2(command, args, { stdio: "ignore", detached: true });
|
|
17364
|
+
log(`spawned pid=${child.pid ?? "unknown"}`);
|
|
17365
|
+
child.on("spawn", () => log("event: spawn (process launched)"));
|
|
17366
|
+
child.on("error", (err) => log(`event: error ${err instanceof Error ? err.stack ?? err.message : String(err)}`));
|
|
17367
|
+
child.on("exit", (code, signal) => log(`event: exit code=${code} signal=${signal}`));
|
|
17352
17368
|
child.unref();
|
|
17353
17369
|
}
|
|
17354
17370
|
|
|
17355
17371
|
// src/commands/up-down.ts
|
|
17356
|
-
async function executeUp(baseUrl, cgHome, daemonScript, appScript, configPath) {
|
|
17372
|
+
async function executeUp(baseUrl, cgHome, daemonScript, appScript, configPath, opts = {}) {
|
|
17357
17373
|
const lines = [];
|
|
17358
17374
|
const daemonResult = await executeDaemonStart(baseUrl, cgHome, daemonScript);
|
|
17359
17375
|
lines.push(daemonResult.message);
|
|
@@ -17361,7 +17377,11 @@ async function executeUp(baseUrl, cgHome, daemonScript, appScript, configPath) {
|
|
|
17361
17377
|
if (!canProceed) {
|
|
17362
17378
|
return lines.join("\n");
|
|
17363
17379
|
}
|
|
17364
|
-
const guiResult = await executeGuiStart(baseUrl, cgHome, appScript, {
|
|
17380
|
+
const guiResult = await executeGuiStart(baseUrl, cgHome, appScript, {
|
|
17381
|
+
background: true,
|
|
17382
|
+
configPath,
|
|
17383
|
+
noOpen: opts.noOpen
|
|
17384
|
+
});
|
|
17365
17385
|
lines.push(typeof guiResult === "string" ? guiResult : guiResult.message);
|
|
17366
17386
|
return lines.join("\n");
|
|
17367
17387
|
}
|
|
@@ -17479,8 +17499,10 @@ gui.command("stop").description("Stop the GUI").action(() => {
|
|
|
17479
17499
|
gui.command("status").description("Check GUI status").action(() => {
|
|
17480
17500
|
console.log(executeGuiStatus(CG_HOME));
|
|
17481
17501
|
});
|
|
17482
|
-
program2.command("up").description("Start daemon + GUI, open browser").action(async () => {
|
|
17483
|
-
console.log(await executeUp(BASE_URL, CG_HOME, getDaemonScript(), getAppScript(), CONFIG_PATH
|
|
17502
|
+
program2.command("up").description("Start daemon + GUI, open browser (use --no-open to skip)").option("--no-open", "Do not open browser").action(async (opts) => {
|
|
17503
|
+
console.log(await executeUp(BASE_URL, CG_HOME, getDaemonScript(), getAppScript(), CONFIG_PATH, {
|
|
17504
|
+
noOpen: opts.open === false
|
|
17505
|
+
}));
|
|
17484
17506
|
});
|
|
17485
17507
|
program2.command("down").description("Stop GUI + daemon").action(async () => {
|
|
17486
17508
|
console.log(await executeDown(CG_HOME));
|