feat: add silky cli tools
This commit is contained in:
@@ -9,6 +9,9 @@ import { checkAppDir, installApp, uninstallApp } from '@/module/download/install
|
||||
import { fileIsExist } from '@/uitls/file.ts';
|
||||
import fs from 'fs';
|
||||
import { getConfig } from '@/module/get-config.ts';
|
||||
import path from 'path';
|
||||
import inquirer from 'inquirer';
|
||||
import { baseURL, getUrl } from '@/module/query.ts';
|
||||
export const appCommand = new Command('app').description('app 命令').action(() => {
|
||||
console.log('app');
|
||||
});
|
||||
@@ -55,7 +58,6 @@ const downloadAppCommand = new Command('download')
|
||||
} else {
|
||||
data.id = id;
|
||||
}
|
||||
const res = await queryApp(data);
|
||||
let registry = 'https://kevisual.cn';
|
||||
if (options?.registry) {
|
||||
registry = new URL(options.registry).origin;
|
||||
@@ -63,6 +65,8 @@ const downloadAppCommand = new Command('download')
|
||||
const config = getConfig();
|
||||
registry = new URL(config.baseURL).origin;
|
||||
}
|
||||
const res = await queryApp(data, { url: getUrl(registry) });
|
||||
console.log('registry', registry, data);
|
||||
if (res.code === 200) {
|
||||
const app = res.data;
|
||||
let appType: 'app' | 'web' = 'web';
|
||||
@@ -88,9 +92,36 @@ const downloadAppCommand = new Command('download')
|
||||
|
||||
const uninstallAppCommand = new Command('uninstall')
|
||||
.alias('remove')
|
||||
.description('卸载 app serve client的包')
|
||||
.description('卸载 app serve client的包。 手动删除更简单。')
|
||||
.option('-i, --id <id>', 'user/key')
|
||||
.option('-t, --type <type>', 'app,或者web, 默认为web', 'web')
|
||||
.option('-p, --path <path>', '删除的路径, 如果存在,则优先执行,不会去判断 id 和 type 。')
|
||||
.action(async (options) => {
|
||||
if (options.path) {
|
||||
const _path = path.resolve(options.path);
|
||||
try {
|
||||
const checkPath = fileIsExist(_path);
|
||||
if (!checkPath) {
|
||||
console.error(chalk.red('path is error, 请输入正确的路径'));
|
||||
} else {
|
||||
const answer = await inquirer.prompt([
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'confirm',
|
||||
message: `确定要删除 ${_path} 吗?`,
|
||||
default: false,
|
||||
},
|
||||
]);
|
||||
if (answer.confirm) {
|
||||
fs.rmSync(_path, { recursive: true });
|
||||
console.log(chalk.green('删除成功', _path));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(chalk.red('删除失败', e));
|
||||
}
|
||||
return;
|
||||
}
|
||||
const id = options.id || '';
|
||||
if (!id) {
|
||||
console.error(chalk.red('id is required'));
|
||||
@@ -102,7 +133,7 @@ const uninstallAppCommand = new Command('uninstall')
|
||||
data.user = user;
|
||||
data.key = key;
|
||||
} else {
|
||||
console.error(chalk.red('id is required'));
|
||||
console.error(chalk.red('id is required user/key'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -113,6 +144,7 @@ const uninstallAppCommand = new Command('uninstall')
|
||||
},
|
||||
{
|
||||
appDir: '',
|
||||
type: options.type,
|
||||
},
|
||||
);
|
||||
if (result.code === 200) {
|
||||
|
||||
Reference in New Issue
Block a user