fix: 更新部署
This commit is contained in:
		@@ -2,6 +2,7 @@ import { app } from '@/app.ts';
 | 
				
			|||||||
import { MicroAppModel } from './models.ts';
 | 
					import { MicroAppModel } from './models.ts';
 | 
				
			||||||
import { appPathCheck, installApp } from './module/install-app.ts';
 | 
					import { appPathCheck, installApp } from './module/install-app.ts';
 | 
				
			||||||
import { loadApp } from './module/load-app.ts';
 | 
					import { loadApp } from './module/load-app.ts';
 | 
				
			||||||
 | 
					import { manager } from './manager-app.ts';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 应用上传到 应用管理 的平台
 | 
					// 应用上传到 应用管理 的平台
 | 
				
			||||||
app
 | 
					app
 | 
				
			||||||
@@ -68,7 +69,9 @@ app
 | 
				
			|||||||
    if (check) {
 | 
					    if (check) {
 | 
				
			||||||
      ctx.throw(400, 'App already exists, please remove it first');
 | 
					      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);
 | 
					  .addTo(app);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -94,3 +97,21 @@ app
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
  .addTo(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);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -57,8 +57,25 @@ export const installApp = async (opts: InstallAppOpts) => {
 | 
				
			|||||||
  if (!name || !version || !app) {
 | 
					  if (!name || !version || !app) {
 | 
				
			||||||
    throw new Error('Invalid package.json');
 | 
					    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;
 | 
					  app.key = key;
 | 
				
			||||||
  fs.writeFileSync(pkgs, JSON.stringify(pkg, null, 2));
 | 
					  fs.writeFileSync(pkgs, JSON.stringify(pkg, null, 2));
 | 
				
			||||||
  // fs.unlinkSync(filePath);
 | 
					  // fs.unlinkSync(filePath);
 | 
				
			||||||
  return { path: filePath, pkg };
 | 
					  return { path: filePath, pkg, showAppInfo };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,13 +24,15 @@ export enum AppType {
 | 
				
			|||||||
export type AppInfo = {
 | 
					export type AppInfo = {
 | 
				
			||||||
  key: string;
 | 
					  key: string;
 | 
				
			||||||
  status?: 'inactive' | 'running' | 'stop' | 'error'; // 运行状态
 | 
					  status?: 'inactive' | 'running' | 'stop' | 'error'; // 运行状态
 | 
				
			||||||
 | 
					  version?: string; // 版本
 | 
				
			||||||
  type?: AppType; // 默认类型
 | 
					  type?: AppType; // 默认类型
 | 
				
			||||||
  entry?: string; // 入口文件
 | 
					  description?: string; // 描述
 | 
				
			||||||
  path?: string; // 文件路径
 | 
					 | 
				
			||||||
  timestamp?: number; // 时间戳, 每次更新更新时间戳
 | 
					  timestamp?: number; // 时间戳, 每次更新更新时间戳
 | 
				
			||||||
  process?: any; // 进程
 | 
					  process?: any; // 进程
 | 
				
			||||||
  description?: string; // 描述
 | 
					
 | 
				
			||||||
  version?: string; // 版本
 | 
					  origin?: Record<string, any>; // 原始数据
 | 
				
			||||||
 | 
					  entry?: string; // 入口文件
 | 
				
			||||||
 | 
					  path?: string; // 文件路径
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
export const onAppShowInfo = (app: AppInfo) => {
 | 
					export const onAppShowInfo = (app: AppInfo) => {
 | 
				
			||||||
  return {
 | 
					  return {
 | 
				
			||||||
@@ -41,6 +43,15 @@ export const onAppShowInfo = (app: AppInfo) => {
 | 
				
			|||||||
    version: app.version,
 | 
					    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 = {
 | 
					type managerOptions = {
 | 
				
			||||||
  mainApp: App;
 | 
					  mainApp: App;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user