mm_machine 1.8.3 → 1.8.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 (3) hide show
  1. package/index.js +37 -19
  2. package/package.json +3 -3
  3. package/test.js +6 -1
package/index.js CHANGED
@@ -92,8 +92,16 @@ class Item {
92
92
  */
93
93
  Item.prototype.set_config = function(config) {
94
94
  this.config = conf(Object.assign({}, this.config, config || {}), this.filename);
95
+ this.set_config_after();
95
96
  }
96
97
 
98
+ /**
99
+ * 设置配置后
100
+ */
101
+ Item.prototype.set_config_after = function() {
102
+
103
+ };
104
+
97
105
  /**
98
106
  * 加载完成时
99
107
  */
@@ -201,14 +209,16 @@ Item.prototype.loadFile = function(file) {
201
209
  var obj;
202
210
  var f = file.fullname(this.dir);
203
211
  var text = f.loadText();
204
- if (text) {
205
- obj = text.toJson();
206
- } else {
212
+ if (!text) {
207
213
  this.new_config(f);
208
- var text = f.loadText();
209
- if (text) {
210
- obj = text.toJson();
211
- }
214
+ text = f.loadText();
215
+ }
216
+ if (text) {
217
+ obj = $.loadJson(f, (mod) => {
218
+ if (mod) {
219
+ this.set_config(mod);
220
+ }
221
+ });
212
222
  }
213
223
  this.filename = f;
214
224
  return obj;
@@ -460,9 +470,11 @@ Index.prototype.load_list = function(list) {
460
470
  var obj;
461
471
  if (_this.mode) {
462
472
  obj = $.loadJson(file, function(config) {
463
- var plug = _this.get(config.name);
464
- if (plug) {
465
- plug.set_config(config);
473
+ if (config.name) {
474
+ var plug = _this.get(config.name);
475
+ if (plug) {
476
+ plug.set_config(config);
477
+ }
466
478
  }
467
479
  });
468
480
  } else {
@@ -494,8 +506,9 @@ Index.prototype.load_list = function(list) {
494
506
  /**
495
507
  * 加载配置
496
508
  * @param {String} path 检索路径
509
+ * @param {Boolean} accurate 精准路径,默认为false
497
510
  */
498
- Index.prototype.load = function(path) {
511
+ Index.prototype.load = function(path, accurate) {
499
512
  if (path) {
500
513
  if (!ph.isAbsolute(path)) {
501
514
  path = ph.join('app', path);
@@ -503,15 +516,20 @@ Index.prototype.load = function(path) {
503
516
  } else {
504
517
  path = './app/';
505
518
  }
506
-
507
- // 获取所有应用路径
508
- var search_dir;
509
- if (this.scope && this.scope !== $.val.scope) {
510
- search_dir = this.type + '_' + this.scope;
511
- } else {
512
- search_dir = this.type;
519
+ var list_scope = [];
520
+ if (!accurate) {
521
+ // 获取所有应用路径
522
+ var search_dir;
523
+ if (this.scope && this.scope !== $.val.scope) {
524
+ search_dir = this.type + '_' + this.scope;
525
+ } else {
526
+ search_dir = this.type;
527
+ }
528
+ list_scope = $.dir.getAll(path, search_dir);
529
+ }
530
+ else {
531
+ list_scope = $.dir.getAll(path);
513
532
  }
514
- var list_scope = $.dir.getAll(path, search_dir);
515
533
 
516
534
  // 遍历目录路径
517
535
  list_scope.map((f) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "1.8.3",
3
+ "version": "1.8.5",
4
4
  "description": "这是超级美眉框架机制构建辅助模块,用于快速构建一个机制",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "homepage": "https://github.com/qiuwenwu/mm_machine#readme",
32
32
  "dependencies": {
33
- "mm_config": "^1.1.3",
34
- "mm_hot_reload": "^1.0.4"
33
+ "mm_config": "^1.1.4",
34
+ "mm_hot_reload": "^1.0.5"
35
35
  }
36
36
  }
package/test.js CHANGED
@@ -30,6 +30,11 @@ async function demo() {
30
30
  await engine.exec('demo1', 'init');
31
31
  await engine.run(null, 'main');
32
32
  await engine.exec(null, 'main');
33
+
34
+ var plug = engine.get('demo1');
35
+ if (plug) {
36
+ plug.loadFile(plug.filename);
37
+ }
33
38
  // console.log("模块数", engine.list.length);
34
39
 
35
40
  // var i = 0;
@@ -76,7 +81,7 @@ async function demo() {
76
81
  // text = text.replace("1234567", "7654321");
77
82
  // file.saveText(text);
78
83
  // }, 26000)
79
-
84
+
80
85
  setInterval(() => {
81
86
  var plug = engine.get("demo1");
82
87
  console.log("查看变化", plug);