fix: 更新部署

This commit is contained in:
xion 2024-11-24 02:07:13 +08:00
parent 01680b39c2
commit 4bbc531ac7
3 changed files with 55 additions and 6 deletions

View File

@ -2,6 +2,7 @@ import { app } from '@/app.ts';
import { MicroAppModel } from './models.ts';
import { appPathCheck, installApp } from './module/install-app.ts';
import { loadApp } from './module/load-app.ts';
import { manager } from './manager-app.ts';
// 应用上传到 应用管理 的平台
app
@ -68,7 +69,9 @@ app
if (check) {
ctx.throw(400, 'App already exists, please remove it first');
}
await installApp({ path, key });
const installAppData = await installApp({ path, key });
await manager.add(installAppData.showAppInfo);
ctx.body = installAppData;
})
.addTo(app);
@ -94,3 +97,21 @@ app
}
})
.addTo(app);
// curl http://localhost:4002/api/router?path=micro-app&key=unload
app
.route({
path: 'micro-app',
key: 'unload',
})
.define(async (ctx) => {
// const { key } = ctx.query?.data;
const key = 'mark';
const main = manager.getAppShowInfo(key);
if (!main) {
ctx.throw(400, 'Invalid app');
}
manager.removeApp(key);
ctx.body = main;
})
.addTo(app);

View File

@ -57,8 +57,25 @@ export const installApp = async (opts: InstallAppOpts) => {
if (!name || !version || !app) {
throw new Error('Invalid package.json');
}
const readmeFile = path.join(extractPath, 'README.md');
let readmeDesc = '';
if (fileIsExist(readmeFile)) {
readmeDesc = fs.readFileSync(readmeFile, 'utf-8');
}
let showAppInfo = {
key,
status: 'inactive',
type: app?.type || 'system-app',
description: readmeDesc || '',
version,
//
entry: app?.entry || '',
path: extractPath,
origin: app,
};
app.key = key;
fs.writeFileSync(pkgs, JSON.stringify(pkg, null, 2));
// fs.unlinkSync(filePath);
return { path: filePath, pkg };
return { path: filePath, pkg, showAppInfo };
};

View File

@ -24,13 +24,15 @@ export enum AppType {
export type AppInfo = {
key: string;
status?: 'inactive' | 'running' | 'stop' | 'error'; // 运行状态
version?: string; // 版本
type?: AppType; // 默认类型
entry?: string; // 入口文件
path?: string; // 文件路径
description?: string; // 描述
timestamp?: number; // 时间戳, 每次更新更新时间戳
process?: any; // 进程
description?: string; // 描述
version?: string; // 版本
origin?: Record<string, any>; // 原始数据
entry?: string; // 入口文件
path?: string; // 文件路径
};
export const onAppShowInfo = (app: AppInfo) => {
return {
@ -41,6 +43,15 @@ export const onAppShowInfo = (app: AppInfo) => {
version: app.version,
};
};
export const createAppShowInfo = (app: any) => {
return {
key: app.key,
status: app.status,
type: app.type,
description: app.description,
version: app.version,
};
};
type managerOptions = {
mainApp: App;
};