/** * 下载 app serve client的包的命令 */ import { chalk } from '@/module/chalk.ts'; import { program, Command } from '../program.ts'; import { queryApp } from '../query/app-manager/query-app.ts'; import { installApp } from '@/module/download/install.ts'; export const downloadCommand = new Command('download').description('下载 app serve client的包').action(() => { console.log('download'); }); program.addCommand(downloadCommand); const downloadAppCommand = new Command('app') .description('下载 app serve client的包') .option('-i, --id ', '下载 app serve client的包, id 或者user/key') .option('-o, --output ', '下载 app serve client的包, 输出路径') .action(async (options) => { const id = options.id || ''; if (!id) { console.error(chalk.red('id is required')); return; } const [user, key] = id.split('/'); const data: any = {}; if (user && key) { data.user = user; data.key = key; } else { data.id = id; } const res = await queryApp(data); if (res.code === 200) { const app = res.data; const result = await installApp(app, { appDir: '', // kevisualUrl: 'https://kevisual.cn', kevisualUrl: 'https://kevisual.xiongxiao.me', }); if (result.code === 200) { console.log(chalk.green('下载成功', res.data?.user, res.data?.key)); } else { console.error(chalk.red(result.message || '下载失败')); } } else { console.error(chalk.red(res.message || '下载失败')); } }); downloadCommand.addCommand(downloadAppCommand);