update: 更新light-code部分的代码模块
This commit is contained in:
@@ -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