mm_machine 1.8.3 → 1.8.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.
Files changed (3) hide show
  1. package/index.js +29 -19
  2. package/package.json +3 -3
  3. package/test.js +6 -1
package/index.js CHANGED
@@ -201,14 +201,16 @@ Item.prototype.loadFile = function(file) {
201
201
  var obj;
202
202
  var f = file.fullname(this.dir);
203
203
  var text = f.loadText();
204
- if (text) {
205
- obj = text.toJson();
206
- } else {
204
+ if (!text) {
207
205
  this.new_config(f);
208
- var text = f.loadText();
209
- if (text) {
210
- obj = text.toJson();
211
- }
206
+ text = f.loadText();
207
+ }
208
+ if (text) {
209
+ obj = $.loadJson(f, (mod) => {
210
+ if (mod) {
211
+ this.set_config(mod);
212
+ }
213
+ });
212
214
  }
213
215
  this.filename = f;
214
216
  return obj;
@@ -460,9 +462,11 @@ Index.prototype.load_list = function(list) {
460
462
  var obj;
461
463
  if (_this.mode) {
462
464
  obj = $.loadJson(file, function(config) {
463
- var plug = _this.get(config.name);
464
- if (plug) {
465
- plug.set_config(config);
465
+ if (config.name) {
466
+ var plug = _this.get(config.name);
467
+ if (plug) {
468
+ plug.set_config(config);
469
+ }
466
470
  }
467
471
  });
468
472
  } else {
@@ -494,8 +498,9 @@ Index.prototype.load_list = function(list) {
494
498
  /**
495
499
  * 加载配置
496
500
  * @param {String} path 检索路径
501
+ * @param {Boolean} accurate 精准路径,默认为false
497
502
  */
498
- Index.prototype.load = function(path) {
503
+ Index.prototype.load = function(path, accurate) {
499
504
  if (path) {
500
505
  if (!ph.isAbsolute(path)) {
501
506
  path = ph.join('app', path);
@@ -503,15 +508,20 @@ Index.prototype.load = function(path) {
503
508
  } else {
504
509
  path = './app/';
505
510
  }
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;
511
+ var list_scope = [];
512
+ if (!accurate) {
513
+ // 获取所有应用路径
514
+ var search_dir;
515
+ if (this.scope && this.scope !== $.val.scope) {
516
+ search_dir = this.type + '_' + this.scope;
517
+ } else {
518
+ search_dir = this.type;
519
+ }
520
+ list_scope = $.dir.getAll(path, search_dir);
521
+ }
522
+ else {
523
+ list_scope = $.dir.getAll(path);
513
524
  }
514
- var list_scope = $.dir.getAll(path, search_dir);
515
525
 
516
526
  // 遍历目录路径
517
527
  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.4",
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);