mm_config 2.1.4 → 2.1.6
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.
- package/config_async.json +1 -1
- package/config_debounce.json +1 -1
- package/eslint.config.js +68 -0
- package/index.js +16 -7
- package/package.json +2 -2
- package/test.js +7 -0
package/config_async.json
CHANGED
package/config_debounce.json
CHANGED
package/eslint.config.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const jsdoc = require('eslint-plugin-jsdoc');
|
|
2
|
+
|
|
3
|
+
module.exports = [
|
|
4
|
+
{
|
|
5
|
+
files: ['lib/**/*.js'],
|
|
6
|
+
languageOptions: {
|
|
7
|
+
ecmaVersion: 2020,
|
|
8
|
+
sourceType: 'script'
|
|
9
|
+
},
|
|
10
|
+
plugins: {
|
|
11
|
+
jsdoc: jsdoc
|
|
12
|
+
},
|
|
13
|
+
rules: {
|
|
14
|
+
// JSDoc相关规则 - 设置为error级别强制要求
|
|
15
|
+
'jsdoc/require-jsdoc': ['error', {
|
|
16
|
+
require: {
|
|
17
|
+
FunctionDeclaration: true,
|
|
18
|
+
MethodDefinition: true,
|
|
19
|
+
ClassDeclaration: true,
|
|
20
|
+
ArrowFunctionExpression: true
|
|
21
|
+
}
|
|
22
|
+
}],
|
|
23
|
+
'jsdoc/check-param-names': 'off',
|
|
24
|
+
'jsdoc/check-tag-names': 'off',
|
|
25
|
+
'jsdoc/check-types': 'off',
|
|
26
|
+
'jsdoc/require-param': 'off',
|
|
27
|
+
'jsdoc/require-param-description': 'off',
|
|
28
|
+
'jsdoc/require-returns': 'off',
|
|
29
|
+
'jsdoc/require-returns-description': 'off',
|
|
30
|
+
|
|
31
|
+
// 基础语法规则
|
|
32
|
+
'no-unused-vars': ['error', { args: 'none', vars: 'all' }],
|
|
33
|
+
'no-console': 'warn',
|
|
34
|
+
|
|
35
|
+
// 代码风格规则
|
|
36
|
+
'indent': ['error', 2],
|
|
37
|
+
'quotes': ['error', 'single'],
|
|
38
|
+
'semi': ['error', 'always'],
|
|
39
|
+
'comma-dangle': ['error', 'never'],
|
|
40
|
+
'no-trailing-spaces': 'error',
|
|
41
|
+
'eol-last': 'error',
|
|
42
|
+
'max-len': ['error', { code: 100 }],
|
|
43
|
+
'max-lines-per-function': ['error', { max: 40 }],
|
|
44
|
+
'complexity': ['error', 12],
|
|
45
|
+
'max-depth': ['error', 4],
|
|
46
|
+
'max-params': ['error', 4],
|
|
47
|
+
|
|
48
|
+
// 命名规则
|
|
49
|
+
'id-length': ['error', {
|
|
50
|
+
min: 1,
|
|
51
|
+
max: 20,
|
|
52
|
+
properties: 'always'
|
|
53
|
+
}]
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
files: ['test/**/*.js'],
|
|
58
|
+
languageOptions: {
|
|
59
|
+
ecmaVersion: 2020,
|
|
60
|
+
sourceType: 'script'
|
|
61
|
+
},
|
|
62
|
+
rules: {
|
|
63
|
+
// 测试文件中允许使用console
|
|
64
|
+
'no-console': 'off',
|
|
65
|
+
'no-unused-vars': 'off'
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
];
|
package/index.js
CHANGED
|
@@ -35,13 +35,13 @@ class Config {
|
|
|
35
35
|
this._conn = null;
|
|
36
36
|
this._timer = null;
|
|
37
37
|
this._promise = Promise.resolve();
|
|
38
|
-
|
|
38
|
+
this._logger = $.log || console;
|
|
39
39
|
// 如果没有提供配置且有文件路径,则从文件加载
|
|
40
40
|
if (!options && file) {
|
|
41
41
|
try {
|
|
42
42
|
this.options = file.loadJson();
|
|
43
43
|
} catch (err) {
|
|
44
|
-
|
|
44
|
+
this.log('error', `Error loading options from ${file}:`, err.message);
|
|
45
45
|
this.options = {};
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -52,6 +52,16 @@ class Config {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* 日志输出
|
|
57
|
+
* @param {String} level - 日志级别(debug/info/warn/error)
|
|
58
|
+
* @param {String} message - 日志消息
|
|
59
|
+
* @param {...*} args - 可选参数
|
|
60
|
+
*/
|
|
61
|
+
Config.prototype.log = function(level, message, ...args){
|
|
62
|
+
this._logger[level](`[${this.constructor.name}] ${message}`, ...args);
|
|
63
|
+
}
|
|
64
|
+
|
|
55
65
|
/**
|
|
56
66
|
* 设置配置
|
|
57
67
|
* @param {Object} config - 配置对象
|
|
@@ -65,7 +75,7 @@ Config.prototype.setConfig = function (config) {
|
|
|
65
75
|
* @param {Object} options - 配置对象
|
|
66
76
|
*/
|
|
67
77
|
Config.prototype.setOptions = function (options) {
|
|
68
|
-
|
|
78
|
+
$.push(this.options, options, true);
|
|
69
79
|
}
|
|
70
80
|
|
|
71
81
|
/**
|
|
@@ -88,7 +98,7 @@ Config.prototype.saveSync = function () {
|
|
|
88
98
|
this._file.saveJson(this.options);
|
|
89
99
|
return true;
|
|
90
100
|
} catch (err) {
|
|
91
|
-
|
|
101
|
+
this.log('error', `Error saving options to ${this._file}:`, err.message);
|
|
92
102
|
return false;
|
|
93
103
|
}
|
|
94
104
|
};
|
|
@@ -109,7 +119,7 @@ Config.prototype.saveAsync = async function () {
|
|
|
109
119
|
return true;
|
|
110
120
|
})
|
|
111
121
|
.catch(err => {
|
|
112
|
-
|
|
122
|
+
this.log('error', `Error saving options to ${this._file}:`, err.message);
|
|
113
123
|
return false;
|
|
114
124
|
});
|
|
115
125
|
|
|
@@ -218,7 +228,6 @@ function create(file, options = {}, config = {}) {
|
|
|
218
228
|
let f = file.fullname();
|
|
219
229
|
// 检查是否已存在配置
|
|
220
230
|
if (dict[f]) {
|
|
221
|
-
// $.log.warn(`[options] Config for file ${f} already exists.`);
|
|
222
231
|
return dict[f].getProxy();
|
|
223
232
|
}
|
|
224
233
|
var cfg = new Config(options, f, config);
|
|
@@ -239,7 +248,7 @@ async function createAsync(file, options = {}, config = {}) {
|
|
|
239
248
|
let f = file.fullname();
|
|
240
249
|
// 检查是否已存在配置
|
|
241
250
|
if (dict[f]) {
|
|
242
|
-
|
|
251
|
+
this.log('warn', `Config for file ${f} already exists.`);
|
|
243
252
|
return dict[f].getAsyncProxy();
|
|
244
253
|
}
|
|
245
254
|
var cfg = new Config(options, f, config);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_config",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.6",
|
|
4
4
|
"description": "这是超级美眉配置同步器,用于更改配置同步保存为JSON文件",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,6 +26,6 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://gitee.com/qiuwenwu91/mm_config#readme",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"mm_expand": "^
|
|
29
|
+
"mm_expand": "^2.0.0"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/test.js
CHANGED
|
@@ -129,6 +129,13 @@ async function testMethods() {
|
|
|
129
129
|
|
|
130
130
|
const state = await cg.get('state');
|
|
131
131
|
$.log.debug('获取到的状态:', state);
|
|
132
|
+
|
|
133
|
+
// 测试设置选项
|
|
134
|
+
await cg.setOptions({
|
|
135
|
+
sort: 200,
|
|
136
|
+
state: "2"
|
|
137
|
+
});
|
|
138
|
+
$.log.debug('设置后的选项:', await cg.options);
|
|
132
139
|
}
|
|
133
140
|
|
|
134
141
|
// 测试缓存清理功能
|