baton-host 0.1.7 → 0.1.8

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.
Files changed (2) hide show
  1. package/bin/baton-host.js +29 -38
  2. package/package.json +5 -5
package/bin/baton-host.js CHANGED
@@ -290,48 +290,19 @@ async function promptPortForInstall() {
290
290
  }
291
291
  }
292
292
 
293
- async function printBridgeInfoFromCache() {
293
+ function printBridgeInfoFromCache() {
294
294
  if (!fs.existsSync(BRIDGE_INFO_PATH)) {
295
295
  throw new Error("未找到已保存的连接信息,请稍后重试");
296
296
  }
297
297
 
298
- let cached;
299
- try {
300
- cached = JSON.parse(fs.readFileSync(BRIDGE_INFO_PATH, "utf8"));
301
- } catch {
302
- throw new Error("已保存的连接信息损坏,请重新执行 service restart");
303
- }
304
-
305
- if (!cached?.bridgeUrl || !cached?.displayLabel) {
306
- throw new Error("已保存的连接信息不完整,请稍后重试");
307
- }
308
-
309
- const payload = JSON.stringify({ bridgeUrl: cached.bridgeUrl });
310
- // eslint-disable-next-line @typescript-eslint/no-require-imports
311
- const qrcode = require("qrcode-terminal");
312
-
313
- console.log("\n✅ Baton Bridge 已启动");
314
- console.log(`模式: ${cached.displayLabel}`);
315
- console.log(`主连接地址: ${cached.bridgeUrl}`);
316
- if (cached.lanBridgeUrl && cached.lanBridgeUrl !== cached.bridgeUrl) {
317
- console.log(`局域网地址: ${cached.lanBridgeUrl}`);
318
- }
319
- if (cached.note) {
320
- console.log(`说明: ${cached.note}`);
321
- }
322
- console.log("\n请使用 Baton App 扫描下方二维码连接:\n");
323
-
324
- await new Promise((resolve) => {
325
- qrcode.generate(payload, { small: true }, (qrText) => {
326
- for (const line of qrText.split("\n")) {
327
- console.log(line);
328
- }
329
- resolve();
330
- });
331
- });
298
+ const envVars = readEnvFile();
299
+ const env = {
300
+ ...process.env,
301
+ ...envVars,
302
+ BATON_CLOUDFLARED_BIN: path.join(INSTALL_BIN_DIR, "cloudflared")
303
+ };
332
304
 
333
- console.log("\n在 Baton App 设置 → Bridge 服务器 → 扫码连接");
334
- console.log("现在可以关闭终端,服务会继续在后台运行。\n");
305
+ runInheritedCommand(path.join(INSTALL_BIN_DIR, "baton-host"), ["--print-bridge-info"], { env });
335
306
  }
336
307
 
337
308
  async function waitForBridgeInfo(timeoutMs = 15000) {
@@ -347,7 +318,7 @@ async function waitForBridgeInfo(timeoutMs = 15000) {
347
318
 
348
319
  async function runBridgePrintCommand() {
349
320
  await waitForBridgeInfo();
350
- await printBridgeInfoFromCache();
321
+ printBridgeInfoFromCache();
351
322
  }
352
323
 
353
324
  function buildWrapperScript() {
@@ -487,6 +458,26 @@ function runCommand(command, args, options = {}) {
487
458
  return result;
488
459
  }
489
460
 
461
+ function runInheritedCommand(command, args, options = {}) {
462
+ const result = spawnSync(command, args, {
463
+ stdio: "inherit",
464
+ env: options.env || process.env
465
+ });
466
+
467
+ if (result.error) {
468
+ if (options.allowFailure) {
469
+ return result;
470
+ }
471
+ throw result.error;
472
+ }
473
+
474
+ if (!options.allowFailure && result.status !== 0) {
475
+ throw new Error(`${command} ${args.join(" ")} 失败,退出码 ${result.status}`);
476
+ }
477
+
478
+ return result;
479
+ }
480
+
490
481
  function installLinuxService() {
491
482
  const unitPath = getLinuxUnitPath();
492
483
  ensureDir(path.dirname(unitPath));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baton-host",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Baton Bridge Host CLI(二进制分发入口)",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -10,9 +10,9 @@
10
10
  "bin"
11
11
  ],
12
12
  "optionalDependencies": {
13
- "baton-host-darwin-arm64": "0.1.7",
14
- "baton-host-darwin-x64": "0.1.7",
15
- "baton-host-linux-arm64": "0.1.7",
16
- "baton-host-linux-x64": "0.1.7"
13
+ "baton-host-darwin-arm64": "0.1.8",
14
+ "baton-host-darwin-x64": "0.1.8",
15
+ "baton-host-linux-arm64": "0.1.8",
16
+ "baton-host-linux-x64": "0.1.8"
17
17
  }
18
18
  }