mm_machine 3.4.6 → 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 -16
- 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,18 +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
|
-
let key = option.key;
|
|
187
|
-
let value = cached[key];
|
|
188
|
-
if (cached.hasOwnProperty(key) && value !== undefined) {
|
|
189
|
-
this._options[key] = value;
|
|
190
|
-
} else {
|
|
191
|
-
this._options[key] = option.default;
|
|
192
|
-
}
|
|
222
|
+
if (Array.isArray(options)) {
|
|
223
|
+
this._options = this._buildOptionsFromArr(options, cached);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
this._options = this._buildOptionsFromDict(options, cached);
|
|
193
227
|
}
|
|
194
228
|
};
|
|
195
229
|
|
|
@@ -210,14 +244,25 @@ Drive.prototype._getOptionsFileName = function () {
|
|
|
210
244
|
return './' + current_name.toLowerCase() + '.json';
|
|
211
245
|
};
|
|
212
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
|
+
|
|
213
257
|
/**
|
|
214
258
|
* 获取选项缓存文件路径
|
|
215
259
|
* @returns {string} 选项缓存文件路径 为空字符串表示未配置缓存目录
|
|
216
260
|
*/
|
|
217
261
|
Drive.prototype._getOptionsFile = function () {
|
|
218
|
-
let
|
|
219
|
-
|
|
220
|
-
|
|
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);
|
|
221
266
|
};
|
|
222
267
|
|
|
223
268
|
/**
|
|
@@ -807,7 +852,7 @@ Drive.prototype.loadBefore = function () {
|
|
|
807
852
|
/**
|
|
808
853
|
* 加载处理
|
|
809
854
|
*/
|
|
810
|
-
Drive.prototype._loadCore = function () {};
|
|
855
|
+
Drive.prototype._loadCore = function () { };
|
|
811
856
|
|
|
812
857
|
/**
|
|
813
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": {
|