ee-core 2.11.0 → 2.12.0
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/cache.js +28 -8
- package/config/config_loader.js +70 -0
- package/config/index.js +6 -51
- package/core/lib/loader/file_loader.js +5 -2
- package/ee/application.js +1 -0
- package/ee/baseApp.js +0 -5
- package/ee/eeApp.js +0 -3
- package/jobs/child/app.js +1 -1
- package/jobs/child/forkProcess.js +2 -2
- package/loader/index.js +5 -9
- package/log/logger.js +5 -8
- package/main/index.js +4 -4
- package/message/childMessage.js +0 -1
- package/package.json +1 -1
- package/ps/index.js +7 -0
- package/storage/jsondb/adapters/FileSync.js +3 -3
package/config/cache.js
CHANGED
|
@@ -1,27 +1,47 @@
|
|
|
1
1
|
const EE = require('../ee');
|
|
2
|
+
const { ConfigLoader } = require('./config_loader');
|
|
3
|
+
|
|
4
|
+
const Instance = {
|
|
5
|
+
config: null,
|
|
6
|
+
};
|
|
2
7
|
|
|
3
8
|
const conf = {
|
|
4
9
|
|
|
10
|
+
loadConfig() {
|
|
11
|
+
const configLoader = new ConfigLoader();
|
|
12
|
+
Instance["config"] = configLoader.load();
|
|
13
|
+
return Instance["config"];
|
|
14
|
+
},
|
|
15
|
+
|
|
5
16
|
/**
|
|
6
17
|
* 获取 内存中的config
|
|
7
18
|
*/
|
|
8
|
-
_getConfig(
|
|
19
|
+
_getConfig() {
|
|
9
20
|
const { CoreApp } = EE;
|
|
10
|
-
|
|
11
|
-
|
|
21
|
+
|
|
22
|
+
if (CoreApp && CoreApp.config) {
|
|
23
|
+
return CoreApp.config;
|
|
12
24
|
}
|
|
13
|
-
|
|
14
|
-
|
|
25
|
+
|
|
26
|
+
if (Instance["config"]) {
|
|
27
|
+
return Instance["config"];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 重新加载 config
|
|
31
|
+
this.loadConfig();
|
|
32
|
+
|
|
33
|
+
if (!Instance["config"]) {
|
|
34
|
+
throw new Error('[ee-core] [config] config is not loaded!');
|
|
15
35
|
}
|
|
16
36
|
|
|
17
|
-
return
|
|
37
|
+
return Instance["config"];
|
|
18
38
|
},
|
|
19
39
|
|
|
20
40
|
/**
|
|
21
41
|
* all
|
|
22
42
|
*/
|
|
23
|
-
all(
|
|
24
|
-
return this._getConfig(
|
|
43
|
+
all() {
|
|
44
|
+
return this._getConfig();
|
|
25
45
|
},
|
|
26
46
|
|
|
27
47
|
/**
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const debug = require('debug')('ee-core:config:config_loader');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const Ps = require('../ps');
|
|
6
|
+
const extend = require('../utils/extend');
|
|
7
|
+
const Timing = require('../core/lib/utils/timing');
|
|
8
|
+
const Loader= require('../loader');
|
|
9
|
+
|
|
10
|
+
class ConfigLoader {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.timing = new Timing();
|
|
13
|
+
this.config = {};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Load config/config.xxx.js
|
|
18
|
+
*/
|
|
19
|
+
load() {
|
|
20
|
+
this.timing.start('Load Config');
|
|
21
|
+
|
|
22
|
+
// Load Application config
|
|
23
|
+
const appConfig = this._AppConfig();
|
|
24
|
+
debug("[load] appConfig: %o", appConfig);
|
|
25
|
+
this.config = appConfig;
|
|
26
|
+
|
|
27
|
+
this.timing.end('Load Config');
|
|
28
|
+
return this.config;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
_AppConfig() {
|
|
32
|
+
const names = [
|
|
33
|
+
'config.default',
|
|
34
|
+
`config.${Ps.env()}`,
|
|
35
|
+
];
|
|
36
|
+
const target = {};
|
|
37
|
+
for (const filename of names) {
|
|
38
|
+
const config = this._loadConfig(Ps.getElectronDir(), filename);
|
|
39
|
+
extend(true, target, config);
|
|
40
|
+
}
|
|
41
|
+
return target;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
_loadConfig(dirpath, filename) {
|
|
45
|
+
const appInfo = {
|
|
46
|
+
name: Ps.appName(),
|
|
47
|
+
baseDir: Ps.getElectronDir(),
|
|
48
|
+
electronDir: Ps.getElectronDir(),
|
|
49
|
+
env: Ps.env(),
|
|
50
|
+
home: Ps.getHomeDir(),
|
|
51
|
+
root: Ps.getRootDir(),
|
|
52
|
+
appUserDataDir: Ps.getAppUserDataDir(),
|
|
53
|
+
userHome: Ps.getUserHomeDir(),
|
|
54
|
+
appVersion: Ps.appVersion(),
|
|
55
|
+
isPackaged: Ps.isPackaged(),
|
|
56
|
+
isEncrypted: Ps.isEncrypted(),
|
|
57
|
+
execDir: Ps.getExecDir(),
|
|
58
|
+
}
|
|
59
|
+
const filepath = path.join(dirpath, 'config', filename);
|
|
60
|
+
const config = Loader.loadOneFile(filepath, appInfo);
|
|
61
|
+
debug("[_loadConfig] filepath: %s", filepath);
|
|
62
|
+
if (!config) return null;
|
|
63
|
+
|
|
64
|
+
return config;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = {
|
|
69
|
+
ConfigLoader
|
|
70
|
+
};
|
package/config/index.js
CHANGED
|
@@ -1,66 +1,21 @@
|
|
|
1
|
-
const Storage = require('../storage');
|
|
2
1
|
const ConfigCache = require('./cache');
|
|
3
|
-
var SystemDb = undefined;
|
|
4
2
|
|
|
5
3
|
const Cfg = {
|
|
6
4
|
|
|
7
|
-
/**
|
|
8
|
-
* 获取 coredb
|
|
9
|
-
*/
|
|
10
|
-
_getCoreDB() {
|
|
11
|
-
// [todo] 要么每次new对象,要么所有地方都用同一个实例,否则会出现数据无法刷新的情况
|
|
12
|
-
SystemDb = Storage.connection('system');
|
|
13
|
-
return SystemDb;
|
|
14
|
-
},
|
|
15
|
-
|
|
16
5
|
/**
|
|
17
6
|
* all
|
|
18
7
|
*/
|
|
19
|
-
all(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const cacheValue = ConfigCache.all();
|
|
23
|
-
return cacheValue;
|
|
24
|
-
}
|
|
25
|
-
const cdb = this._getCoreDB();
|
|
26
|
-
const config = cdb.getItem('config');
|
|
27
|
-
|
|
28
|
-
return config;
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* setAll
|
|
33
|
-
*/
|
|
34
|
-
setAll(value) {
|
|
35
|
-
const cdb = this._getCoreDB();
|
|
36
|
-
cdb.setItem('config', value);
|
|
37
|
-
|
|
38
|
-
return;
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* setValue
|
|
43
|
-
*/
|
|
44
|
-
setValue(key, value) {
|
|
45
|
-
const cdb = this._getCoreDB();
|
|
46
|
-
cdb.setConfigItem(key, value);
|
|
47
|
-
|
|
48
|
-
return;
|
|
8
|
+
all() {
|
|
9
|
+
const cacheValue = ConfigCache.all();
|
|
10
|
+
return cacheValue;
|
|
49
11
|
},
|
|
50
12
|
|
|
51
13
|
/**
|
|
52
14
|
* getValue
|
|
53
15
|
*/
|
|
54
|
-
getValue(key
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return cacheValue;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const cdb = this._getCoreDB();
|
|
61
|
-
let v = cdb.getConfigItem(key);
|
|
62
|
-
|
|
63
|
-
return v;
|
|
16
|
+
getValue(key) {
|
|
17
|
+
const cacheValue = ConfigCache.getValue(key);
|
|
18
|
+
return cacheValue;
|
|
64
19
|
},
|
|
65
20
|
|
|
66
21
|
/**
|
|
@@ -210,8 +210,11 @@ class FileLoader {
|
|
|
210
210
|
for (const addonName of addonpaths) {
|
|
211
211
|
if (filterAddons.includes(addonName)) continue;
|
|
212
212
|
|
|
213
|
-
|
|
214
|
-
fullpath = loader.resolveModule(
|
|
213
|
+
const filepath = path.join(directory, addonName, 'index');
|
|
214
|
+
const fullpath = loader.resolveModule(filepath);
|
|
215
|
+
if (!fs.existsSync(fullpath)) {
|
|
216
|
+
throw new Error(`The ${filepath} file does not exist`);
|
|
217
|
+
}
|
|
215
218
|
if (!fs.statSync(fullpath).isFile()) continue;
|
|
216
219
|
|
|
217
220
|
let exports = getExports(fullpath, this.options, addonName);
|
package/ee/application.js
CHANGED
package/ee/baseApp.js
CHANGED
|
@@ -7,7 +7,6 @@ const HttpClient = require('../httpclient');
|
|
|
7
7
|
const HTTPCLIENT = Symbol('EeApplication#httpclient');
|
|
8
8
|
const LOGGERS = Symbol('EeApplication#loggers');
|
|
9
9
|
const Log = require('../log');
|
|
10
|
-
const Conf = require('../config');
|
|
11
10
|
|
|
12
11
|
class BaseApp extends EeAppCore {
|
|
13
12
|
constructor (options = {}) {
|
|
@@ -15,10 +14,6 @@ class BaseApp extends EeAppCore {
|
|
|
15
14
|
super(options);
|
|
16
15
|
|
|
17
16
|
this.loader.loadConfig();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// [todo] 缓存配置
|
|
21
|
-
Conf.setAll(this.config);
|
|
22
17
|
|
|
23
18
|
this.loader.load();
|
|
24
19
|
|
package/ee/eeApp.js
CHANGED
package/jobs/child/app.js
CHANGED
|
@@ -7,6 +7,7 @@ const Ps = require('../../ps');
|
|
|
7
7
|
const Channel = require('../../const/channel');
|
|
8
8
|
const Helper = require('../../utils/helper');
|
|
9
9
|
const Loader = require('../../loader');
|
|
10
|
+
const extend = require('../../utils/extend');
|
|
10
11
|
|
|
11
12
|
class ForkProcess {
|
|
12
13
|
constructor(host, opt = {}) {
|
|
@@ -18,8 +19,7 @@ class ForkProcess {
|
|
|
18
19
|
cwd = path.join(Ps.getHomeDir(), '..');
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
let options = Object.assign({
|
|
22
|
+
let options = extend(true,{
|
|
23
23
|
processArgs: {},
|
|
24
24
|
processOptions: {
|
|
25
25
|
cwd: cwd,
|
package/loader/index.js
CHANGED
|
@@ -3,7 +3,6 @@ const fs = require('fs');
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const UtilsCore = require('../core/lib/utils');
|
|
5
5
|
const Ps = require('../ps');
|
|
6
|
-
const Log = require('../log');
|
|
7
6
|
|
|
8
7
|
module.exports = {
|
|
9
8
|
|
|
@@ -24,11 +23,10 @@ module.exports = {
|
|
|
24
23
|
filepath = filepath && this.resolveModule(filepath);
|
|
25
24
|
if (!fs.existsSync(filepath)) {
|
|
26
25
|
let errorMsg = `[ee-core] [loader/index] loadOneFile ${filepath} does not exist`;
|
|
27
|
-
Log.coreLogger.error(errorMsg);
|
|
28
26
|
throw new Error(errorMsg);
|
|
29
27
|
}
|
|
30
28
|
|
|
31
|
-
|
|
29
|
+
let ret = UtilsCore.loadFile(filepath);
|
|
32
30
|
if (is.function(ret) && !is.class(ret) && !UtilsCore.isBytecodeClass(ret)) {
|
|
33
31
|
ret = ret(...inject);
|
|
34
32
|
}
|
|
@@ -45,8 +43,7 @@ module.exports = {
|
|
|
45
43
|
loadJsFile (filepath) {
|
|
46
44
|
if (!fs.existsSync(filepath)) {
|
|
47
45
|
let errMsg = `[ee-core] [loader] loadJobFile ${filepath} does not exist`;
|
|
48
|
-
|
|
49
|
-
return;
|
|
46
|
+
throw new Error(errMsg);
|
|
50
47
|
}
|
|
51
48
|
|
|
52
49
|
const ret = UtilsCore.loadFile(filepath);
|
|
@@ -64,8 +61,7 @@ module.exports = {
|
|
|
64
61
|
execJsFile (filepath, ...inject) {
|
|
65
62
|
if (!fs.existsSync(filepath)) {
|
|
66
63
|
let errMsg = `[ee-core] [loader] loadJobFile ${filepath} does not exist`;
|
|
67
|
-
|
|
68
|
-
return;
|
|
64
|
+
throw new Error(errMsg);
|
|
69
65
|
}
|
|
70
66
|
|
|
71
67
|
let ret = UtilsCore.loadFile(filepath);
|
|
@@ -97,7 +93,7 @@ module.exports = {
|
|
|
97
93
|
|
|
98
94
|
if (!fs.existsSync(filepath) && !fs.existsSync(fullpath)) {
|
|
99
95
|
let files = { filepath, fullpath }
|
|
100
|
-
|
|
96
|
+
console.warn(`[ee-core] [loader] resolveModule unknow filepath: ${files}`)
|
|
101
97
|
return undefined;
|
|
102
98
|
}
|
|
103
99
|
}
|
|
@@ -122,7 +118,7 @@ module.exports = {
|
|
|
122
118
|
fullpath = this.resolveModule(filepath);
|
|
123
119
|
if (!fs.existsSync(fullpath)) {
|
|
124
120
|
let errorMsg = `[ee-core] [loader] requireModule filepath: ${filepath} does not exist`;
|
|
125
|
-
|
|
121
|
+
throw new Error(errorMsg);
|
|
126
122
|
}
|
|
127
123
|
const ret = UtilsCore.loadFile(fullpath);
|
|
128
124
|
|
package/log/logger.js
CHANGED
|
@@ -3,8 +3,9 @@ const assert = require('assert');
|
|
|
3
3
|
const dayjs = require('dayjs');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const Ps = require('../ps');
|
|
6
|
-
const Conf = require('../config');
|
|
7
6
|
const ConfigCache = require('../config/cache');
|
|
7
|
+
const extend = require('../utils/extend');
|
|
8
|
+
|
|
8
9
|
let LogDate = 0;
|
|
9
10
|
const TmpFileName = {
|
|
10
11
|
appLogName: '',
|
|
@@ -39,17 +40,13 @@ module.exports = {
|
|
|
39
40
|
coreLogger: {},
|
|
40
41
|
allowDebugAtProd: false,
|
|
41
42
|
enablePerformanceTimer: false,
|
|
42
|
-
rotator: '
|
|
43
|
+
rotator: 'day',
|
|
43
44
|
},
|
|
44
45
|
customLogger: {}
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (!sysConfig) {
|
|
50
|
-
sysConfig = Conf.all(false);
|
|
51
|
-
}
|
|
52
|
-
opt = Object.assign(defaultConfig, {
|
|
48
|
+
const sysConfig = ConfigCache.all();
|
|
49
|
+
opt = extend(true, defaultConfig, {
|
|
53
50
|
logger: sysConfig.logger,
|
|
54
51
|
customLogger: sysConfig.customLogger || {}
|
|
55
52
|
});
|
package/main/index.js
CHANGED
|
@@ -43,13 +43,13 @@ class ElectronEgg {
|
|
|
43
43
|
baseDir = Ps.getEncryptDir(app.getAppPath());
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (!fs.existsSync(
|
|
46
|
+
const indexFile = path.join(baseDir, 'index');
|
|
47
|
+
const indexModulePath = Loader.resolveModule(indexFile);
|
|
48
|
+
if (!fs.existsSync(indexModulePath)) {
|
|
49
49
|
throw new Error(`The ${indexFile} file does not exist`);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
const EEApp = UtilsCore.loadFile(
|
|
52
|
+
const EEApp = UtilsCore.loadFile(indexModulePath);
|
|
53
53
|
EE.app = new EEApp();
|
|
54
54
|
}
|
|
55
55
|
}
|
package/message/childMessage.js
CHANGED
|
@@ -40,7 +40,6 @@ class ChildMessage {
|
|
|
40
40
|
*/
|
|
41
41
|
sendErrorToTerminal(err) {
|
|
42
42
|
let errTips = (err && typeof err == 'object') ? err.toString() : '';
|
|
43
|
-
errTips += ' Error !!! Please See file ee-core.log or ee-error-xxx.log for details !'
|
|
44
43
|
let message = {
|
|
45
44
|
channel: Channel.process.showException,
|
|
46
45
|
data: errTips
|
package/package.json
CHANGED
package/ps/index.js
CHANGED
|
@@ -19,7 +19,7 @@ class FileSync extends Base {
|
|
|
19
19
|
let canDeserialized = this._canDeserialized(data);
|
|
20
20
|
if (!canDeserialized) {
|
|
21
21
|
let errMessage = `[ee-core] [storage/jsondb] malformed json in file: ${this.source}\n${data}`;
|
|
22
|
-
|
|
22
|
+
console.error(errMessage);
|
|
23
23
|
|
|
24
24
|
// 是否文件结尾多一个括号,尝试处理
|
|
25
25
|
data = data.trim().slice(0, -1);
|
|
@@ -34,7 +34,7 @@ class FileSync extends Base {
|
|
|
34
34
|
this._fsWrite(this.defaultValue);
|
|
35
35
|
}
|
|
36
36
|
errMessage = '[ee-core] [storage/jsondb] malformed json that cannot be handled!';
|
|
37
|
-
|
|
37
|
+
console.error(errMessage);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
const value = canDeserialized ? this.deserialize(data) : this.defaultValue;
|
|
@@ -53,7 +53,7 @@ class FileSync extends Base {
|
|
|
53
53
|
_fsWrite(data) {
|
|
54
54
|
const isObject = Object.prototype.toString.call(data) === '[object Object]';
|
|
55
55
|
if (!isObject) {
|
|
56
|
-
|
|
56
|
+
console.error('[ee-core] [storage/jsondb] Variable is not an object :', data);
|
|
57
57
|
return
|
|
58
58
|
}
|
|
59
59
|
|