mm_machine 3.4.5 → 3.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.
- package/lib/drive.js +61 -13
- package/package.json +1 -1
package/lib/drive.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const path = require('path');
|
|
1
2
|
require('mm_tpl');
|
|
2
3
|
const { conf } = require('mm_config');
|
|
3
4
|
const { Mod } = require('./mod');
|
|
@@ -163,6 +164,46 @@ Drive.prototype.getConfig = function () {
|
|
|
163
164
|
return this.config;
|
|
164
165
|
};
|
|
165
166
|
|
|
167
|
+
/**
|
|
168
|
+
* 构建选项
|
|
169
|
+
* @param {object} options 选项对象
|
|
170
|
+
*/
|
|
171
|
+
Drive.prototype._buildOptionsFromArr = function (options, cached) {
|
|
172
|
+
var values = {};
|
|
173
|
+
for (let i = 0; i < options.length; i++) {
|
|
174
|
+
let option = options[i];
|
|
175
|
+
let key = option.name;
|
|
176
|
+
let value = cached[key];
|
|
177
|
+
if (cached.hasOwnProperty(key) && value !== undefined) {
|
|
178
|
+
values[key] = value;
|
|
179
|
+
} else {
|
|
180
|
+
values[key] = option.default;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return values;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* 构建选项
|
|
188
|
+
* @param {object} options 选项对象
|
|
189
|
+
* @param {object} cached 缓存对象
|
|
190
|
+
* @returns {object} 选项对象
|
|
191
|
+
*/
|
|
192
|
+
Drive.prototype._buildOptionsFromDict = function (options, cached) {
|
|
193
|
+
var values = {};
|
|
194
|
+
for (let key in options) {
|
|
195
|
+
let option = options[key];
|
|
196
|
+
let value = cached[key];
|
|
197
|
+
if (cached.hasOwnProperty(key) && value !== undefined) {
|
|
198
|
+
values[key] = value;
|
|
199
|
+
} else {
|
|
200
|
+
values[key] = option.default;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return values;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
|
|
166
207
|
/**
|
|
167
208
|
* 初始化选项
|
|
168
209
|
* 从缓存文件加载键值对,如果没有缓存则根据config.options生成默认键值对
|
|
@@ -178,15 +219,11 @@ Drive.prototype._initOptions = function () {
|
|
|
178
219
|
if (cache_file && cache_file.hasFile()) {
|
|
179
220
|
cached = cache_file.loadJson() || {};
|
|
180
221
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
this._options[key] = cached[key];
|
|
187
|
-
} else {
|
|
188
|
-
this._options[key] = options[key].default;
|
|
189
|
-
}
|
|
222
|
+
if (Array.isArray(options)) {
|
|
223
|
+
this._options = this._buildOptionsFromArr(options, cached);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
this._options = this._buildOptionsFromDict(options, cached);
|
|
190
227
|
}
|
|
191
228
|
};
|
|
192
229
|
|
|
@@ -207,14 +244,25 @@ Drive.prototype._getOptionsFileName = function () {
|
|
|
207
244
|
return './' + current_name.toLowerCase() + '.json';
|
|
208
245
|
};
|
|
209
246
|
|
|
247
|
+
/**
|
|
248
|
+
* 获取选项缓存目录
|
|
249
|
+
* @returns {string} 选项缓存目录
|
|
250
|
+
*/
|
|
251
|
+
Drive.prototype._getOptionsDirName = function () {
|
|
252
|
+
let parent = this.getParent();
|
|
253
|
+
var current_name = parent.constructor.name + '_' + (parent.config.name || 'default');
|
|
254
|
+
return current_name.toLowerCase();
|
|
255
|
+
};
|
|
256
|
+
|
|
210
257
|
/**
|
|
211
258
|
* 获取选项缓存文件路径
|
|
212
259
|
* @returns {string} 选项缓存文件路径 为空字符串表示未配置缓存目录
|
|
213
260
|
*/
|
|
214
261
|
Drive.prototype._getOptionsFile = function () {
|
|
215
|
-
let
|
|
216
|
-
|
|
217
|
-
|
|
262
|
+
let cache_dir = this._getCacheDir();
|
|
263
|
+
let options_dir = this._getOptionsDirName();
|
|
264
|
+
let file_name = this._getOptionsFileName();
|
|
265
|
+
return path.join(cache_dir, options_dir, file_name);
|
|
218
266
|
};
|
|
219
267
|
|
|
220
268
|
/**
|
|
@@ -804,7 +852,7 @@ Drive.prototype.loadBefore = function () {
|
|
|
804
852
|
/**
|
|
805
853
|
* 加载处理
|
|
806
854
|
*/
|
|
807
|
-
Drive.prototype._loadCore = function () {};
|
|
855
|
+
Drive.prototype._loadCore = function () { };
|
|
808
856
|
|
|
809
857
|
/**
|
|
810
858
|
* 保存配置
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_machine",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.7",
|
|
4
4
|
"description": "A flexible Node.js plugin mechanism system for dynamic loading, management and execution of modules. Supports hot reload, lifecycle management, and modern JavaScript features.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|