mm_config 2.1.6 → 2.1.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.
- package/README.md +382 -284
- package/README_EN.md +382 -0
- package/index.js +276 -273
- package/package.json +24 -5
- package/.gitattributes +0 -5
- package/cache_test1.json +0 -3
- package/cache_test2.json +0 -3
- package/cache_test3.json +0 -3
- package/config1.json +0 -6
- package/config2.json +0 -4
- package/config_async.json +0 -5
- package/config_debounce.json +0 -5
- package/config_json5.json +0 -4
- package/eslint.config.js +0 -68
- package/test.js +0 -199
package/index.js
CHANGED
|
@@ -1,360 +1,363 @@
|
|
|
1
1
|
require('mm_expand');
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* 配置字典(私有)
|
|
5
|
+
* @type {object}
|
|
6
|
+
*/
|
|
7
|
+
const dict = {};
|
|
8
|
+
|
|
3
9
|
/**
|
|
4
10
|
* 配置类
|
|
5
11
|
* @class
|
|
6
12
|
*/
|
|
7
13
|
class Config {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.options = {};
|
|
34
|
-
this._file = file;
|
|
35
|
-
this._conn = null;
|
|
36
|
-
this._timer = null;
|
|
37
|
-
this._promise = Promise.resolve();
|
|
38
|
-
this._logger = $.log || console;
|
|
39
|
-
// 如果没有提供配置且有文件路径,则从文件加载
|
|
40
|
-
if (!options && file) {
|
|
41
|
-
try {
|
|
42
|
-
this.options = file.loadJson();
|
|
43
|
-
} catch (err) {
|
|
44
|
-
this.log('error', `Error loading options from ${file}:`, err.message);
|
|
45
|
-
this.options = {};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
// 设置配置
|
|
49
|
-
this.setOptions(options);
|
|
50
|
-
// 设置配置
|
|
51
|
-
this.setConfig(config);
|
|
52
|
-
}
|
|
14
|
+
/**
|
|
15
|
+
* 创建配置实例
|
|
16
|
+
* @param {object} config - 配置选项
|
|
17
|
+
* @param {number} config.debounce_time - 防抖时间(ms)
|
|
18
|
+
* @param {boolean} config.pretty - 是否美化输出
|
|
19
|
+
* @param {string} config.format - 格式(json/json5)
|
|
20
|
+
* @param {string} config.file - 配置文件路径
|
|
21
|
+
* @param {object} options - 选项
|
|
22
|
+
*/
|
|
23
|
+
constructor(config, options = {}) {
|
|
24
|
+
this.config = {
|
|
25
|
+
debounce_time: 0, // 默认不防抖
|
|
26
|
+
pretty: true,
|
|
27
|
+
format: 'json',
|
|
28
|
+
file: ''
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
this.options = options || {};
|
|
32
|
+
this._conn = null;
|
|
33
|
+
this._timer = null;
|
|
34
|
+
this._promise = Promise.resolve();
|
|
35
|
+
this._logger = $.log || console;
|
|
36
|
+
// 设置配置
|
|
37
|
+
this.setConfig(config);
|
|
38
|
+
}
|
|
53
39
|
}
|
|
54
40
|
|
|
55
41
|
/**
|
|
56
42
|
* 日志输出
|
|
57
|
-
* @param {
|
|
58
|
-
* @param {
|
|
43
|
+
* @param {string} level - 日志级别(debug/info/warn/error)
|
|
44
|
+
* @param {string} message - 日志消息
|
|
59
45
|
* @param {...*} args - 可选参数
|
|
60
46
|
*/
|
|
61
|
-
Config.prototype.log = function(level, message, ...args){
|
|
62
|
-
|
|
63
|
-
}
|
|
47
|
+
Config.prototype.log = function (level, message, ...args) {
|
|
48
|
+
this._logger[level](`[${this.constructor.name}] ${message}`, ...args);
|
|
49
|
+
};
|
|
64
50
|
|
|
65
51
|
/**
|
|
66
52
|
* 设置配置
|
|
67
|
-
* @param {
|
|
53
|
+
* @param {object} config - 配置对象
|
|
68
54
|
*/
|
|
69
55
|
Config.prototype.setConfig = function (config) {
|
|
70
|
-
|
|
71
|
-
}
|
|
56
|
+
$.push(this.config, config);
|
|
57
|
+
};
|
|
72
58
|
|
|
73
59
|
/**
|
|
74
60
|
* 设置配置
|
|
75
|
-
* @param {
|
|
61
|
+
* @param {object} options - 配置对象
|
|
76
62
|
*/
|
|
77
63
|
Config.prototype.setOptions = function (options) {
|
|
78
|
-
|
|
79
|
-
}
|
|
64
|
+
$.push(this.options, options, true);
|
|
65
|
+
};
|
|
80
66
|
|
|
81
67
|
/**
|
|
82
68
|
* 初始化配置(连接文件)
|
|
83
|
-
* @param {
|
|
84
|
-
* @returns {
|
|
69
|
+
* @param {object} conn - 已连接的文件对象
|
|
70
|
+
* @returns {object} 连接的文件对象
|
|
85
71
|
*/
|
|
86
|
-
Config.prototype.setup =
|
|
87
|
-
|
|
88
|
-
|
|
72
|
+
Config.prototype.setup = function (conn) {
|
|
73
|
+
if (conn) this._conn = conn;
|
|
74
|
+
return this._conn;
|
|
89
75
|
};
|
|
90
76
|
|
|
91
77
|
/**
|
|
92
78
|
* 保存配置到文件(同步)
|
|
93
|
-
* @returns {
|
|
79
|
+
* @returns {boolean} 保存是否成功
|
|
94
80
|
*/
|
|
95
81
|
Config.prototype.saveSync = function () {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
82
|
+
if (!this.config.file) return false;
|
|
83
|
+
try {
|
|
84
|
+
this.config.file.saveJson(this.options);
|
|
85
|
+
return true;
|
|
86
|
+
} catch (err) {
|
|
87
|
+
this.log('error', `Error saving options to ${this.config.file}:`, err.message);
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
104
90
|
};
|
|
105
91
|
|
|
106
92
|
/**
|
|
107
93
|
* 保存配置到文件(异步)
|
|
108
|
-
* @returns {Promise<
|
|
94
|
+
* @returns {Promise<boolean>} 保存操作是否成功
|
|
109
95
|
*/
|
|
110
96
|
Config.prototype.saveAsync = async function () {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
97
|
+
if (!this.config.file) return Promise.resolve(true);
|
|
98
|
+
|
|
99
|
+
// 确保之前的写操作完成
|
|
100
|
+
await this._promise;
|
|
101
|
+
|
|
102
|
+
this._promise = Promise.resolve()
|
|
103
|
+
.then(() => {
|
|
104
|
+
this.config.file.saveJson(this.options);
|
|
105
|
+
return true;
|
|
106
|
+
})
|
|
107
|
+
.catch(err => {
|
|
108
|
+
this.log('error', `Error saving options to ${this.config.file}:`, err.message);
|
|
109
|
+
return false;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
return this._promise;
|
|
127
113
|
};
|
|
128
114
|
|
|
129
115
|
/**
|
|
130
116
|
* 获取代理对象
|
|
131
|
-
* @returns {Proxy}
|
|
117
|
+
* @returns {Proxy} 配置对象的代理实例
|
|
132
118
|
*/
|
|
133
119
|
Config.prototype.getProxy = function () {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
120
|
+
const self = this;
|
|
121
|
+
|
|
122
|
+
return new Proxy(this.options, {
|
|
123
|
+
set(obj, prop, val) {
|
|
124
|
+
obj[prop] = val;
|
|
125
|
+
|
|
126
|
+
if (self.config.debounce_time > 0) {
|
|
127
|
+
// 防抖处理
|
|
128
|
+
if (self._timer) {
|
|
129
|
+
clearTimeout(self._timer);
|
|
130
|
+
}
|
|
131
|
+
self._timer = setTimeout(() => {
|
|
132
|
+
self.saveSync();
|
|
133
|
+
}, self.config.debounce_time);
|
|
134
|
+
} else {
|
|
135
|
+
// 无防抖,直接保存
|
|
136
|
+
self.saveSync();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return true;
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
get(obj, prop) {
|
|
143
|
+
// 提供一些特殊属性访问
|
|
144
|
+
if (prop === '_saveAsync') {
|
|
145
|
+
return () => self.saveAsync();
|
|
146
|
+
}
|
|
147
|
+
if (prop === '_saveSync') {
|
|
148
|
+
return () => self.saveSync();
|
|
149
|
+
}
|
|
150
|
+
if (prop === '_raw') {
|
|
151
|
+
return obj;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return obj[prop];
|
|
155
|
+
}
|
|
156
|
+
});
|
|
171
157
|
};
|
|
172
158
|
|
|
173
159
|
/**
|
|
174
160
|
* 获取异步代理对象
|
|
175
|
-
* @returns {Proxy}
|
|
161
|
+
* @returns {Proxy} 异步配置对象的代理实例
|
|
176
162
|
*/
|
|
177
163
|
Config.prototype.getAsyncProxy = function () {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
164
|
+
const self = this;
|
|
165
|
+
|
|
166
|
+
return new Proxy(this.options, {
|
|
167
|
+
set(obj, prop, val) {
|
|
168
|
+
obj[prop] = val;
|
|
169
|
+
|
|
170
|
+
if (self.config.debounce_time > 0) {
|
|
171
|
+
if (self._timer) {
|
|
172
|
+
clearTimeout(self._timer);
|
|
173
|
+
}
|
|
174
|
+
self._timer = setTimeout(() => {
|
|
175
|
+
self.saveAsync();
|
|
176
|
+
}, self.config.debounce_time);
|
|
177
|
+
} else {
|
|
178
|
+
self.saveAsync();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return true;
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
get(obj, prop) {
|
|
185
|
+
if (prop === '_saveAsync') {
|
|
186
|
+
return () => self.saveAsync();
|
|
187
|
+
}
|
|
188
|
+
if (prop === '_saveSync') {
|
|
189
|
+
return () => self.saveSync();
|
|
190
|
+
}
|
|
191
|
+
if (prop === '_raw') {
|
|
192
|
+
return obj;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return obj[prop];
|
|
196
|
+
}
|
|
197
|
+
});
|
|
212
198
|
};
|
|
213
199
|
|
|
214
|
-
/**
|
|
215
|
-
* 配置字典(私有)
|
|
216
|
-
* @type {Object}
|
|
217
|
-
*/
|
|
218
|
-
const dict = {};
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* 创建配置(同步)
|
|
222
|
-
* @param {String} file - 配置文件路径
|
|
223
|
-
* @param {Object} options - 配置对象
|
|
224
|
-
* @param {Object} config - 配置选项
|
|
225
|
-
* @returns {Proxy}
|
|
226
|
-
*/
|
|
227
|
-
function create(file, options = {}, config = {}) {
|
|
228
|
-
let f = file.fullname();
|
|
229
|
-
// 检查是否已存在配置
|
|
230
|
-
if (dict[f]) {
|
|
231
|
-
return dict[f].getProxy();
|
|
232
|
-
}
|
|
233
|
-
var cfg = new Config(options, f, config);
|
|
234
|
-
cfg.saveSync(); // 确保文件存在
|
|
235
|
-
// 注册配置字典
|
|
236
|
-
dict[f] = cfg;
|
|
237
|
-
return dict[f].getProxy();
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* 创建配置(异步)
|
|
242
|
-
* @param {String} file - 配置文件路径
|
|
243
|
-
* @param {Object} options - 配置对象
|
|
244
|
-
* @param {Object} config - 配置选项
|
|
245
|
-
* @returns {Promise<Proxy>}
|
|
246
|
-
*/
|
|
247
|
-
async function createAsync(file, options = {}, config = {}) {
|
|
248
|
-
let f = file.fullname();
|
|
249
|
-
// 检查是否已存在配置
|
|
250
|
-
if (dict[f]) {
|
|
251
|
-
this.log('warn', `Config for file ${f} already exists.`);
|
|
252
|
-
return dict[f].getAsyncProxy();
|
|
253
|
-
}
|
|
254
|
-
var cfg = new Config(options, f, config);
|
|
255
|
-
await cfg.saveAsync(); // 确保文件存在
|
|
256
|
-
// 注册配置字典
|
|
257
|
-
dict[f] = cfg;
|
|
258
|
-
return dict[f].getAsyncProxy();
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* 清理指定文件配置缓存
|
|
263
|
-
* @param {String} file - 配置文件路径
|
|
264
|
-
*/
|
|
265
|
-
function clear(file) {
|
|
266
|
-
if (!file) return clearAll();
|
|
267
|
-
let f = file.fullname();
|
|
268
|
-
if (dict[f]) {
|
|
269
|
-
delete dict[f];
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* 清理所有配置缓存
|
|
275
|
-
*/
|
|
276
|
-
function clearAll() {
|
|
277
|
-
Object.keys(dict).forEach(key => {
|
|
278
|
-
delete dict[key];
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
|
|
282
200
|
/**
|
|
283
201
|
* 获取配置值
|
|
284
|
-
* @param {
|
|
285
|
-
* @returns {*}
|
|
202
|
+
* @param {string} key - 配置键
|
|
203
|
+
* @returns {*} 配置值
|
|
286
204
|
*/
|
|
287
205
|
Config.prototype.get = async function (key) {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
206
|
+
let value;
|
|
207
|
+
if (this._conn) {
|
|
208
|
+
value = await this._conn.get(key);
|
|
209
|
+
}
|
|
210
|
+
if (!value) {
|
|
211
|
+
value = this.options[key];
|
|
212
|
+
}
|
|
213
|
+
return value;
|
|
296
214
|
};
|
|
297
215
|
|
|
298
216
|
/**
|
|
299
217
|
* 设置配置值
|
|
300
|
-
* @param {
|
|
218
|
+
* @param {string} key - 配置键
|
|
301
219
|
* @param {*} value - 配置值
|
|
302
220
|
*/
|
|
303
221
|
Config.prototype.set = async function (key, value) {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
222
|
+
if (this._conn) {
|
|
223
|
+
await this._conn.set(key, value);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
this.options[key] = value;
|
|
227
|
+
}
|
|
310
228
|
};
|
|
311
229
|
|
|
312
230
|
/**
|
|
313
231
|
* 检查配置是否存在
|
|
314
|
-
* @param {
|
|
315
|
-
* @returns {
|
|
232
|
+
* @param {string} key - 配置键
|
|
233
|
+
* @returns {boolean} 配置项是否存在
|
|
316
234
|
*/
|
|
317
235
|
Config.prototype.has = async function (key) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
236
|
+
let bl = false;
|
|
237
|
+
if (this._conn) {
|
|
238
|
+
bl = await this._conn.has(key);
|
|
239
|
+
};
|
|
240
|
+
if (!bl) {
|
|
241
|
+
bl = this.options.hasOwnProperty(key);
|
|
242
|
+
}
|
|
243
|
+
return bl;
|
|
326
244
|
};
|
|
327
245
|
|
|
328
246
|
/**
|
|
329
247
|
* 删除配置项
|
|
330
|
-
* @param {
|
|
248
|
+
* @param {string} key - 配置键
|
|
331
249
|
*/
|
|
332
250
|
Config.prototype.del = async function (key) {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
251
|
+
if (this._conn) {
|
|
252
|
+
await this._conn.del(key);
|
|
253
|
+
};
|
|
254
|
+
delete this.options[key];
|
|
337
255
|
};
|
|
338
256
|
|
|
339
257
|
/**
|
|
340
258
|
* 获取所有配置键
|
|
341
|
-
* @returns {Array<
|
|
259
|
+
* @returns {Array<string>} 配置键列表
|
|
342
260
|
*/
|
|
343
261
|
Config.prototype.keys = async function () {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
262
|
+
let keys = [];
|
|
263
|
+
if (this._conn) {
|
|
264
|
+
keys = await this._conn.keys();
|
|
265
|
+
}
|
|
266
|
+
const local_keys = Object.keys(this.options);
|
|
267
|
+
keys = keys.concat(local_keys);
|
|
268
|
+
return keys;
|
|
351
269
|
};
|
|
352
270
|
|
|
271
|
+
/**
|
|
272
|
+
* 销毁
|
|
273
|
+
*/
|
|
274
|
+
Config.prototype.destroy = function () {
|
|
275
|
+
if (this._conn) {
|
|
276
|
+
this._conn.close();
|
|
277
|
+
}
|
|
278
|
+
delete dict[this.config.file];
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* 创建配置(同步)
|
|
283
|
+
* @param {string} file - 配置文件路径
|
|
284
|
+
* @param {object} options - 配置对象
|
|
285
|
+
* @param {object} config - 配置选项
|
|
286
|
+
* @returns {Proxy} 配置代理对象
|
|
287
|
+
*/
|
|
288
|
+
function create(file, options = {}, config = {}) {
|
|
289
|
+
const f = file.fullname();
|
|
290
|
+
// 检查是否已存在配置
|
|
291
|
+
if (dict[f]) {
|
|
292
|
+
return dict[f].getProxy();
|
|
293
|
+
}
|
|
294
|
+
const cfg = new Config({ file: f, ...config }, options);
|
|
295
|
+
cfg.saveSync(); // 确保文件存在
|
|
296
|
+
// 注册配置字典
|
|
297
|
+
dict[f] = cfg;
|
|
298
|
+
return dict[f].getProxy();
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* 创建配置(异步)
|
|
303
|
+
* @param {string} file - 配置文件路径
|
|
304
|
+
* @param {object} options - 配置对象
|
|
305
|
+
* @param {object} config - 配置选项
|
|
306
|
+
* @returns {Promise<Proxy>} 异步配置代理对象
|
|
307
|
+
*/
|
|
308
|
+
async function createAsync(file, options = {}, config = {}) {
|
|
309
|
+
const f = file.fullname();
|
|
310
|
+
// 检查是否已存在配置
|
|
311
|
+
if (dict[f]) {
|
|
312
|
+
this.log('warn', `Config for file ${f} already exists.`);
|
|
313
|
+
return dict[f].getAsyncProxy();
|
|
314
|
+
}
|
|
315
|
+
const cfg = new Config({ file: f, ...config }, options);
|
|
316
|
+
await cfg.saveAsync(); // 确保文件存在
|
|
317
|
+
// 注册配置字典
|
|
318
|
+
dict[f] = cfg;
|
|
319
|
+
return dict[f].getAsyncProxy();
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* 清理指定文件配置缓存
|
|
324
|
+
* @param {string} file - 配置文件路径
|
|
325
|
+
* @returns {void}
|
|
326
|
+
*/
|
|
327
|
+
function clear(file) {
|
|
328
|
+
if (!file) return clearAll();
|
|
329
|
+
const f = file.fullname();
|
|
330
|
+
if (dict[f]) {
|
|
331
|
+
delete dict[f];
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* 清理所有配置缓存
|
|
337
|
+
*/
|
|
338
|
+
function clearAll() {
|
|
339
|
+
Object.keys(dict).forEach(key => {
|
|
340
|
+
delete dict[key];
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* 获取配置代理对象
|
|
346
|
+
* @param {object} options - 配置对象
|
|
347
|
+
* @param {string} file - 配置文件路径
|
|
348
|
+
* @param {object} config - 配置选项
|
|
349
|
+
* @returns {Proxy} 配置代理对象
|
|
350
|
+
*/
|
|
351
|
+
function conf(options, file, config = {}) {
|
|
352
|
+
return createAsync(file, options, config);
|
|
353
|
+
}
|
|
354
|
+
|
|
353
355
|
// 模块导出
|
|
354
356
|
module.exports = {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
357
|
+
Config,
|
|
358
|
+
create,
|
|
359
|
+
createAsync,
|
|
360
|
+
clear,
|
|
361
|
+
clearAll,
|
|
362
|
+
conf
|
|
360
363
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_config",
|
|
3
|
-
"version": "2.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.1.7",
|
|
4
|
+
"description": "Super Meimei Configuration Synchronizer - Automatically sync configuration changes to JSON files",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "node test.js"
|
|
7
|
+
"test": "node test.js",
|
|
8
|
+
"lint": "eslint index.js",
|
|
9
|
+
"lint:fix": "eslint index.js --fix"
|
|
8
10
|
},
|
|
9
11
|
"repository": {
|
|
10
12
|
"type": "git",
|
|
@@ -17,7 +19,10 @@
|
|
|
17
19
|
"sync",
|
|
18
20
|
"async",
|
|
19
21
|
"debounce",
|
|
20
|
-
"json5"
|
|
22
|
+
"json5",
|
|
23
|
+
"configuration",
|
|
24
|
+
"settings",
|
|
25
|
+
"automation"
|
|
21
26
|
],
|
|
22
27
|
"author": "邱文武",
|
|
23
28
|
"license": "ISC",
|
|
@@ -25,7 +30,21 @@
|
|
|
25
30
|
"url": "https://gitee.com/qiuwenwu91/mm_config/issues"
|
|
26
31
|
},
|
|
27
32
|
"homepage": "https://gitee.com/qiuwenwu91/mm_config#readme",
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=14.0.0"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"index.js",
|
|
38
|
+
"README.md",
|
|
39
|
+
"README_EN.md",
|
|
40
|
+
"LICENSE"
|
|
41
|
+
],
|
|
28
42
|
"dependencies": {
|
|
29
43
|
"mm_expand": "^2.0.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"eslint": "^9.39.2",
|
|
47
|
+
"eslint-plugin-jsdoc": "^61.5.0",
|
|
48
|
+
"mm_eslint": "^1.0.6"
|
|
30
49
|
}
|
|
31
|
-
}
|
|
50
|
+
}
|