完善cli

This commit is contained in:
cool 2024-03-20 14:06:24 +08:00
parent ce91a3f16d
commit 67184a365b
2 changed files with 48 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/plugin-cli",
"version": "7.1.4",
"version": "7.1.7",
"description": "cool-admin midway plugin",
"main": "dist/index.js",
"scripts": {
@ -22,6 +22,7 @@
"readme": "README.md",
"license": "MIT",
"dependencies": {
"@cool-midway/cache-manager-fs-hash": "^7.0.0",
"@midwayjs/cache-manager": "^3.15.2",
"@midwayjs/core": "^3.15.0",
"archiver": "^6.0.1",

View File

@ -1,5 +1,6 @@
import { MidwayCache } from "@midwayjs/cache-manager";
import { IMidwayContext, IMidwayApplication } from "@midwayjs/core";
import { CoolCacheStore, FsCacheStore } from "./cache/store";
// 文件上传
export * from "./hook/upload";
@ -48,7 +49,9 @@ export abstract class BasePlugin {
/** 应用实例用到此项无法本地调试需安装到cool-admin中才能调试 */
app: IMidwayApplication;
/** 缓存 */
cache: MidwayCache;
cache: FsCacheStore | MidwayCache;
/** 插件 */
pluginService: PluginService;
setCtx(ctx: IMidwayContext) {
this.ctx = ctx;
@ -60,6 +63,24 @@ export abstract class BasePlugin {
constructor() {}
/**
* App级别的实例
* @param name
* @returns
*/
async getAppInstance(name: string) {
return await this.app.getApplicationContext().getAsync(name);
}
/**
*
* @param name
* @returns
*/
async getCtxInstance(name: string) {
return await this.ctx.requestContext.getAsync(name);
}
/**
*
* @param pluginInfo
@ -75,8 +96,32 @@ export abstract class BasePlugin {
this.pluginInfo = pluginInfo;
this.ctx = ctx;
this.app = app;
this.cache = CoolCacheStore({});
if (other) {
this.cache = other.cache;
this.pluginService = other.pluginService;
}
}
}
export declare class PluginService {
/**
*
* @param key key
* @param method
* @param params
* @returns
*/
invoke(key: string, method: string, ...params: any[]): Promise<any>;
/**
*
* @param key
* @returns
*/
getInstance(key: string): Promise<any>;
/**
*
* @param key
*/
checkStatus(key: string): Promise<void>;
}