@commandgarden/cli 1.0.1 → 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 +31 -17
- 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,35 +4907,33 @@ 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
4916
|
if (!opts.noOpen) {
|
|
4914
4917
|
const appUrl = `http://127.0.0.1:${appPort}`;
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
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");
|
|
4919
4924
|
} catch {
|
|
4920
4925
|
}
|
|
4921
|
-
|
|
4926
|
+
if (existsSync3(pidPath)) unlinkSync2(pidPath);
|
|
4927
|
+
return `GUI failed to start. Check ${logPath} for errors.`;
|
|
4922
4928
|
}
|
|
4923
|
-
openBrowser(appUrl);
|
|
4924
4929
|
}
|
|
4925
4930
|
return `GUI started (PID: ${child2.pid ?? "unknown"}).`;
|
|
4926
4931
|
}
|
|
4927
4932
|
const child = spawn2("node", [appScript], { stdio: "inherit" });
|
|
4928
4933
|
if (!opts.noOpen) {
|
|
4929
4934
|
const appUrl = `http://127.0.0.1:${appPort}`;
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
await fetch(appUrl);
|
|
4933
|
-
break;
|
|
4934
|
-
} catch {
|
|
4935
|
-
}
|
|
4936
|
-
await new Promise((r) => setTimeout(r, 250));
|
|
4937
|
-
}
|
|
4938
|
-
openBrowser(appUrl);
|
|
4935
|
+
const ready = await waitForServer(appUrl, child);
|
|
4936
|
+
if (ready) openBrowser(appUrl);
|
|
4939
4937
|
}
|
|
4940
4938
|
await new Promise((resolve) => child.on("exit", () => resolve()));
|
|
4941
4939
|
return "GUI stopped.";
|
|
@@ -4964,6 +4962,22 @@ function executeGuiStatus(cgHome) {
|
|
|
4964
4962
|
return "GUI: not running (stale PID file).";
|
|
4965
4963
|
}
|
|
4966
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
|
+
}
|
|
4967
4981
|
function openBrowser(url) {
|
|
4968
4982
|
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
|
|
4969
4983
|
exec(`${cmd} ${url}`);
|