feat: add app download
This commit is contained in:
88
src/command/app/index.ts
Normal file
88
src/command/app/index.ts
Normal 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);
|
||||
51
src/command/download.ts
Normal file
51
src/command/download.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* 下载 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);
|
||||
Reference in New Issue
Block a user