mm_machine 3.4.1 → 3.4.4

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/lib/drive.js CHANGED
@@ -195,7 +195,7 @@ Drive.prototype._initOptions = function () {
195
195
  * @returns {string} 缓存目录
196
196
  */
197
197
  Drive.prototype._getCacheDir = function () {
198
- return './cache/options'.fullname();
198
+ return './cache/options'.fullname($.run_path);
199
199
  };
200
200
 
201
201
  /**
@@ -203,23 +203,8 @@ Drive.prototype._getCacheDir = function () {
203
203
  * @returns {string} 选项缓存文件名
204
204
  */
205
205
  Drive.prototype._getOptionsFileName = function () {
206
- // 先获取上级名
207
- let parent = this.getParent();
208
- let parent_name = '';
209
- if (parent) {
210
- // 获取上级构造名
211
- let constructor_name = parent.constructor.name || '';
212
- // 再获取上级名称
213
- let mod_name = parent.config?.name || '';
214
- parent_name = constructor_name + '_' + mod_name;
215
- }
216
-
217
- // 再获取当前模块名
218
- let current_name = this.constructor.name + '_' + (this.config.name || 'default');
219
- if (parent_name) {
220
- current_name = parent_name + '/' + current_name;
221
- }
222
- return `./${current_name}.json`.toLowerCase();
206
+ var current_name = this.constructor.name + '_' + (this.config.name || 'default');
207
+ return './' + current_name.toLowerCase() + '.json';
223
208
  };
224
209
 
225
210
  /**
package/lib/manager.js CHANGED
@@ -82,8 +82,16 @@ class Manager extends Mod {
82
82
  * @type {string}
83
83
  */
84
84
  scope: $.val && $.val.scope ? $.val.scope + '' : 'server',
85
- // 事件触发器
86
- trigger_key: []
85
+ /**
86
+ * 最大搜索深度 -1表示不限制深度
87
+ * @type {number}
88
+ */
89
+ max_depth: 3,
90
+ /**
91
+ * 忽略目录数组
92
+ * @type {Array}
93
+ */
94
+ ignore: ['node_modules', '.git']
87
95
  };
88
96
 
89
97
  /**
@@ -102,7 +110,7 @@ class Manager extends Mod {
102
110
  parent
103
111
  );
104
112
 
105
- this.scanner = new Scanner();
113
+ this.scanner = new Scanner(this.config.ignore, this.config.max_depth);
106
114
  // 模块
107
115
  this.mods = mods;
108
116
  // 不使用注册表时,用内部缓存记录模块条目信息
package/lib/scanner.js CHANGED
@@ -1,3 +1,5 @@
1
+ require('mm_expand');
2
+
1
3
  /**
2
4
  * 扫描类
3
5
  * 负责按目录或文件名模式检索文件
@@ -5,15 +7,10 @@
5
7
  class Scanner {
6
8
  /**
7
9
  * 构造函数
8
- * @param {object} config 配置项
9
10
  */
10
- constructor(config) {
11
- this.config = Object.assign(
12
- {
13
- ignore: ['*/node_modules/*', '*/.git/*', '*/cache/*', '*/backup/*']
14
- },
15
- config
16
- );
11
+ constructor(ignore, max_depth = 3) {
12
+ this.ignore = ignore || ['node_modules', '.git'];
13
+ this.max_depth = max_depth;
17
14
  }
18
15
  }
19
16
 
@@ -23,13 +20,15 @@ class Scanner {
23
20
  * @param {string} dir 根目录
24
21
  * @param {string} filename 目标文件名
25
22
  * @param {string} dirname 目标目录名
23
+ * @param {number} max_depth 最大搜索深度 -1表示不限制深度
24
+ * @param {Array} ignore 忽略目录数组
26
25
  * @returns {Array} 文件路径数组
27
26
  */
28
- Scanner.prototype.scan = async function (dir, filename, dirname) {
29
- let dirs = await this.scanDir(dir, dirname);
27
+ Scanner.prototype.scan = async function (dir, filename, dirname, ignore = this.ignore, max_depth = this.max_depth) {
28
+ let dirs = await this.scanDir(dir, dirname, ignore, max_depth);
30
29
  let results = await Promise.all(
31
30
  dirs.map((d) => {
32
- return $.file.getAllAsync(d, filename);
31
+ return $.file.getAllAsync(d, filename, undefined, ignore, max_depth);
33
32
  })
34
33
  );
35
34
  return results.flat();
@@ -40,10 +39,12 @@ Scanner.prototype.scan = async function (dir, filename, dirname) {
40
39
  * 在指定目录下找所有匹配 dirname 的子目录
41
40
  * @param {string} dir 根目录
42
41
  * @param {string} dirname 目标目录名
42
+ * @param {number} max_depth 最大搜索深度 -1表示不限制深度
43
+ * @param {Array} ignore 忽略目录数组
43
44
  * @returns {Array} 目录路径数组
44
45
  */
45
- Scanner.prototype.scanDir = async function (dir, dirname) {
46
- return await $.dir.getAllAsync(dir, dirname);
46
+ Scanner.prototype.scanDir = async function (dir, dirname, ignore = this.ignore, max_depth = this.max_depth) {
47
+ return await $.dir.getAllAsync(dir, dirname, ignore, max_depth);
47
48
  };
48
49
 
49
50
  /**
@@ -51,10 +52,12 @@ Scanner.prototype.scanDir = async function (dir, dirname) {
51
52
  * 在指定目录下找所有匹配 filename 的文件
52
53
  * @param {string} dir 根目录
53
54
  * @param {string} filename 目标文件名
55
+ * @param {number} max_depth 最大搜索深度 -1表示不限制深度
56
+ * @param {Array} ignore 忽略目录数组
54
57
  * @returns {Array} 文件路径数组
55
58
  */
56
- Scanner.prototype.scanFile = async function (dir, filename) {
57
- return await $.file.getAllAsync(dir, filename);
59
+ Scanner.prototype.scanFile = async function (dir, filename, ignore = this.ignore, max_depth = this.max_depth) {
60
+ return await $.file.getAllAsync(dir, filename, undefined, ignore, max_depth);
58
61
  };
59
62
 
60
63
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "3.4.1",
3
+ "version": "3.4.4",
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": {
@@ -33,9 +33,9 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "@prettier/sync": "^0.6.1",
36
- "mm_config": "^2.4.6",
37
- "mm_hot_reload": "^1.4.3",
38
- "mm_tpl": "^2.6.6"
36
+ "mm_config": "^2.4.8",
37
+ "mm_hot_reload": "^1.4.7",
38
+ "mm_tpl": "^2.6.8"
39
39
  },
40
40
  "devDependencies": {
41
41
  "eslint": "^10.8.1",