mm_machine 1.4.5 → 1.4.8

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 +46 -12
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -78,7 +78,7 @@ class Item {
78
78
  * @param {Object} config 配置
79
79
  */
80
80
  Item.prototype.set_config = function(config){
81
- this.config = conf(Object.assign(this.config, config));
81
+ this.config = conf(Object.assign(this.config, config || {}));
82
82
  }
83
83
 
84
84
  /**
@@ -113,16 +113,15 @@ Item.prototype.remove_module = function(module) {
113
113
  * @description 加载配置对象
114
114
  * @param {Object} obj 配置对象
115
115
  */
116
- Item.prototype.loadObj = function(obj) {
117
- $.push(this.config, obj, true);
118
- var f = this.config.func_file;
116
+ Item.prototype.loadObj = function(config) {
117
+ var f = config.func_file;
119
118
  if (f) {
120
119
  var file = f.fullname(this.dir);
121
120
  if (file.hasFile()) {
122
121
  this.remove_module(file);
123
122
  var cs = require(file);
124
123
  if (cs) {
125
- var name = this.config.func_name;
124
+ var name = config.func_name;
126
125
  if (name) {
127
126
  this.main = cs[name];
128
127
  } else {
@@ -158,6 +157,10 @@ Item.prototype.loadFile = function(file) {
158
157
  obj = text.toJson();
159
158
  } else {
160
159
  this.new_config(f);
160
+ var text = f.loadText();
161
+ if (text) {
162
+ obj = text.toJson();
163
+ }
161
164
  }
162
165
  this.filename = f;
163
166
  return obj;
@@ -219,16 +222,14 @@ Item.prototype.removeFile = function() {
219
222
  * @param {Object|String} cg 配置对象或配置路径
220
223
  */
221
224
  Item.prototype.load = function(cg) {
222
- var obj;
223
- if (!cg) {
224
- cg = this.extensions;
225
- }
225
+ var config;
226
226
  if (typeof(cg) === "string") {
227
- obj = this.loadFile(cg);
227
+ config = this.loadFile(cg);
228
228
  } else {
229
- obj = cg;
229
+ config = cg;
230
230
  }
231
- this.loadObj(obj);
231
+ this.set_config(config);
232
+ this.loadObj(this.config);
232
233
  };
233
234
 
234
235
  /**
@@ -264,6 +265,25 @@ Item.prototype.main = function(param1, param2) {
264
265
  return null;
265
266
  };
266
267
 
268
+ /**
269
+ * 运行指令
270
+ * @param {Number} state 状态 0为不可以,1为可用
271
+ * @param {Array} ...params 参数集合
272
+ */
273
+ Item.prototype.run_cmd = function(state, ...params){
274
+ return null;
275
+ };
276
+
277
+ /**
278
+ * 下达指令
279
+ * @param {Number} state 状态 0为不可以,1为可用
280
+ * @param {Array} ...params 参数集合
281
+ */
282
+ Item.prototype.cmd = function(state, ...params){
283
+ this.config.state = state;
284
+ return this.run_cmd((state, ...param);
285
+ }
286
+
267
287
  /**
268
288
  * @module 导出Drive类
269
289
  */
@@ -434,6 +454,20 @@ Index.prototype.get = function(name) {
434
454
  return obj;
435
455
  };
436
456
 
457
+ /**
458
+ * 下达指令
459
+ * @param {String} name 名称
460
+ * @param {Number} state 状态
461
+ * @param {Array} ...params 参数集合
462
+ */
463
+ Index.prototype.cmd = async function(name, state, ...params){
464
+ var obj = this.get(name);
465
+ if(!obj){
466
+ return "error: program does not exist";
467
+ }
468
+ return await obj.cmd(name, ...params);
469
+ }
470
+
437
471
  /**
438
472
  * @description 查询配置项
439
473
  * @param {String} name 名称
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "1.4.5",
3
+ "version": "1.4.8",
4
4
  "description": "这是超级美眉框架机制构建辅助模块,用于快速构建一个机制",
5
5
  "main": "index.js",
6
6
  "scripts": {