mm_machine 2.3.3 → 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.
- package/index.js +48 -4
- 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'
|
|
@@ -130,7 +137,7 @@ Manager.prototype.newInfo = function (name, sort, state, file = '') {
|
|
|
130
137
|
*/
|
|
131
138
|
Manager.prototype.setInfo = function (info) {
|
|
132
139
|
let has = false;
|
|
133
|
-
for(let i = 0; i < this.infos.length; i++) {
|
|
140
|
+
for (let i = 0; i < this.infos.length; i++) {
|
|
134
141
|
let o = this.infos[i];
|
|
135
142
|
if (o.name == info.name) {
|
|
136
143
|
this.infos[i] = info;
|
|
@@ -268,8 +275,12 @@ Manager.prototype.newMod = function (config_file, config, script) {
|
|
|
268
275
|
}
|
|
269
276
|
mod.mode = this.config.mode;
|
|
270
277
|
mod.loadConfig(config_file);
|
|
271
|
-
|
|
272
|
-
|
|
278
|
+
if (script) {
|
|
279
|
+
mod.setMethods(script);
|
|
280
|
+
}
|
|
281
|
+
if (config) {
|
|
282
|
+
mod.setConfig(config);
|
|
283
|
+
}
|
|
273
284
|
return mod;
|
|
274
285
|
};
|
|
275
286
|
|
|
@@ -362,6 +373,36 @@ Manager.prototype.loads = async function () {
|
|
|
362
373
|
await Promise.all(promises);
|
|
363
374
|
};
|
|
364
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
|
+
|
|
365
406
|
/**
|
|
366
407
|
* 检索目录下所有文件
|
|
367
408
|
* @private
|
|
@@ -379,6 +420,9 @@ Manager.prototype._findFiles = function (dir) {
|
|
|
379
420
|
this.log('warn', '目录不存在', dir);
|
|
380
421
|
return [];
|
|
381
422
|
}
|
|
423
|
+
if (this.config.search_way === 'dir') {
|
|
424
|
+
return this._getAllDirFiles(dir);
|
|
425
|
+
}
|
|
382
426
|
// 检索目录下所有文件
|
|
383
427
|
return $.file.getAll(dir, this.config.filename);
|
|
384
428
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_machine",
|
|
3
|
-
"version": "2.3.
|
|
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": {
|