新增路径配置

This commit is contained in:
cool 2024-04-16 11:15:29 +08:00
parent b526c75161
commit fc23c816b2
2 changed files with 24 additions and 1 deletions

View File

@ -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"
}
}

View File

@ -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)
);
}
/**
*
*/