mm_machine 1.9.1 → 1.9.2

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 CHANGED
@@ -3,434 +3,9 @@
3
3
  * @author <a href="http://qww.elins.cn">邱文武</a>
4
4
  * @version 1.5
5
5
  */
6
- var conf = require('mm_config');
7
- const ph = require('path');
8
6
  const util = require('util');
9
- const Mod = require('mm_hot_reload');
10
-
11
- $.mod = new Mod();
12
- $.require = function(file, func) {
13
- return $.mod.load(file, func);
14
- }
15
- $.loadJson = function(file, func) {
16
- return $.mod.load(file, func);
17
- }
18
-
19
- /**
20
- * 驱动基础类
21
- * @class
22
- */
23
- class Item {
24
- /**
25
- * 构造函数
26
- * @param {String} dir 当前目录
27
- * @param {String} dir_base 模块目录
28
- * @constructor
29
- */
30
- constructor(dir, dir_base) {
31
- /**
32
- * 当前路径
33
- */
34
- this.dir = dir;
35
-
36
- /**
37
- * 默认文件
38
- */
39
- this.default_file = "./sys.json";
40
-
41
- // 当前文件
42
- this.filename;
43
- /* 通用项 */
44
- /**
45
- * 配置参数
46
- */
47
- this.config = {
48
- /**
49
- * 名称, 由中英文和下“_”组成, 用于卸载接口 例如: demo
50
- */
51
- "name": "",
52
- /**
53
- * 标题, 介绍作用
54
- */
55
- "title": "",
56
- /**
57
- * 描述, 用于描述该有什么用的
58
- */
59
- "description": "",
60
- /**
61
- * 文件路径, 当调用函数不存在时,会先从文件中加载
62
- */
63
- "func_file": "./index.js",
64
- /**
65
- * 回调函数名 用于决定调用脚本的哪个函数
66
- */
67
- "func_name": "",
68
- /**
69
- * 排序
70
- */
71
- "sort": 10,
72
- /**
73
- * 状态, 0表示未启用, 1表示启用
74
- */
75
- "state": 1,
76
- /**
77
- * 显示, 0表示不显示, 1表示显示
78
- */
79
- "show": 0
80
- };
81
-
82
- /**
83
- * 模块目录
84
- */
85
- this.dir_base = dir_base;
86
-
87
- /**
88
- * 模式
89
- * 1.生产模式,改变文件不会重新加载
90
- * 2.热更新模式,改变文件重新加载
91
- * 3.重载模式,执行完后重新加载,避免变量污染
92
- * 4.热更新+重载模式,改变文件重新加载,执行完后重新加载
93
- */
94
- this.mode = 1;
95
- }
96
- }
97
-
98
- /**
99
- * 设置配置
100
- * @param {Object} config 配置
101
- */
102
- Item.prototype.set_config = function(config) {
103
- this.config = conf(Object.assign({}, this.config, config || {}), this.filename);
104
- this.set_config_after();
105
- }
106
-
107
- /**
108
- * 设置配置后
109
- */
110
- Item.prototype.set_config_after = function() {
111
-
112
- };
113
-
114
- /**
115
- * 加载完成时
116
- */
117
- Item.prototype.load_after = function() {
118
-
119
- };
120
-
121
- /**
122
- * 新建脚本
123
- * @param {String} file
124
- */
125
- Item.prototype.new_script = function(file) {
126
- var fl = this.dir_base + "/script.js";
127
- if (fl.hasFile()) {
128
- fl.copyFile(file);
129
- }
130
- };
131
-
132
- /**
133
- * 移除模块
134
- * @param {Object} m
135
- */
136
- Item.prototype.remove_module = function(m) {
137
- // 移除模块和监听
138
- $.mod.unload(m);
139
- // var path = require.resolve(m);
140
- // delete require.cache[path];
141
- // require.cache[path] = null;
142
- };
143
-
144
- /**
145
- * 卸载对象
146
- * @param {String} file 文件
147
- */
148
- Item.prototype.unloadObj = function(file) {
149
- this.remove_module(file || this.config.func_file.fullname(this.dir));
150
- }
151
-
152
- /**
153
- * 卸载
154
- * @param {Boolean} remove 是否删除文件
155
- */
156
- Item.prototype.unload = function(remove) {
157
- this.unloadObj();
158
- if (remove) {
159
- this.remove_file();
160
- }
161
- }
162
-
163
- /**
164
- * 加载配置对象
165
- * @param {Object} obj 配置对象
166
- */
167
- Item.prototype.loadObj = function(config) {
168
- if (!config) {
169
- config = this.config;
170
- } else {
171
- this.set_config(config);
172
- config = this.config;
173
- }
174
- var f = config.func_file;
175
- if (f) {
176
- var file = f.fullname(this.dir);
177
- if (!file.hasFile()) {
178
- this.new_script(file);
179
- }
180
-
181
- var name = config.func_name;
182
- var cs;
183
- if (this.mode === 2 || this.mode === 4) {
184
- cs = $.require(file, (cs, way) => {
185
- if (way == "change" && cs) {
186
- if (name) {
187
- this.main = cs[name];
188
- } else {
189
- $.push(this, cs, true);
190
- }
191
- }
192
- });
193
- } else {
194
- cs = require(file);
195
- }
196
- if (cs) {
197
- if (name) {
198
- this.main = cs[name];
199
- } else {
200
- $.push(this, cs, true);
201
- }
202
- }
203
- }
204
- this.load_after();
205
- };
206
-
207
- /**
208
- * 新建配置
209
- * @param {String} file
210
- */
211
- Item.prototype.new_config = function(file) {
212
- var fl = this.dir_base + "/config.tpl.json";
213
- fl.copyFile(file);
214
- };
215
-
216
- /**
217
- * 加载配置文件
218
- * @param {String} file 文件路径
219
- * @param {String} name 配置项名称
220
- * @return {Object} 配置对象
221
- */
222
- Item.prototype.loadFile = function(file, name) {
223
- var config;
224
- var f = file.fullname(this.dir);
225
- var text = f.loadText();
226
- if (!text) {
227
- this.new_config(f);
228
- }
229
- if (text) {
230
- if (this.mode === 2 || this.mode === 4) {
231
- config = $.loadJson(f, (conf, way) => {
232
- if (way == "change" && conf) {
233
- if (Array.isArray(conf)) {
234
- var list = conf;
235
- for (var i = 0; i < list.length; i++) {
236
- var o = list[i];
237
- if (this.config.name === o.name) {
238
- this.set_config(o);
239
- break;
240
- }
241
- }
242
- } else {
243
- this.set_config(conf);
244
- }
245
- }
246
- });
247
- } else {
248
- config = f.loadJson();
249
- }
250
-
251
- if (name) {
252
- if (Array.isArray(config)) {
253
- var list = config;
254
- for (var i = 0; i < list.length; i++) {
255
- var o = list[i];
256
- if (name === o.name) {
257
- config = o;
258
- break;
259
- }
260
- }
261
- }
262
- }
263
- }
264
- this.dir = f.dirname();
265
- this.filename = f;
266
- return config;
267
- };
268
-
269
- /**
270
- * 重载配置和脚本
271
- */
272
- Item.prototype.reload = function() {
273
- this.unloadObj();
274
- this.load(this.filename, this.config.name);
275
- }
276
-
277
- /**
278
- * 删除脚本
279
- */
280
- Item.prototype.del_script = function() {
281
- var f = this.config.func_file;
282
- if (f) {
283
- $.dir.del(this.dir);
284
- }
285
- };
286
-
287
- /**
288
- * 删除配置和脚本文件
289
- * @param {Object} item 项目
290
- */
291
- Item.prototype.remove_file = function() {
292
- var name = this.config.name;
293
- var file = this.filename;
294
-
295
- var msg = null;
296
- if (file.hasFile()) {
297
- var text = file.loadText();
298
- if (text) {
299
- var jarr = text.toJson();
300
- if (jarr.constructor == Array) {
301
- for (var i = 0; i < jarr.length; i++) {
302
- var o = jarr[i];
303
- if (name === o.name) {
304
- this.del_script();
305
- jarr.splice(i, 1);
306
- break;
307
- }
308
- }
309
- if (jarr.length) {
310
- file.saveText(JSON.stringify(jarr, null, 4));
311
- } else {
312
- file.delFile();
313
- }
314
- } else {
315
- this.del_script();
316
- }
317
- } else {
318
- this.del_script();
319
- }
320
- } else {
321
- msg = "配置文件不存在";
322
- }
323
- return msg;
324
- };
325
-
326
- /**
327
- * 载入配置
328
- * @param {Object|String} cg 配置对象或配置路径
329
- * @param {String} name 配置名称
330
- */
331
- Item.prototype.load = function(cg, name) {
332
- var config;
333
- if (typeof(cg) === "string") {
334
- config = this.loadFile(cg, name);
335
- } else {
336
- config = cg;
337
- }
338
- this.loadObj(config);
339
- };
340
-
341
- /**
342
- * 保存配置
343
- */
344
- Item.prototype.save = function() {
345
- var f = this.filename.fullname(this.dir);
346
- var text = f.loadText();
347
- if (text) {
348
- if (text.trim().startsWith('[')) {
349
- var jarr = text.toJson();
350
- for (var i = 0; i < jarr.length; i++) {
351
- if (jarr[i].name === this.config.name) {
352
- jarr[i] = this.config;
353
- break;
354
- }
355
- }
356
- var txt = JSON.stringify(jarr, null, 4);
357
- f.saveText(txt);
358
- return;
359
- }
360
- }
361
- var txt = JSON.stringify(this.config, null, 4);
362
- f.saveText(txt);
363
- };
364
-
365
- /**
366
- * 主要执行函数
367
- * @param {Object} param1 参数一
368
- * @param {Object} param2 参数二
369
- */
370
- Item.prototype.main = async function(...params) {
371
- return null;
372
- };
373
-
374
- /**
375
- * 调用函数
376
- * @param {String} method 函数名
377
- * @param {Object} params 参数集合
378
- * @return {Object} 执行结果
379
- */
380
- Item.prototype.run = async function(method, ...params) {
381
- if (this[method]) {
382
- if (this[method + "_before"]) {
383
- try {
384
- this[method + "_before"](...params);
385
- } catch (err) {
386
- $.log.error("执行前失败!", err);
387
- }
388
- }
389
- var ret;
390
- try {
391
- ret = this[method](...params);
392
- } catch (err) {
393
- $.log.error("执行时失败!", err);
394
- }
395
- if (util.types.isPromise(ret)) {
396
- ret = await ret;
397
- }
398
- if (this[method + "_after"]) {
399
- try {
400
- ret = this[method + "_after"](ret, ...params) || ret;
401
- } catch (err) {
402
- $.log.error("执行后失败!", err);
403
- }
404
- }
405
- if (util.types.isPromise(ret)) {
406
- ret = await ret;
407
- }
408
- return ret
409
- }
410
- };
411
-
412
- /**
413
- * 运行指令
414
- * @param {Number} state 状态 0为不可以,1为可用
415
- * @param {Array} ...params 参数集合
416
- */
417
- Item.prototype.run_cmd = async function(state, ...params) {
418
- return this.run('cmd', state, ...param);
419
- };
420
-
421
- /**
422
- * 下达指令
423
- * @param {Number} state 状态 0为不可以,1为可用
424
- * @param {Array} ...params 参数集合
425
- */
426
- Item.prototype.cmd = function(state, ...params) {
427
- return null;
428
- }
429
-
430
- /**
431
- * @module 导出Drive类
432
- */
433
- exports.Item = Item;
7
+ const ph = require('path');
8
+ const Item = require('./item.js');
434
9
 
435
10
  /**
436
11
  * @class Index索引类
@@ -471,9 +46,10 @@ class Index {
471
46
  /**
472
47
  * 模式
473
48
  * 1.生产模式,改变文件不会重新加载
474
- * 2.热更新模式,改变文件重新加载
475
- * 3.重载模式,执行完后重新加载,避免变量污染
476
- * 4.热更新+重载模式,改变文件重新加载,执行完后重新加载
49
+ * 2.热更新模式,改变配置文件会重新加载配置,不重新加载脚本
50
+ * 3.热重载模式,改变配置文件都会加载配置和脚本
51
+ * 4.重载模式,执行完后重新加载脚本,避免变量污染
52
+ * 5.热更新+重载模式,改变配置文件重新加载配置和脚本,执行完后重新加载脚本
477
53
  */
478
54
  this.mode = 1;
479
55
  }
@@ -497,20 +73,15 @@ Index.prototype.Drive = Item;
497
73
  * @param {Object} cg 配置参数
498
74
  * @param {String} file 配置文件
499
75
  */
500
- Index.prototype.load_item = function(dir, cg, file) {
76
+ Index.prototype.load_item = async function(dir, cg, file) {
501
77
  if (this.Drive) {
502
- var drive = new this.Drive(dir);
78
+ var drive = new this.Drive(dir, this.dir_base.fullname());
79
+ drive.mode = this.mode;
503
80
  if (cg) {
504
- if (this.mode < 3) {
505
- drive.mode = this.mode;
506
- } else {
507
- drive.mode = 2;
508
- }
509
- drive.load(file);
81
+ await drive.run('load_config', file, cg.name);
510
82
  drive.set_config(cg);
511
83
  } else {
512
- drive.mode = this.mode;
513
- drive.load(file);
84
+ await drive.run('load_config', file);
514
85
  }
515
86
  this.list.push(drive);
516
87
  return drive;
@@ -534,19 +105,46 @@ Index.prototype.load_item = function(dir, cg, file) {
534
105
  * 加载列表
535
106
  * @param {Array} list 文件列表
536
107
  */
537
- Index.prototype.load_list = function(list) {
108
+ Index.prototype.load_list = async function(list) {
538
109
  // 遍历文件路径
539
- list.map((file) => {
540
- this.load_file(file, true);
110
+ for (var i = 0; i < list.length; i++) {
111
+ var file = list[i];
112
+ await this.load_file(file, true);
113
+ }
114
+ };
115
+
116
+ /**
117
+ * 排序
118
+ */
119
+ Index.prototype.sort = function() {
120
+ var _this = this;
121
+ this.list.sort(function(o1, o2) {
122
+ var p1 = o1.config[_this.sort_key];
123
+ var p2 = o2.config[_this.sort_key];
124
+ return p2 - p1;
541
125
  });
542
126
  };
543
127
 
544
128
  /**
545
- * 加载配置
129
+ * 更新前
130
+ */
131
+ Index.prototype.update_before = async function(dir) {
132
+ // console.log("更新前")
133
+ }
134
+
135
+ /**
136
+ * 更新后
137
+ */
138
+ Index.prototype.update_after = async function(dir) {
139
+ // console.log("更新后")
140
+ }
141
+
142
+ /**
143
+ * 更新所有配置
546
144
  * @param {String} path 检索路径
547
145
  * @param {Boolean} accurate 精准路径,默认为false
548
146
  */
549
- Index.prototype.load = function(path, accurate) {
147
+ Index.prototype.update_config_all = async function(path, accurate) {
550
148
  if (path) {
551
149
  if (!ph.isAbsolute(path)) {
552
150
  path = ph.join('app', path);
@@ -569,71 +167,70 @@ Index.prototype.load = function(path, accurate) {
569
167
  list_scope = $.dir.getAll(path);
570
168
  }
571
169
  } catch (err) {
572
- $.log.error("检索目录失败!", err);
170
+ console.error("检索目录失败!", err);
573
171
  }
574
172
 
575
- // 遍历目录路径
576
- list_scope.map((f) => {
173
+ for (var i = 0; i < list_scope.length; i++) {
174
+ var f = list_scope[i];
577
175
  // 获取所有配置文件
578
176
  var list_file = $.file.getAll(f, "*" + this.type + ".json");
579
- this.load_list(list_file);
580
- });
581
- };
582
-
583
- /**
584
- * 排序
585
- */
586
- Index.prototype.sort = function() {
587
- var _this = this;
588
- this.list.sort(function(o1, o2) {
589
- var p1 = o1.config[_this.sort_key];
590
- var p2 = o2.config[_this.sort_key];
591
- return p2 - p1;
592
- });
177
+ await this.load_list(list_file);
178
+ }
593
179
  };
594
180
 
595
-
596
181
  /**
597
- * 更新前
182
+ * 更新配置
183
+ * @param {Object} dir
598
184
  */
599
- Index.prototype.update_before = async function(dir) {
600
- // console.log("更新前")
185
+ Index.prototype.update_config_have = async function(dir) {
186
+ var list = this.list;
187
+ for (var i = 0; i < list.length; i++) {
188
+ var o = list[i];
189
+ var file = o.filename;
190
+ if (file) {
191
+ var config = file.loadJson();
192
+ if (config) {
193
+ if (Array.isArray(config)) {
194
+ var lt = config;
195
+ for (var n = 0; n < lt.length; n++) {
196
+ var cg = lt[n];
197
+ if (cg.name == o.config.name) {
198
+ o.set_config(cg);
199
+ continue;
200
+ }
201
+ }
202
+ } else {
203
+ o.set_config(config);
204
+ }
205
+ }
206
+ }
207
+ }
601
208
  }
602
209
 
603
210
  /**
604
- * 更新后
211
+ * 更新配置
212
+ * @param {Object} dir
605
213
  */
606
- Index.prototype.update_after = async function(dir) {
607
- // console.log("更新后")
214
+ Index.prototype.update_config = async function(dir, accurate = false, clear = false) {
215
+ if (clear) {
216
+ this.clear();
217
+ await this.update_config_all(dir, accurate);
218
+ } else {
219
+ // 如果没有指定目录,则更新已有的配置文件
220
+ await this.update_config_have();
221
+ }
222
+ this.sort();
608
223
  }
609
224
 
610
225
  /**
611
- * 更新配置
612
- * @param {Object} dir
226
+ * 更新JS
613
227
  */
614
- Index.prototype.update_config = async function(dir) {
615
- if (!dir) {
616
- var list = this.list;
617
- for (var i = 0; i < list.length; i++) {
618
- var o = list[i];
619
- var file = o.filename;
620
- if (file) {
621
- var config = file.loadJson();
622
- if (config) {
623
- if (Array.isArray(config)) {
624
- var lt = config;
625
- for (var n = 0; n < lt.length; n++) {
626
- var cg = lt[n];
627
- if (cg.name == o.config.name) {
628
- o.set_config(cg);
629
- continue;
630
- }
631
- }
632
- } else {
633
- o.set_config(config);
634
- }
635
- }
636
- }
228
+ Index.prototype.update_script = async function() {
229
+ var list = this.list;
230
+ for (var i = 0; i < list.length; i++) {
231
+ var o = list[i];
232
+ if (o.config.state === 1) {
233
+ await o.run('load');
637
234
  }
638
235
  }
639
236
  }
@@ -643,14 +240,11 @@ Index.prototype.update_config = async function(dir) {
643
240
  * @param {String} dir 检索的路径
644
241
  * @param {Boolean} loadJS 是否加载JS
645
242
  */
646
- Index.prototype.update_main = async function(dir, loadJS = true) {
243
+ Index.prototype.update_main = async function(dir, accurate = false, loadJS = true, clear = true) {
244
+ await this.update_config(dir, accurate, clear);
647
245
  if (loadJS) {
648
- this.clear();
649
- this.load(dir);
650
- } else {
651
- this.update_config(dir);
246
+ await this.update_script();
652
247
  }
653
- this.sort();
654
248
  }
655
249
 
656
250
  /**
@@ -658,9 +252,9 @@ Index.prototype.update_main = async function(dir, loadJS = true) {
658
252
  * @param {String} dir 检索的路径
659
253
  * @param {Boolean} loadJS 是否加载JS
660
254
  */
661
- Index.prototype.update = async function(dir, loadJS = true) {
255
+ Index.prototype.update = async function(dir, accurate = false, loadJS = true, clear = true) {
662
256
  await this.update_before(dir);
663
- await this.update_main(dir, loadJS);
257
+ await this.update_main(dir, accurate, loadJS, clear);
664
258
  await this.update_after(dir);
665
259
  };
666
260
 
@@ -683,20 +277,6 @@ Index.prototype.get = function(name) {
683
277
  return obj;
684
278
  };
685
279
 
686
- /**
687
- * 下达指令
688
- * @param {String} name 名称
689
- * @param {Number} state 状态
690
- * @param {Array} ...params 参数集合
691
- */
692
- Index.prototype.cmd = async function(name, state, ...params) {
693
- var obj = this.get(name);
694
- if (!obj) {
695
- return "error: program does not exist";
696
- }
697
- return await obj.run("cmd", state, ...params);
698
- }
699
-
700
280
  /**
701
281
  * 查询配置项
702
282
  * @param {String} name 名称
@@ -736,7 +316,7 @@ Index.prototype.save = function(name) {
736
316
  * @param {Object} obj 配置参数
737
317
  * @return {String} 失败返回错误提示,成功返回null
738
318
  */
739
- Index.prototype.add = function(obj) {
319
+ Index.prototype.add = async function(obj) {
740
320
  var f = obj.filename;
741
321
  if (!f) {
742
322
  return "文件保存路径不能为空";
@@ -774,7 +354,7 @@ Index.prototype.add = function(obj) {
774
354
  f.saveText(JSON.stringify(obj.config, null, 4));
775
355
  }
776
356
  } else {
777
- this.load_item(f.dirname(), obj.config, f);
357
+ await this.load_item(f.dirname(), obj.config, f);
778
358
  this.save(name);
779
359
  }
780
360
  return null;
@@ -802,64 +382,80 @@ Index.prototype.del = function(name, remove) {
802
382
  return obj;
803
383
  };
804
384
 
385
+ /**
386
+ * 加载模块
387
+ * @param {String} name 模块名称
388
+ * @return {String} 失败返回null,成功返回文件路径
389
+ */
390
+ Index.prototype.load = async function(name) {
391
+ var o = this.get(name);
392
+ var file = null;
393
+ if (o) {
394
+ await o.run('load');
395
+ file = o.filename;
396
+ }
397
+ return file;
398
+ }
399
+
805
400
  /**
806
401
  * 卸载模块
807
402
  * @param {String} name 模块名称
808
403
  * @param {Boolean} remove 是否删除配置文件
809
404
  * @return {String} 失败返回null,成功返回文件路径
810
405
  */
811
- Index.prototype.unload = function(name, remove) {
406
+ Index.prototype.unload = async function(name, remove) {
812
407
  var o = this.del(name, remove);
813
408
  var file = null;
814
409
  if (o) {
815
- o.unload(remove);
410
+ await o.run('unload', remove);
816
411
  file = o.filename;
817
412
  }
818
413
  return file;
819
414
  }
820
415
 
416
+ /**
417
+ * 重载脚本和配置
418
+ * @param {String} file 文件名
419
+ * @return {String} 重载失败返回错误提示,重载成功返回null
420
+ */
421
+ Index.prototype.reload = async function(name) {
422
+ var o = this.get(name);
423
+ if (o) {
424
+ await o.run('reload');
425
+ return o.filename;
426
+ }
427
+ return '没有找到模块';
428
+ }
429
+
821
430
  /**
822
431
  * 通过文件加载配置
823
432
  * @param {String} file 文件名
824
433
  * @param {Boolean} create 不存在则进行创建
825
434
  * @return {String} 加载失败返回错误提示,加载成功返回null
826
435
  */
827
- Index.prototype.load_file = function(file, create = false) {
436
+ Index.prototype.load_file = async function(file, create = false) {
828
437
  var _this = this;
829
438
  var dir = file.dirname();
830
439
  // 载入文件
831
440
  var obj = file.loadJson();
832
441
  if (obj) {
833
442
  if (obj.constructor == Array) {
834
- obj.map(function(o) {
443
+ for (var i = 0; i < obj.length; i++) {
444
+ var o = obj[i];
835
445
  // 实例化一个驱动
836
- _this.load_item(dir, o, file);
837
- });
446
+ await _this.load_item(dir, o, file);
447
+ }
838
448
  } else {
839
- return _this.load_item(dir, null, file);
449
+ return await _this.load_item(dir, null, file);
840
450
  }
841
451
  } else if (create) {
842
- return _this.load_item(dir, null, file);
452
+ return await _this.load_item(dir, null, file);
843
453
  } else {
844
454
  return file + "文件不存在";
845
455
  }
846
456
  return null;
847
457
  };
848
458
 
849
- /**
850
- * 重载脚本和配置
851
- * @param {String} file 文件名
852
- * @return {String} 重载失败返回错误提示,重载成功返回null
853
- */
854
- Index.prototype.reload = function(name) {
855
- var o = this.get(name);
856
- if (o) {
857
- o.reload();
858
- return null;
859
- }
860
- return '没有找到模块';
861
- }
862
-
863
459
  /**
864
460
  * 调用函数
865
461
  * @param {String} name 模块名
@@ -878,8 +474,8 @@ Index.prototype.run = async function(name, method, ...params) {
878
474
  } else {
879
475
  result = ret;
880
476
  }
881
- if (this.mode > 2) {
882
- o.reload();
477
+ if (this.mode >= 4) {
478
+ o.run('reload');
883
479
  }
884
480
  }
885
481
  } else if (name === null) {
@@ -893,6 +489,9 @@ Index.prototype.run = async function(name, method, ...params) {
893
489
  } else {
894
490
  result = ret;
895
491
  }
492
+ if (this.mode >= 4) {
493
+ o.run('reload');
494
+ }
896
495
  }
897
496
  }
898
497
  }
@@ -911,33 +510,42 @@ Index.prototype.exec = async function(name, method, ...params) {
911
510
  if (name) {
912
511
  var o = await this.get(name);
913
512
  if (o) {
513
+ if (!o.complete) {
514
+ await o.run('load');
515
+ }
914
516
  var ret = o.run(method, ...params);
915
517
  if (util.types.isPromise(ret)) {
916
518
  result = await ret;
917
519
  } else {
918
520
  result = ret;
919
521
  }
920
- if (this.mode > 2) {
921
- o.reload();
522
+ if (this.mode >= 4) {
523
+ await o.run('reload');
922
524
  }
923
525
  }
924
526
  } else if (name === null) {
925
527
  var lt = this.list;
926
528
  for (var i = 0; i < lt.length; i++) {
927
529
  var o = lt[i];
530
+ if (!o.complete) {
531
+ await o.run('load');
532
+ }
928
533
  var ret = o.run(method, ...params);
929
534
  if (util.types.isPromise(ret)) {
930
535
  result = await ret;
931
536
  } else {
932
537
  result = ret;
933
538
  }
539
+ if (this.mode >= 4) {
540
+ await o.run('reload');
541
+ }
934
542
  }
935
543
  }
936
544
  return result;
937
545
  };
938
546
 
939
-
940
547
  /**
941
548
  * @module 导出Index类
942
549
  */
943
- exports.Index = Index;
550
+ exports.Index = Index;
551
+ exports.Item = Item;