@commandgarden/cli 1.0.0 → 1.0.2
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 +40 -4
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -4872,7 +4872,7 @@ async function executeConfigSet(client, key, value) {
|
|
|
4872
4872
|
|
|
4873
4873
|
// src/commands/gui-cmd.ts
|
|
4874
4874
|
import { spawn as spawn2 } from "child_process";
|
|
4875
|
-
import { readFileSync as readFileSync5, writeFileSync as writeFileSync2, existsSync as existsSync3, unlinkSync as unlinkSync2, mkdirSync as mkdirSync2 } from "fs";
|
|
4875
|
+
import { readFileSync as readFileSync5, writeFileSync as writeFileSync2, existsSync as existsSync3, unlinkSync as unlinkSync2, mkdirSync as mkdirSync2, openSync, closeSync } from "fs";
|
|
4876
4876
|
import { join as join2 } from "path";
|
|
4877
4877
|
import { exec } from "child_process";
|
|
4878
4878
|
import { parse as parseYaml2 } from "yaml";
|
|
@@ -4907,14 +4907,34 @@ async function executeGuiStart(baseUrl, cgHome, appScript, opts) {
|
|
|
4907
4907
|
}
|
|
4908
4908
|
mkdirSync2(cgHome, { recursive: true });
|
|
4909
4909
|
if (opts.background) {
|
|
4910
|
-
const
|
|
4910
|
+
const logPath = join2(cgHome, "app.log");
|
|
4911
|
+
const logFd = openSync(logPath, "a");
|
|
4912
|
+
const child2 = spawn2("node", [appScript], { detached: true, stdio: ["ignore", logFd, logFd] });
|
|
4913
|
+
closeSync(logFd);
|
|
4911
4914
|
if (child2.pid) writeFileSync2(pidPath, String(child2.pid));
|
|
4912
4915
|
child2.unref();
|
|
4913
|
-
if (!opts.noOpen)
|
|
4916
|
+
if (!opts.noOpen) {
|
|
4917
|
+
const appUrl = `http://127.0.0.1:${appPort}`;
|
|
4918
|
+
const ready = await waitForServer(appUrl, child2);
|
|
4919
|
+
if (ready) {
|
|
4920
|
+
openBrowser(appUrl);
|
|
4921
|
+
} else {
|
|
4922
|
+
if (child2.pid) try {
|
|
4923
|
+
process.kill(child2.pid, "SIGTERM");
|
|
4924
|
+
} catch {
|
|
4925
|
+
}
|
|
4926
|
+
if (existsSync3(pidPath)) unlinkSync2(pidPath);
|
|
4927
|
+
return `GUI failed to start. Check ${logPath} for errors.`;
|
|
4928
|
+
}
|
|
4929
|
+
}
|
|
4914
4930
|
return `GUI started (PID: ${child2.pid ?? "unknown"}).`;
|
|
4915
4931
|
}
|
|
4916
|
-
if (!opts.noOpen) openBrowser(`http://127.0.0.1:${appPort}`);
|
|
4917
4932
|
const child = spawn2("node", [appScript], { stdio: "inherit" });
|
|
4933
|
+
if (!opts.noOpen) {
|
|
4934
|
+
const appUrl = `http://127.0.0.1:${appPort}`;
|
|
4935
|
+
const ready = await waitForServer(appUrl, child);
|
|
4936
|
+
if (ready) openBrowser(appUrl);
|
|
4937
|
+
}
|
|
4918
4938
|
await new Promise((resolve) => child.on("exit", () => resolve()));
|
|
4919
4939
|
return "GUI stopped.";
|
|
4920
4940
|
}
|
|
@@ -4942,6 +4962,22 @@ function executeGuiStatus(cgHome) {
|
|
|
4942
4962
|
return "GUI: not running (stale PID file).";
|
|
4943
4963
|
}
|
|
4944
4964
|
}
|
|
4965
|
+
async function waitForServer(url, child) {
|
|
4966
|
+
for (let i = 0; i < 40; i++) {
|
|
4967
|
+
try {
|
|
4968
|
+
if (child.pid) process.kill(child.pid, 0);
|
|
4969
|
+
} catch {
|
|
4970
|
+
return false;
|
|
4971
|
+
}
|
|
4972
|
+
try {
|
|
4973
|
+
await fetch(url);
|
|
4974
|
+
return true;
|
|
4975
|
+
} catch {
|
|
4976
|
+
}
|
|
4977
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
4978
|
+
}
|
|
4979
|
+
return false;
|
|
4980
|
+
}
|
|
4945
4981
|
function openBrowser(url) {
|
|
4946
4982
|
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
|
|
4947
4983
|
exec(`${cmd} ${url}`);
|