From 63edd0fd84fe9d69c9147abbf9b3e00ed9c0740a Mon Sep 17 00:00:00 2001 From: abearxiong Date: Tue, 17 Feb 2026 04:10:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=E8=87=B3=200.1.4=EF=BC=8C=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=20live=20=E5=91=BD=E4=BB=A4=E7=9A=84=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/command/cnb/index.ts | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8db471f..d4975ee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/cli", - "version": "0.1.3", + "version": "0.1.4", "description": "envision 命令行工具", "type": "module", "basename": "/root/cli", diff --git a/src/command/cnb/index.ts b/src/command/cnb/index.ts index d881d7c..a3d23ec 100644 --- a/src/command/cnb/index.ts +++ b/src/command/cnb/index.ts @@ -20,7 +20,12 @@ const liveCmd = new Command('live') .option('-c, --config ', '配置文件路径 (优先级高于 JSON 参数), 默认keep.json') .action(async (opts) => { let config: { wss: string; cookie: string; url?: string }; - const configPath = path.join(process.cwd(), opts.config || 'keep.json'); + let configPath = opts.config || 'keep.json' + if (configPath.startsWith('/')) { + configPath = path.resolve(configPath) + } else { + configPath = path.join(process.cwd(), configPath) + } try { let jsonString = opts.json; @@ -50,4 +55,31 @@ const liveCmd = new Command('live') }); cnbCmd.addCommand(liveCmd); + +const workspaceCmd = new Command('workspace') + .alias('w') + .description('工作区live保活,默认执行 ev cnb live -c /workspace/live/keep.json') + .action(() => { + try { + + const configPath = path.join('/workspace/live/keep.json') + const json = readFileSync(configPath, 'utf-8').trim(); + let config = JSON.parse(json); + if (!config.wss || !config.cookie) { + console.error('配置错误: 必须包含 wss 和 cookie 字段'); + process.exit(1); + } + createKeepAlive({ + wsUrl: config.wss, + cookie: config.cookie, + onDisconnect: (code) => { + console.log(`与 CNB 服务器断开连接,代码: ${code}`); + }, + debug: true + }); + } catch (e) { + console.error('error', e) + } + }) +program.addCommand(workspaceCmd) program.addCommand(cnbCmd); \ No newline at end of file