@kvell007/embed-labs-cli 0.1.0-alpha.74 → 0.1.0-alpha.76

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/index.js CHANGED
@@ -7,7 +7,6 @@ import { createRequire } from "node:module";
7
7
  import { homedir, tmpdir } from "node:os";
8
8
  import { basename, delimiter, dirname, join, resolve } from "node:path";
9
9
  import { fileURLToPath } from "node:url";
10
- import { startServer } from "@embed-labs/local-bridge";
11
10
  import { composeBootLogoPackage } from "./image-compose.js";
12
11
  import { buildTaishanPiQtSmoke, compileTaishanPiSingleFile, currentLocalToolchain, installLocalToolchain, latestLocalToolchain, validateLocalToolchain } from "./local-toolchain.js";
13
12
  import { fail, ok } from "@embed-labs/protocol";
@@ -147,11 +146,20 @@ async function main(argv) {
147
146
  return output(parsed, await bridgePost("/v1/board/taishanpi/deploy", request), renderBoardDeployResult);
148
147
  }
149
148
  if (area === "bridge" && action === "start") {
150
- startServer({
151
- host: stringFlag(parsed, "host"),
152
- port: numberFlag(parsed, "port")
149
+ const launcher = await resolveBridgeLauncher();
150
+ const args = [
151
+ ...launcher.args,
152
+ ...(stringFlag(parsed, "host") ? ["--host", stringFlag(parsed, "host")] : []),
153
+ ...(numberFlag(parsed, "port") ? ["--port", String(numberFlag(parsed, "port"))] : [])
154
+ ];
155
+ const child = spawn(launcher.command, args, {
156
+ cwd: process.cwd(),
157
+ env: process.env,
158
+ stdio: "inherit"
159
+ });
160
+ return await new Promise((resolveExit) => {
161
+ child.on("close", (code) => resolveExit(code ?? 0));
153
162
  });
154
- return await waitForever();
155
163
  }
156
164
  if (area === "bridge" && action === "status") {
157
165
  return output(parsed, await bridgeGet("/healthz"), renderBridgeStatus);
@@ -1972,6 +1980,51 @@ async function resolveExecutableOnPath(name) {
1972
1980
  }
1973
1981
  return undefined;
1974
1982
  }
1983
+ async function resolveBridgeLauncher() {
1984
+ const explicitBinary = process.env.EMBED_LOCAL_BRIDGE_BINARY?.trim();
1985
+ if (explicitBinary) {
1986
+ try {
1987
+ await access(explicitBinary, constants.X_OK);
1988
+ return { command: explicitBinary, args: [] };
1989
+ }
1990
+ catch {
1991
+ // Fall through so the package launcher can print its clearer repair message.
1992
+ }
1993
+ }
1994
+ const pathBinary = await resolveExecutableOnPath(process.platform === "win32" ? "embed-local-bridge.cmd" : "embed-local-bridge");
1995
+ if (pathBinary) {
1996
+ return { command: pathBinary, args: [] };
1997
+ }
1998
+ const packageLauncher = await resolveBridgePackageLauncher();
1999
+ if (packageLauncher) {
2000
+ return { command: process.execPath, args: [packageLauncher] };
2001
+ }
2002
+ return {
2003
+ command: process.execPath,
2004
+ args: [resolve(SOURCE_CHECKOUT_ROOT, "packages", "local-bridge", "dist", "index.js")]
2005
+ };
2006
+ }
2007
+ async function resolveBridgePackageLauncher() {
2008
+ const candidates = [];
2009
+ try {
2010
+ const packageJson = require.resolve("@embed-labs/local-bridge/package.json");
2011
+ candidates.push(join(dirname(packageJson), "dist", "index.js"));
2012
+ }
2013
+ catch {
2014
+ // Source checkout fallback below.
2015
+ }
2016
+ candidates.push(resolve(SOURCE_CHECKOUT_ROOT, "packages", "local-bridge", "dist", "index.js"));
2017
+ for (const candidate of candidates) {
2018
+ try {
2019
+ await access(candidate, constants.R_OK);
2020
+ return candidate;
2021
+ }
2022
+ catch {
2023
+ // Keep looking.
2024
+ }
2025
+ }
2026
+ return undefined;
2027
+ }
1975
2028
  function defaultOpenCodeRoot() {
1976
2029
  return join(process.cwd(), ".opencode");
1977
2030
  }