mm_machine 2.3.4 → 2.3.5

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.
Files changed (2) hide show
  1. package/index.js +41 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -50,6 +50,13 @@ class Manager extends Mod {
50
50
  * @type {string}
51
51
  */
52
52
  mod_type: 'drive',
53
+ /**
54
+ * 搜索模式
55
+ * dir 按目录搜索
56
+ * file 按文件名搜索
57
+ * @type {string}
58
+ */
59
+ search_way: 'file',
53
60
  /**
54
61
  * 是否懒加载
55
62
  * @type {boolean}
@@ -71,7 +78,7 @@ class Manager extends Mod {
71
78
  */
72
79
  sort_key: 'sort',
73
80
  /**
74
- * 作用域(同时作为检索的后缀名)
81
+ * 作用域
75
82
  * @type {string}
76
83
  */
77
84
  scope: ($.val && $.val.scope) ? $.val.scope + '' : 'server'
@@ -366,6 +373,36 @@ Manager.prototype.loads = async function () {
366
373
  await Promise.all(promises);
367
374
  };
368
375
 
376
+ /**
377
+ * 获取目录名
378
+ * @returns {string} 目录名
379
+ */
380
+ Manager.prototype._getDirName = function () {
381
+ // 前缀,为当前类名
382
+ let prefix = this.constructor.name.toLowerCase();
383
+ // 后缀,为配置项名称
384
+ let name = this.config.name.toLowerCase();
385
+ // 目录名,为前缀加下划线加后缀
386
+ return prefix + "_" + name;
387
+ };
388
+
389
+ /**
390
+ * 获取所有目录下的文件
391
+ * @param {string} dir 目录路径
392
+ * @returns {Array} 文件路径数组
393
+ */
394
+ Manager.prototype._getAllDirFiles = function (dir) {
395
+ let files = [];
396
+ let dirs = $.dir.getAll(dir, this._getDirName());
397
+ for (let d of dirs) {
398
+ let list = $.file.getAll(d, this.config.filename);
399
+ if (list.length > 0) {
400
+ files.push(...list);
401
+ }
402
+ }
403
+ return files;
404
+ };
405
+
369
406
  /**
370
407
  * 检索目录下所有文件
371
408
  * @private
@@ -383,6 +420,9 @@ Manager.prototype._findFiles = function (dir) {
383
420
  this.log('warn', '目录不存在', dir);
384
421
  return [];
385
422
  }
423
+ if (this.config.search_way === 'dir') {
424
+ return this._getAllDirFiles(dir);
425
+ }
386
426
  // 检索目录下所有文件
387
427
  return $.file.getAll(dir, this.config.filename);
388
428
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "2.3.4",
3
+ "version": "2.3.5",
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": {