mm_machine 2.5.7 → 2.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/drive.js +7 -1
- package/index.js +49 -3
- package/mod.js +9 -0
- package/package.json +1 -1
package/drive.js
CHANGED
|
@@ -163,6 +163,12 @@ Drive.prototype._getDir = function () {
|
|
|
163
163
|
dir = this.config_file.dirname();
|
|
164
164
|
this._dir = dir;
|
|
165
165
|
}
|
|
166
|
+
else if (this.getParent) {
|
|
167
|
+
let parent_dir = this.getParent()?.getDir() || '';
|
|
168
|
+
if (parent_dir) {
|
|
169
|
+
dir = this.config.name.fullname(parent_dir);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
166
172
|
}
|
|
167
173
|
return dir;
|
|
168
174
|
};
|
|
@@ -172,7 +178,7 @@ Drive.prototype._getDir = function () {
|
|
|
172
178
|
* @returns {string} 模板目录
|
|
173
179
|
*/
|
|
174
180
|
Drive.prototype._getTplDir = function () {
|
|
175
|
-
return this.getParent()
|
|
181
|
+
return this.getParent()?.getTplDir() || '';
|
|
176
182
|
};
|
|
177
183
|
|
|
178
184
|
/**
|
package/index.js
CHANGED
|
@@ -597,12 +597,29 @@ Manager.prototype._initManager = function () {
|
|
|
597
597
|
|
|
598
598
|
};
|
|
599
599
|
|
|
600
|
+
/**
|
|
601
|
+
* 获取公共模块目录
|
|
602
|
+
* @returns {string} 公共模块目录
|
|
603
|
+
*/
|
|
604
|
+
Manager.prototype.getBaseDir = function () {
|
|
605
|
+
return this.config.base_dir;
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* 获取二次开发模块目录
|
|
610
|
+
* @returns {string} 二次开发模块目录
|
|
611
|
+
*/
|
|
612
|
+
Manager.prototype.getDir = function () {
|
|
613
|
+
return this.config.dir || this._getDir();
|
|
614
|
+
};
|
|
615
|
+
|
|
600
616
|
/**
|
|
601
617
|
* 加载资源
|
|
602
618
|
*/
|
|
603
619
|
Manager.prototype._loadSources = async function () {
|
|
604
620
|
// 通过更新函数加载资源信息
|
|
605
|
-
let
|
|
621
|
+
let base_dir = this.getBaseDir();
|
|
622
|
+
let dir = this.getDir();
|
|
606
623
|
if (base_dir) {
|
|
607
624
|
await this.call('update', base_dir);
|
|
608
625
|
await this.call('update', dir, false);
|
|
@@ -902,12 +919,41 @@ Manager.prototype.offEvent = function (event) {
|
|
|
902
919
|
|
|
903
920
|
/**
|
|
904
921
|
* 创建模块
|
|
905
|
-
* @param {
|
|
922
|
+
* @param {object} config 模块配置
|
|
923
|
+
* @returns {string} 创建的模块文件路径
|
|
906
924
|
*/
|
|
907
925
|
Manager.prototype.createFile = function (config) {
|
|
926
|
+
if (!config.name) {
|
|
927
|
+
throw new TypeError('模块名称不能为空');
|
|
928
|
+
}
|
|
929
|
+
if (!config.title) {
|
|
930
|
+
throw new TypeError('模块标题不能为空');
|
|
931
|
+
}
|
|
932
|
+
if (!config.description) {
|
|
933
|
+
throw new TypeError('模块描述不能为空');
|
|
934
|
+
}
|
|
935
|
+
if (this.getMod(config.name)) {
|
|
936
|
+
throw new Error(`创建失败,原因:模块${config.name}已存在`);
|
|
937
|
+
}
|
|
908
938
|
let mod = new this.Drive(config, this);
|
|
909
|
-
let file = `${config.name}/${this.config.filename}
|
|
939
|
+
let file = `${config.name}/${this.config.filename}`;
|
|
940
|
+
if (this.config.search_way === 'dir') {
|
|
941
|
+
let dir_name = this._getDirName();
|
|
942
|
+
file = `${dir_name}/${file}`;
|
|
943
|
+
}
|
|
944
|
+
file = file.fullname(this.config.dir);
|
|
910
945
|
mod.createConfigFile(file, config);
|
|
946
|
+
return file;
|
|
947
|
+
};
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* 创建模块
|
|
951
|
+
* @param {object} config 模块配置
|
|
952
|
+
* @returns {object} 创建的模块实例
|
|
953
|
+
*/
|
|
954
|
+
Manager.prototype.create = function (config) {
|
|
955
|
+
let file = this.createFile(config);
|
|
956
|
+
let mod = this.registerMod(file, config);
|
|
911
957
|
return mod;
|
|
912
958
|
};
|
|
913
959
|
|
package/mod.js
CHANGED
|
@@ -660,6 +660,15 @@ Mod.prototype._destroyCore = async function () {
|
|
|
660
660
|
this._methods = {};
|
|
661
661
|
};
|
|
662
662
|
|
|
663
|
+
/**
|
|
664
|
+
* 获取模块目录
|
|
665
|
+
* @returns {string} 模块目录
|
|
666
|
+
*/
|
|
667
|
+
Mod.prototype._getDir = function () {
|
|
668
|
+
if (!this.getParent) return '';
|
|
669
|
+
return this.getParent()?.getDir() || '';
|
|
670
|
+
};
|
|
671
|
+
|
|
663
672
|
module.exports = {
|
|
664
673
|
Mod
|
|
665
674
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_machine",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.8",
|
|
4
4
|
"description": "A flexible Node.js plugin mechanism system for dynamic loading, management and execution of modules. Supports hot reload, lifecycle management, and modern JavaScript features.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|