This commit is contained in:
2025-03-09 17:49:10 +08:00
parent ce9b43b497
commit 0ee7d9a69a
5 changed files with 483 additions and 395 deletions

View File

@@ -0,0 +1,88 @@
/**
* 下载 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, uninstallApp } from '@/module/download/install.ts';
export const appCommand = new Command('app').description('app 命令').action(() => {
console.log('app');
});
program.addCommand(appCommand);
const downloadAppCommand = new Command('download')
.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 || '下载失败'));
}
});
const uninstallAppCommand = new Command('uninstall')
.alias('remove')
.description('卸载 app serve client的包')
.option('-i, --id <id>', 'user/key')
.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 {
console.error(chalk.red('id is required'));
return;
}
const result = await uninstallApp(
{
user,
key,
},
{
appDir: '',
},
);
if (result.code === 200) {
console.log(chalk.green('卸载成功', user, key));
} else {
console.error(chalk.red(result.message || '卸载失败'));
}
});
appCommand.addCommand(downloadAppCommand);
appCommand.addCommand(uninstallAppCommand);