feat: clear rollup

This commit is contained in:
2025-04-24 12:42:02 +08:00
parent c2e8818975
commit 6827945446
13 changed files with 285 additions and 361 deletions

View File

@@ -8,6 +8,7 @@ import { queryApp } from '../../../query/app-manager/query-app.ts';
import { checkAppDir, installApp, uninstallApp } from '@/module/download/install.ts';
import { fileIsExist } from '@/uitls/file.ts';
import fs from 'fs';
import { getConfig } from '@/module/get-config.ts';
export const appCommand = new Command('app').description('app 命令').action(() => {
console.log('app');
});
@@ -27,7 +28,7 @@ program.addCommand(appCommand);
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('-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) => {
@@ -58,6 +59,9 @@ const downloadAppCommand = new Command('download')
let registry = 'https://kevisual.cn';
if (options?.registry) {
registry = new URL(options.registry).origin;
} else {
const config = getConfig();
registry = new URL(config.baseURL).origin;
}
if (res.code === 200) {
const app = res.data;

View File

@@ -106,8 +106,21 @@ const command = new Command('me')
.action(async (options) => {
try {
let res = await showMe(false);
let isRefresh = false;
if (res.code === 200 && res.data?.accessToken) {
res = await showMe(false);
isRefresh = true;
}
if (res.code === 200) {
if (isRefresh) {
console.log(chalk.green('refresh token success'), '\n');
}
} else {
console.log(
isRefresh ? chalk.red('refresh token failed, please login again.') : chalk.red('you need login first. \n run `envision login` to login'),
'\n',
);
return;
}
const baseURL = getConfig().baseURL;
const pickData = pick(res?.data, ['username', 'type', 'orgs']);

View File

@@ -3,14 +3,27 @@ import { getConfig, writeConfig } from '@/module/index.ts';
import { queryLogin, storage } from '@/module/query.ts';
import inquirer from 'inquirer';
import util from 'util';
function isNumeric(str: string) {
return /^-?\d+\.?\d*$/.test(str);
}
const showList = (list: string[]) => {
if (list.length === 0) {
console.log('expand baseURLList is empty');
return;
}
const config = getConfig();
console.log('----current baseURL:' + config.baseURL + '----\n');
list.forEach((item, index) => {
console.log(`${index + 1}: ${item}`);
});
};
const token = new Command('token')
.option('-e, --env', 'show token in env')
.description('show token')
.action(async (opts) => {
const token = storage.getItem('token');
if (opts.env) {
console.log('token', process.env.KEVISUAL_TOKEN);
console.log('token in env', process.env.KEVISUAL_TOKEN);
} else {
console.log('token', token);
}
@@ -30,7 +43,6 @@ app.addCommand(token);
const baseURL = new Command('baseURL')
.alias('base')
.alias('registry')
.description('show baseURL')
.option('-a, --add <baseURL>', 'add baseURL')
.option('-r, --remove <number>', 'remove baseURL number')
@@ -49,20 +61,7 @@ const baseURL = new Command('baseURL')
const newList = new Set(list);
return Array.from(newList);
};
const showList = (list: string[]) => {
if (list.length === 0) {
console.log('expand baseURLList is empty');
return;
}
const config = getConfig();
console.log('----current baseURL:' + config.baseURL + '----\n');
list.forEach((item, index) => {
console.log(`${index + 1}: ${item}`);
});
};
function isNumeric(str: string) {
return /^-?\d+\.?\d*$/.test(str);
}
if (opts.add || opts.set) {
let change = false;
if (opts.add) {
@@ -132,12 +131,10 @@ app.addCommand(baseURL);
const setBaseURL = new Command('set')
.option('-b, --baseURL <baseURL>', 'set baseURL')
// .argument('<baseURL>', 'set baseURL', '')
.description('set baseURL')
.action(async (opt) => {
const config = getConfig();
let baseURL = opt.baseURL;
// let baseURL = opt;
if (!baseURL) {
const answers = await inquirer.prompt([
{
@@ -147,6 +144,10 @@ const setBaseURL = new Command('set')
},
]);
baseURL = answers.baseURL;
if (!baseURL) {
console.log('baseURL is required');
return;
}
}
writeConfig({ ...config, baseURL });
});
@@ -158,3 +159,44 @@ baseURL.addCommand(setBaseURL);
// });
// app.addCommand(showQueryURL);
const rvm = new Command('registry')
.alias('reg')
.description('registry manager')
.option('-l, --list', 'list registry')
.option('-s, --set <registry>', 'set registry')
.action(async (opts) => {
const config = getConfig();
const defaultRegistry = ['https://kevisual.cn', 'https://kevisual.silkyai.cn', 'https://kevisual.xiongxiao.me'];
if (opts.list) {
showList(defaultRegistry);
return;
}
if (opts.set) {
const isNumber = isNumeric(opts.set);
if (isNumber) {
const index = Number(opts.set) - 1;
if (index < 0 || index >= defaultRegistry.length) {
console.log('index out of range');
return;
}
writeConfig({ ...config, baseURL: defaultRegistry[index] });
console.log('set registry', defaultRegistry[index]);
} else {
writeConfig({ ...config, baseURL: opts.set });
console.log('set registry', opts.set);
}
}
});
app.addCommand(rvm);
const silky = new Command('silky').description('silky registry').action(async (opts) => {
console.log('silky registry');
const config = getConfig();
const defaultRegistry = ['https://kevisual.silkyai.cn'];
writeConfig({ ...config, baseURL: defaultRegistry[0] });
showList(defaultRegistry);
});
app.addCommand(silky);

View File

@@ -1,6 +1,7 @@
import path from 'path';
import fs from 'fs';
import { storage } from '../query.ts';
import { chalk } from '../chalk.ts';
type DownloadTask = {
downloadPath: string;
@@ -69,8 +70,17 @@ export const installApp = async (app: Package, opts: InstallAppOpts = {}) => {
if (token) {
fetchURL.searchParams.set('token', token);
}
fetchURL.searchParams.set('download', 'true');
const res = await fetch(fetchURL.toString());
const blob = await res.blob();
const type = blob.type;
if (type.includes('text/html')) {
const html = await blob.text();
if (html === 'fetchRes is error') {
console.log(chalk.red('fetchRes is error'));
break;
}
}
fs.writeFileSync(downloadPath, Buffer.from(await blob.arrayBuffer()));
}
let indexHtml = files.find((file: any) => file.name === 'index.html');

View File

@@ -4,7 +4,7 @@ import fs from 'fs';
let version = '0.0.1';
try {
// @ts-ignore
if (VERSION) version = VERSION;
if (ENVISION_VERSION) version = ENVISION_VERSION;
} catch (e) {}
// @ts-ignore
program.name('app').description('A CLI tool with envison').version(version);