mm_machine 2.5.7 → 2.5.9
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 +56 -5
- 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,46 @@ Manager.prototype.offEvent = function (event) {
|
|
|
902
919
|
|
|
903
920
|
/**
|
|
904
921
|
* 创建模块
|
|
905
|
-
* @param {
|
|
922
|
+
* @param {object} config 模块配置
|
|
923
|
+
* @param {string} file 模块文件路径
|
|
924
|
+
* @returns {string} 创建的模块文件路径
|
|
906
925
|
*/
|
|
907
|
-
Manager.prototype.createFile = function (config) {
|
|
926
|
+
Manager.prototype.createFile = function (config, file) {
|
|
927
|
+
if (!config.name) {
|
|
928
|
+
throw new TypeError('模块名称不能为空');
|
|
929
|
+
}
|
|
930
|
+
if (!config.title) {
|
|
931
|
+
throw new TypeError('模块标题不能为空');
|
|
932
|
+
}
|
|
933
|
+
if (!config.description) {
|
|
934
|
+
throw new TypeError('模块描述不能为空');
|
|
935
|
+
}
|
|
936
|
+
if (this.getMod(config.name)) {
|
|
937
|
+
throw new Error(`创建失败,原因:模块${config.name}已存在`);
|
|
938
|
+
}
|
|
908
939
|
let mod = new this.Drive(config, this);
|
|
909
|
-
let
|
|
910
|
-
|
|
940
|
+
let f = file;
|
|
941
|
+
if (!f) {
|
|
942
|
+
f = `${config.name}/${this.config.filename}`;
|
|
943
|
+
if (this.config.search_way === 'dir') {
|
|
944
|
+
let dir_name = this._getDirName();
|
|
945
|
+
f = `${dir_name}/${f}`;
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
f = f.fullname(this.config.dir);
|
|
949
|
+
mod.createConfigFile(f, config);
|
|
950
|
+
return f;
|
|
951
|
+
};
|
|
952
|
+
|
|
953
|
+
/**
|
|
954
|
+
* 创建模块
|
|
955
|
+
* @param {object} config 模块配置
|
|
956
|
+
* @param {string} file 模块文件路径
|
|
957
|
+
* @returns {object} 创建的模块实例
|
|
958
|
+
*/
|
|
959
|
+
Manager.prototype.create = function (config, file = '') {
|
|
960
|
+
let f = this.createFile(config, file);
|
|
961
|
+
let mod = this.registerMod(f, config);
|
|
911
962
|
return mod;
|
|
912
963
|
};
|
|
913
964
|
|
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.9",
|
|
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": {
|