mm_machine 1.4.4 → 1.4.7

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 +24 -15
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -35,7 +35,7 @@ class Item {
35
35
  /**
36
36
  * 配置参数
37
37
  */
38
- this.config = conf({
38
+ this.config = {
39
39
  /**
40
40
  * 名称, 由中英文和下“_”组成, 用于卸载接口 例如: demo
41
41
  */
@@ -61,10 +61,10 @@ class Item {
61
61
  */
62
62
  "sort": 10,
63
63
  /**
64
- * 开关, true表示开启,false表示关闭
64
+ * 状态, 1表示开启,0表示未开启
65
65
  */
66
- "switch": true
67
- });
66
+ "state": 1
67
+ };
68
68
 
69
69
  /**
70
70
  * 模块目录
@@ -73,6 +73,14 @@ class Item {
73
73
  }
74
74
  }
75
75
 
76
+ /**
77
+ * 设置配置
78
+ * @param {Object} config 配置
79
+ */
80
+ Item.prototype.set_config = function(config){
81
+ this.config = conf(Object.assign(this.config, config || {}));
82
+ }
83
+
76
84
  /**
77
85
  * @description 加载完成时
78
86
  */
@@ -105,16 +113,15 @@ Item.prototype.remove_module = function(module) {
105
113
  * @description 加载配置对象
106
114
  * @param {Object} obj 配置对象
107
115
  */
108
- Item.prototype.loadObj = function(obj) {
109
- $.push(this.config, obj, true);
110
- var f = this.config.func_file;
116
+ Item.prototype.loadObj = function(config) {
117
+ var f = config.func_file;
111
118
  if (f) {
112
119
  var file = f.fullname(this.dir);
113
120
  if (file.hasFile()) {
114
121
  this.remove_module(file);
115
122
  var cs = require(file);
116
123
  if (cs) {
117
- var name = this.config.func_name;
124
+ var name = config.func_name;
118
125
  if (name) {
119
126
  this.main = cs[name];
120
127
  } else {
@@ -150,6 +157,10 @@ Item.prototype.loadFile = function(file) {
150
157
  obj = text.toJson();
151
158
  } else {
152
159
  this.new_config(f);
160
+ var text = f.loadText();
161
+ if (text) {
162
+ obj = text.toJson();
163
+ }
153
164
  }
154
165
  this.filename = f;
155
166
  return obj;
@@ -211,16 +222,14 @@ Item.prototype.removeFile = function() {
211
222
  * @param {Object|String} cg 配置对象或配置路径
212
223
  */
213
224
  Item.prototype.load = function(cg) {
214
- var obj;
215
- if (!cg) {
216
- cg = this.extensions;
217
- }
225
+ var config;
218
226
  if (typeof(cg) === "string") {
219
- obj = this.loadFile(cg);
227
+ config = this.loadFile(cg);
220
228
  } else {
221
- obj = cg;
229
+ config = cg;
222
230
  }
223
- this.loadObj(obj);
231
+ this.set_config(config);
232
+ this.loadObj(this.config);
224
233
  };
225
234
 
226
235
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "1.4.4",
3
+ "version": "1.4.7",
4
4
  "description": "这是超级美眉框架机制构建辅助模块,用于快速构建一个机制",
5
5
  "main": "index.js",
6
6
  "scripts": {