Files
cli/src/command/download.ts
2025-03-09 10:35:13 +08:00

52 lines
1.6 KiB
TypeScript

/**
* 下载 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 <id>', '下载 app serve client的包, id 或者user/key')
.option('-o, --output <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);