fix: 更新版本号至 0.1.4,并优化 live 命令的配置路径处理

This commit is contained in:
2026-02-17 04:10:56 +08:00
parent 171d01a784
commit 63edd0fd84
2 changed files with 34 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@kevisual/cli", "name": "@kevisual/cli",
"version": "0.1.3", "version": "0.1.4",
"description": "envision 命令行工具", "description": "envision 命令行工具",
"type": "module", "type": "module",
"basename": "/root/cli", "basename": "/root/cli",

View File

@@ -20,7 +20,12 @@ const liveCmd = new Command('live')
.option('-c, --config <string>', '配置文件路径 (优先级高于 JSON 参数), 默认keep.json') .option('-c, --config <string>', '配置文件路径 (优先级高于 JSON 参数), 默认keep.json')
.action(async (opts) => { .action(async (opts) => {
let config: { wss: string; cookie: string; url?: string }; 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 { try {
let jsonString = opts.json; let jsonString = opts.json;
@@ -50,4 +55,31 @@ const liveCmd = new Command('live')
}); });
cnbCmd.addCommand(liveCmd); 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); program.addCommand(cnbCmd);