mm_machine 2.1.3 → 2.1.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.
@@ -4,10 +4,7 @@
4
4
  "description": "完整测试模块2",
5
5
  "func_file": "./index.js",
6
6
  "func_name": "",
7
- "sort": 10,
7
+ "sort": 1001,
8
8
  "state": 1,
9
- "show": 1,
10
- "SORT": 10,
11
- "STATE": 1,
12
- "SHOW": 0
9
+ "show": 1
13
10
  }
@@ -1,13 +1,10 @@
1
1
  {
2
2
  "name": "demo2",
3
- "title": "测试模块2",
3
+ "title": "测试模块",
4
4
  "description": "完整测试模块1",
5
5
  "func_file": "./main.js",
6
6
  "func_name": "",
7
7
  "sort": 10,
8
8
  "state": 1,
9
- "show": 1,
10
- "SORT": 10,
11
- "STATE": 1,
12
- "SHOW": 0
9
+ "show": 1
13
10
  }
@@ -41,7 +41,7 @@
41
41
  /**
42
42
  * 标题, 介绍作用
43
43
  */
44
- "title": "示例脚本3",
44
+ "title": "示例脚本",
45
45
  /**
46
46
  * 描述, 用于描述该有什么用的
47
47
  */
@@ -41,7 +41,7 @@
41
41
  /**
42
42
  * 标题, 介绍作用
43
43
  */
44
- "title": "示例脚本3",
44
+ "title": "示例脚本",
45
45
  /**
46
46
  * 描述, 用于描述该有什么用的
47
47
  */
package/item.js CHANGED
@@ -100,7 +100,7 @@ Item.prototype.log = function (level, message, ...args) {
100
100
  * @param {object} config 配置对象
101
101
  * @returns {Promise<void>}
102
102
  */
103
- Item.prototype.setConfig = async function (config) {
103
+ Item.prototype.setConfig = function (config) {
104
104
  if (!config) return;
105
105
 
106
106
  // 如果func_file改变,重置加载状态
@@ -109,8 +109,7 @@ Item.prototype.setConfig = async function (config) {
109
109
  }
110
110
 
111
111
  // 合并配置并应用配置处理
112
- const result = await conf({ ...this.config, ...config }, this.filename);
113
- this.config = result;
112
+ this.config = conf({ ...this.config, ...config }, this.filename);
114
113
  };
115
114
 
116
115
  /**
@@ -265,18 +264,6 @@ Item.prototype._loadScript = function (file, name) {
265
264
  return require(file);
266
265
  };
267
266
 
268
- /**
269
- * 处理热重载回调
270
- * @param {string} name 函数名
271
- * @param {object} loaded_module 加载的模块
272
- * @param {string} change_type 变更类型
273
- */
274
- Item.prototype._handleHotReload = function (name, loaded_module, change_type) {
275
- if (change_type === 'change' && loaded_module) {
276
- this._setMainMethod(loaded_module, name);
277
- }
278
- };
279
-
280
267
  /**
281
268
  * 设置主方法
282
269
  * @param {object} module 模块对象
@@ -356,9 +343,9 @@ Item.prototype._handleHotReload = function (loaded_config, change_type) {
356
343
  if (change_type !== 'change' || !loaded_config) return;
357
344
 
358
345
  try {
359
- const target_config = this._findConfigByName(loaded_config, this.config.name);
360
- if (target_config) {
361
- this.setConfig(target_config);
346
+ let config = this._findConfigByName(loaded_config, this.config.name);
347
+ if (config) {
348
+ this.setConfig(config);
362
349
  this.setConfigAfter();
363
350
  this._reloadIfNeeded();
364
351
  }
@@ -484,7 +471,7 @@ Item.prototype.loadConfig = async function (config_data, name) {
484
471
  config = this.loadFile(this.filename, name);
485
472
  }
486
473
 
487
- await this.setConfig(config);
474
+ this.setConfig(config);
488
475
  this.setConfigAfter();
489
476
  } catch (err) {
490
477
  this.log('error', `载入配置失败: `, err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_machine",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
4
4
  "description": "这是超级美眉框架机制构建辅助模块,用于快速构建一个机制,支持动态加载、热更新、模块管理等功能,并具有增强的错误处理和现代JavaScript特性支持。",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -37,13 +37,13 @@
37
37
  },
38
38
  "homepage": "https://gitee.com/qiuwenwu91/mm_machine#readme",
39
39
  "dependencies": {
40
- "mm_config": "^2.1.9",
41
- "mm_hot_reload": "^1.1.4"
40
+ "mm_config": "^2.2.3",
41
+ "mm_hot_reload": "^1.1.9"
42
42
  },
43
43
  "devDependencies": {
44
44
  "eslint": "^9.39.2",
45
- "eslint-plugin-jsdoc": "^61.5.0",
46
- "mm_eslint": "^1.4.0",
47
- "prettier": "^3.7.4"
45
+ "eslint-plugin-jsdoc": "^62.5.0",
46
+ "mm_eslint": "^1.6.3",
47
+ "prettier": "^3.8.1"
48
48
  }
49
49
  }
package/test_easy.js ADDED
@@ -0,0 +1,52 @@
1
+ var { Item, Index } = require('./index.js');
2
+
3
+ class Drive extends Item {
4
+ constructor(dir, dir_base) {
5
+ super(dir, dir_base);
6
+ this.default_file = './demo.json';
7
+ }
8
+ }
9
+
10
+ class Engine extends Index {
11
+ constructor(scope, dir_base) {
12
+ super(scope, dir_base);
13
+ /**
14
+ * 模式
15
+ * 1.生产模式,改变文件不会重新加载
16
+ * 2.热更新模式,改变配置文件会重新加载配置,不重新加载脚本
17
+ * 3.热重载模式,改变配置文件都会加载配置和脚本
18
+ * 4.热更新+重载模式,改变配置文件重新加载配置和脚本,执行完后重新加载脚本
19
+ * 5.重载模式,执行完后重新加载脚本,避免变量污染
20
+ */
21
+ this.mode = 3;
22
+ // 机制类型,必须填写,用于检索文件
23
+ this.type = 'demo';
24
+ }
25
+ }
26
+
27
+ /**
28
+ * 设置引擎的Drive类
29
+ * @type {Drive}
30
+ */
31
+ Engine.prototype.Drive = Drive;
32
+
33
+ async function initEngine() {
34
+ var engine = new Engine('sys', __dirname);
35
+ console.info('→ 加载mod');
36
+ await engine.update('./app/'.fullname(__dirname));
37
+ console.log('模块数', engine.list.length);
38
+ return engine;
39
+ }
40
+
41
+
42
+
43
+ async function loadModule(file) {
44
+ var engine = await initEngine();
45
+ await engine.load(file);
46
+
47
+ // setInterval(() => {
48
+ // console.log('模块数', engine.list);
49
+ // }, 6000);
50
+ }
51
+
52
+ loadModule('./app/test1/config_demo.json');
package/test DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "a": 1
3
- }
package/test.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "name": "test1",
3
- "sort": 10,
4
- "state": 1,
5
- "show": 1,
6
- "SORT": 10,
7
- "STATE": 1,
8
- "SHOW": 0
9
- }