diff --git a/plugin-cli/package.json b/plugin-cli/package.json index be82352..3b18454 100644 --- a/plugin-cli/package.json +++ b/plugin-cli/package.json @@ -1,6 +1,6 @@ { "name": "@cool-midway/plugin-cli", - "version": "7.1.8", + "version": "7.1.9", "description": "cool-admin midway plugin", "main": "dist/index.js", "scripts": { @@ -30,6 +30,7 @@ "esbuild-plugin-copy": "^2.1.1" }, "devDependencies": { + "@types/node": "^20.12.7", "typescript": "^5.3.3" } } diff --git a/plugin-cli/src/index.ts b/plugin-cli/src/index.ts index e58e8e9..7ce6682 100644 --- a/plugin-cli/src/index.ts +++ b/plugin-cli/src/index.ts @@ -52,6 +52,8 @@ export abstract class BasePlugin { cache: FsCacheStore | MidwayCache; /** 插件 */ pluginService: PluginService; + /** 基础目录位置 */ + baseDir: string; setCtx(ctx: IMidwayContext) { this.ctx = ctx; @@ -59,6 +61,8 @@ export abstract class BasePlugin { setApp(app: IMidwayApplication) { this.app = app; + this.baseDir = app.getBaseDir(); + this.configDir(); } constructor() {} @@ -96,6 +100,11 @@ export abstract class BasePlugin { this.pluginInfo = pluginInfo; this.ctx = ctx; this.app = app; + this.baseDir = process.cwd(); + if (this.app) { + this.baseDir = this.app?.getBaseDir(); + } + this.configDir(); this.cache = CoolCacheStore({}); if (other) { this.cache = other.cache; @@ -104,6 +113,19 @@ export abstract class BasePlugin { await this.ready(); } + /** + * 处理配置目录 + */ + private configDir() { + // 替换\为/ + this.baseDir = this.baseDir.replace(/\\/g, "/"); + let config = this.pluginInfo.config || {}; + config = JSON.stringify(config); + this.pluginInfo.config = JSON.parse( + config.replace(/@baseDir/g, this.baseDir) + ); + } + /** * 插件就绪 */