update download app show me

This commit is contained in:
2025-03-30 20:23:45 +08:00
parent be6d7091c3
commit aadd8266b1
8 changed files with 132 additions and 30 deletions

View File

@@ -5,24 +5,47 @@
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';
import { checkAppDir, installApp, uninstallApp } from '@/module/download/install.ts';
import { fileIsExist } from '@/uitls/file.ts';
import fs from 'fs';
export const appCommand = new Command('app').description('app 命令').action(() => {
console.log('app');
});
program.addCommand(appCommand);
/**
* 下载 app serve client的包
* 如果output不存在则创建, 路径为相对路径, 如果存在,则不创建
*
* -t 类型, app或者web 默认为web
* -r 使用私有源
* -o 输出路径
* -i 下载 app serve client的包, id 或者user/key
*
*/
const downloadAppCommand = new Command('download')
.description('下载 app serve client的包. \napp download -i root/code-center')
.option('-i, --id <id>', '下载 app serve client的包, id 或者user/key')
.option('-o, --output <output>', '下载 app serve client的包, 输出路径')
.option('-t, --type <type>', '下载 app serve client的包, 类型, app或者web 默认为web')
.option('-r, --registry <registry>', '下载 app serve client的包, 使用私有源')
.action(async (options) => {
const id = options.id || '';
const output = options.output || '';
if (!id) {
console.error(chalk.red('id is required'));
return;
}
if (output) {
const checkOutput = fileIsExist(output);
if (!checkOutput) {
// console.error(chalk.red('output is error, 请输入正确的路径'));
// return;
fs.mkdirSync(output, { recursive: true });
}
}
const [user, key] = id.split('/');
const data: any = {};
if (user && key) {
@@ -38,10 +61,16 @@ const downloadAppCommand = new Command('download')
}
if (res.code === 200) {
const app = res.data;
let appType: 'app' | 'web' = 'web';
if (options.type === 'app') {
appType = 'app';
} else if (options.type === 'web') {
appType = 'web';
}
const result = await installApp(app, {
appDir: '',
// kevisualUrl: 'https://kevisual.cn',
appDir: output,
kevisualUrl: registry,
appType: appType,
});
if (result.code === 200) {
console.log(chalk.green('下载成功', res.data?.user, res.data?.key));