update: 更新light-code部分的代码模块
This commit is contained in:
@@ -32,7 +32,6 @@ 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的包, 使用私有源')
|
||||
.option('-f, --force ', '强制覆盖')
|
||||
.option('-y, --yes ', '覆盖的时候不提示')
|
||||
@@ -71,16 +70,9 @@ const downloadAppCommand = new Command('download')
|
||||
console.log('registry', registry, data, options.type);
|
||||
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: output,
|
||||
kevisualUrl: registry,
|
||||
appType: appType,
|
||||
force: options.force,
|
||||
yes: options.yes,
|
||||
});
|
||||
@@ -98,7 +90,6 @@ const uninstallAppCommand = new Command('uninstall')
|
||||
.alias('remove')
|
||||
.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) {
|
||||
|
||||
@@ -121,14 +121,6 @@ export const rewritePkg = (packagePath: string, pkg: Package) => {
|
||||
type InstallAppOpts = {
|
||||
appDir?: string;
|
||||
kevisualUrl?: string;
|
||||
/**
|
||||
* 是否是客户端, 下载到 assistant-config的下面
|
||||
*/
|
||||
isClient?: boolean;
|
||||
/**
|
||||
* 是否是web, 下载到 web-config的下面
|
||||
*/
|
||||
appType?: 'app' | 'web';
|
||||
/**
|
||||
* 是否强制覆盖, 下载前删除已有的
|
||||
*/
|
||||
@@ -137,16 +129,16 @@ type InstallAppOpts = {
|
||||
};
|
||||
export const installApp = async (app: Package, opts: InstallAppOpts = {}) => {
|
||||
// const _app = demoData;
|
||||
const { appDir = '', kevisualUrl = 'https://kevisual.cn', isClient = false, appType = 'web' } = opts;
|
||||
const { appDir = '', kevisualUrl = 'https://kevisual.cn', } = opts;
|
||||
const _app = app;
|
||||
try {
|
||||
let files = _app.data.files || [];
|
||||
const version = _app.version;
|
||||
const user = _app.user;
|
||||
const key = _app.key;
|
||||
const downloadDirPath = appType === 'web' ? path.join(appDir, user, key) : path.join(appDir);
|
||||
const downloadDirPath = path.join(appDir, user, key);
|
||||
await checkDelete({ force: opts?.force, yes: opts?.yes, dir: downloadDirPath });
|
||||
const packagePath = path.join(appDir, appType === 'app' ? 'package.json' : `${user}/${key}/package.json`);
|
||||
const packagePath = path.join(appDir, `${user}/${key}/package.json`);
|
||||
const downFiles = files
|
||||
.filter((file: any) => file?.path)
|
||||
.map((file: any) => {
|
||||
@@ -154,9 +146,6 @@ export const installApp = async (app: Package, opts: InstallAppOpts = {}) => {
|
||||
const noVersionPath = file.path.replace(`/${version}`, '');
|
||||
let downloadPath = noVersionPath;
|
||||
let downloadUrl = '';
|
||||
if (appType === 'app') {
|
||||
downloadPath = noVersionPath.replace(`${user}/${key}/`, '');
|
||||
}
|
||||
if (file.path.startsWith('http')) {
|
||||
downloadUrl = file.path;
|
||||
} else {
|
||||
@@ -178,7 +167,7 @@ export const installApp = async (app: Package, opts: InstallAppOpts = {}) => {
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
console.log('downloadUrwl', downloadUrl);
|
||||
console.log('downloadUrl', downloadUrl);
|
||||
const { blob, type } = await fetchLink(downloadUrl);
|
||||
if (type.includes('text/html')) {
|
||||
const html = await blob.text();
|
||||
@@ -222,7 +211,7 @@ export const checkAppDir = (appDir: string) => {
|
||||
if (files.length === 0) {
|
||||
fs.rmSync(appDir, { recursive: true });
|
||||
}
|
||||
} catch (error) {}
|
||||
} catch (error) { }
|
||||
};
|
||||
export const checkFileExists = (path: string) => {
|
||||
try {
|
||||
@@ -237,7 +226,7 @@ type UninstallAppOpts = {
|
||||
type?: 'app' | 'web';
|
||||
};
|
||||
export const uninstallApp = async (app: Partial<Package>, opts: UninstallAppOpts = {}) => {
|
||||
const { appDir = '', type = 'web' } = opts;
|
||||
const { appDir = '' } = opts;
|
||||
try {
|
||||
const { user, key } = app;
|
||||
const keyDir = path.join(appDir, user, key);
|
||||
@@ -254,7 +243,7 @@ export const uninstallApp = async (app: Partial<Package>, opts: UninstallAppOpts
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
type === 'web' && checkAppDir(parentDir);
|
||||
checkAppDir(parentDir);
|
||||
return {
|
||||
code: 200,
|
||||
message: 'Uninstall app success',
|
||||
|
||||
Reference in New Issue
Block a user