ee-core 2.12.0 → 4.0.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/app/application.d.ts +5 -0
- package/app/application.js +31 -0
- package/app/boot.d.ts +5 -0
- package/app/boot.js +74 -0
- package/app/dir.d.ts +1 -0
- package/app/dir.js +27 -0
- package/app/events.d.ts +14 -0
- package/app/events.js +56 -0
- package/app/index.d.ts +2 -0
- package/app/index.js +7 -0
- package/config/config_loader.d.ts +13 -0
- package/config/config_loader.js +19 -23
- package/config/default_config.d.ts +95 -0
- package/config/default_config.js +111 -0
- package/config/index.d.ts +28 -0
- package/config/index.js +20 -37
- package/const/channel.d.ts +16 -0
- package/const/channel.js +26 -16
- package/controller/controller_loader.d.ts +9 -0
- package/controller/controller_loader.js +78 -0
- package/controller/index.d.ts +2 -0
- package/controller/index.js +18 -19
- package/core/index.d.ts +2 -0
- package/core/index.js +6 -5
- package/core/loader/file_loader.d.ts +66 -0
- package/core/{lib/loader → loader}/file_loader.js +39 -156
- package/core/utils/index.d.ts +12 -0
- package/core/utils/index.js +83 -0
- package/core/utils/timing.d.ts +22 -0
- package/core/{lib/utils → utils}/timing.js +3 -2
- package/cross/cross.d.ts +19 -0
- package/cross/cross.js +152 -0
- package/cross/crossProcess.d.ts +29 -0
- package/cross/{spawnProcess.js → crossProcess.js} +36 -53
- package/cross/index.d.ts +2 -0
- package/cross/index.js +6 -181
- package/electron/app/index.d.ts +5 -0
- package/electron/app/index.js +38 -54
- package/electron/index.d.ts +3 -0
- package/electron/index.js +13 -17
- package/electron/window/index.d.ts +6 -0
- package/electron/window/index.js +260 -65
- package/exception/index.d.ts +9 -0
- package/exception/index.js +42 -54
- package/html/index.d.ts +1 -0
- package/html/index.js +7 -10
- package/index.d.ts +2 -0
- package/index.js +4 -52
- package/jobs/child/app.d.ts +1 -0
- package/jobs/child/app.js +10 -10
- package/jobs/child/index.d.ts +13 -0
- package/jobs/child/index.js +14 -11
- package/jobs/child/jobProcess.d.ts +16 -0
- package/jobs/child/{forkProcess.js → jobProcess.js} +31 -62
- package/jobs/child-pool/index.d.ts +26 -0
- package/jobs/child-pool/index.js +25 -48
- package/jobs/index.d.ts +3 -0
- package/jobs/index.js +2 -4
- package/jobs/load-balancer/algorithm/index.d.ts +4 -0
- package/jobs/load-balancer/algorithm/minimumConnection.d.ts +2 -0
- package/jobs/load-balancer/algorithm/polling.d.ts +2 -0
- package/jobs/load-balancer/algorithm/random.d.ts +2 -0
- package/jobs/load-balancer/algorithm/specify.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weights.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weightsMinimumConnection.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weightsPolling.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weightsRandom.d.ts +2 -0
- package/jobs/load-balancer/consts.d.ts +8 -0
- package/jobs/load-balancer/index.d.ts +96 -0
- package/jobs/load-balancer/scheduler.d.ts +16 -0
- package/loader/index.d.ts +9 -0
- package/loader/index.js +73 -143
- package/log/index.d.ts +5 -0
- package/log/index.js +74 -57
- package/log/logger.d.ts +2 -0
- package/log/logger.js +75 -80
- package/message/childMessage.d.ts +10 -0
- package/message/childMessage.js +15 -25
- package/message/index.d.ts +3 -0
- package/message/index.js +7 -16
- package/package.json +8 -2
- package/ps/index.d.ts +37 -0
- package/ps/index.js +135 -238
- package/socket/httpServer.d.ts +8 -0
- package/socket/httpServer.js +55 -45
- package/socket/index.d.ts +10 -0
- package/socket/index.js +52 -69
- package/socket/ipcServer.d.ts +9 -0
- package/socket/ipcServer.js +87 -94
- package/socket/socketServer.d.ts +10 -0
- package/socket/socketServer.js +37 -25
- package/storage/index.d.ts +5 -0
- package/storage/index.js +5 -37
- package/storage/sqliteStorage.d.ts +16 -0
- package/storage/sqliteStorage.js +20 -20
- package/tsconfig.json +14 -0
- package/utils/extend.d.ts +2 -0
- package/utils/extend.js +10 -5
- package/utils/helper.d.ts +14 -0
- package/utils/helper.js +39 -53
- package/utils/index.d.ts +10 -0
- package/utils/index.js +47 -40
- package/utils/ip.d.ts +2 -0
- package/utils/ip.js +5 -45
- package/utils/is.d.ts +14 -0
- package/utils/is.js +107 -141
- package/utils/json.d.ts +5 -0
- package/utils/json.js +15 -7
- package/utils/pargv.d.ts +3 -0
- package/utils/pargv.js +5 -1
- package/utils/port/index.d.ts +1 -0
- package/utils/{get-port → port}/index.js +4 -26
- package/utils/wrap.d.ts +4 -0
- package/utils/wrap.js +8 -3
- package/addon/index.js +0 -35
- package/addon/window/index.js +0 -99
- package/bin/tools.js +0 -8
- package/config/cache.js +0 -62
- package/config/config.default.js +0 -331
- package/const/index.js +0 -9
- package/controller/baseContextClass.js +0 -25
- package/core/lib/ee.js +0 -216
- package/core/lib/loader/context_loader.js +0 -106
- package/core/lib/loader/ee_loader.js +0 -435
- package/core/lib/loader/mixin/addon.js +0 -32
- package/core/lib/loader/mixin/config.js +0 -130
- package/core/lib/loader/mixin/controller.js +0 -125
- package/core/lib/loader/mixin/service.js +0 -28
- package/core/lib/utils/base_context_class.js +0 -34
- package/core/lib/utils/function.js +0 -30
- package/core/lib/utils/index.js +0 -133
- package/core/lib/utils/sequencify.js +0 -59
- package/ee/appLoader.js +0 -48
- package/ee/application.js +0 -101
- package/ee/baseApp.js +0 -99
- package/ee/eeApp.js +0 -406
- package/ee/index.js +0 -58
- package/electron/window/winState.js +0 -186
- package/httpclient/index.js +0 -161
- package/jobs/baseJobClass.js +0 -16
- package/jobs/renderer/index.js +0 -141
- package/jobs/renderer/loadView.js +0 -41
- package/jobs/unification.js +0 -64
- package/main/index.js +0 -57
- package/old-utils/index.js +0 -91
- package/services/baseContextClass.js +0 -24
- package/services/index.js +0 -41
- package/socket/io.js +0 -28
- package/storage/jsondb/adapters/Base.js +0 -23
- package/storage/jsondb/adapters/FileSync.js +0 -64
- package/storage/jsondb/main.js +0 -55
- package/storage/jsondbStorage.js +0 -196
- package/utils/co.js +0 -237
- package/utils/copyto.js +0 -161
- package/utils/depd/index.js +0 -538
- package/utils/depd/lib/browser/index.js +0 -77
- package/utils/get-port/index.d.ts +0 -64
- package/utils/time/index.js +0 -20
- package/utils/time/ms.js +0 -162
package/loader/index.js
CHANGED
|
@@ -1,162 +1,92 @@
|
|
|
1
1
|
const is = require('is-type-of');
|
|
2
2
|
const fs = require('fs');
|
|
3
3
|
const path = require('path');
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const CoreUtils = require('../core/utils');
|
|
5
|
+
const { getElectronDir } = require('../ps');
|
|
6
|
+
|
|
7
|
+
// 加载单个文件(如果是函数,将被执行)
|
|
8
|
+
function loadFile(filepath, ...inject) {
|
|
9
|
+
const isAbsolute = path.isAbsolute(filepath);
|
|
10
|
+
if (!isAbsolute) {
|
|
11
|
+
filepath = path.join(getElectronDir(), filepath);
|
|
12
|
+
}
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* @return {Object} exports
|
|
15
|
-
* @since 1.0.0
|
|
16
|
-
*/
|
|
17
|
-
loadOneFile (filepath, ...inject) {
|
|
18
|
-
const isAbsolute = path.isAbsolute(filepath);
|
|
19
|
-
if (!isAbsolute) {
|
|
20
|
-
filepath = path.join(Ps.getBaseDir(), filepath);
|
|
21
|
-
}
|
|
14
|
+
filepath = filepath && resolveModule(filepath);
|
|
15
|
+
if (!fs.existsSync(filepath)) {
|
|
16
|
+
let errorMsg = `[ee-core] [loader/index] loadFile ${filepath} does not exist`;
|
|
17
|
+
throw new Error(errorMsg);
|
|
18
|
+
}
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
let ret = CoreUtils.loadFile(filepath);
|
|
21
|
+
if (is.function(ret) && !is.class(ret) && !CoreUtils.isBytecodeClass(ret)) {
|
|
22
|
+
ret = ret(...inject);
|
|
23
|
+
}
|
|
24
|
+
return ret;
|
|
25
|
+
}
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return ret;
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* 加载js文件
|
|
38
|
-
*
|
|
39
|
-
* @param {String} filepath - fullpath
|
|
40
|
-
* @return {Any} exports
|
|
41
|
-
* @since 1.0.0
|
|
42
|
-
*/
|
|
43
|
-
loadJsFile (filepath) {
|
|
44
|
-
if (!fs.existsSync(filepath)) {
|
|
45
|
-
let errMsg = `[ee-core] [loader] loadJobFile ${filepath} does not exist`;
|
|
46
|
-
throw new Error(errMsg);
|
|
47
|
-
}
|
|
27
|
+
// requireFile
|
|
28
|
+
function requireFile(filepath) {
|
|
29
|
+
return CoreUtils.loadFile(filepath);
|
|
30
|
+
}
|
|
48
31
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
* @param {Array} inject - pass rest arguments into the function when invoke
|
|
58
|
-
* @return {Any}
|
|
59
|
-
* @since 1.0.0
|
|
60
|
-
*/
|
|
61
|
-
execJsFile (filepath, ...inject) {
|
|
62
|
-
if (!fs.existsSync(filepath)) {
|
|
63
|
-
let errMsg = `[ee-core] [loader] loadJobFile ${filepath} does not exist`;
|
|
64
|
-
throw new Error(errMsg);
|
|
65
|
-
}
|
|
32
|
+
// 加载并运行文件
|
|
33
|
+
function execFile(filepath, ...inject) {
|
|
34
|
+
let ret = CoreUtils.loadFile(filepath);
|
|
35
|
+
if (is.class(ret) || CoreUtils.isBytecodeClass(ret)) {
|
|
36
|
+
ret = new ret(inject);
|
|
37
|
+
} else if (is.function(ret)) {
|
|
38
|
+
ret = ret(inject);
|
|
39
|
+
}
|
|
66
40
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
ret = new ret(inject);
|
|
70
|
-
} else if (is.function(ret)) {
|
|
71
|
-
ret = ret(inject);
|
|
72
|
-
}
|
|
41
|
+
return ret;
|
|
42
|
+
}
|
|
73
43
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
// 特殊后缀处理
|
|
88
|
-
if (filepath && (filepath.endsWith('.defalut') || filepath.endsWith('.prod'))) {
|
|
89
|
-
fullpath = filepath + '.jsc';
|
|
90
|
-
} else if (filepath && filepath.endsWith('.js')) {
|
|
91
|
-
fullpath = filepath + 'c';
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (!fs.existsSync(filepath) && !fs.existsSync(fullpath)) {
|
|
95
|
-
let files = { filepath, fullpath }
|
|
96
|
-
console.warn(`[ee-core] [loader] resolveModule unknow filepath: ${files}`)
|
|
97
|
-
return undefined;
|
|
98
|
-
}
|
|
44
|
+
// 模块的绝对路径
|
|
45
|
+
function resolveModule(filepath) {
|
|
46
|
+
let fullpath;
|
|
47
|
+
try {
|
|
48
|
+
fullpath = require.resolve(filepath);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
|
|
51
|
+
// 特殊后缀处理
|
|
52
|
+
if (filepath && (filepath.endsWith('.defalut') || filepath.endsWith('.prod'))) {
|
|
53
|
+
fullpath = filepath + '.jsc';
|
|
54
|
+
} else if (filepath && filepath.endsWith('.js')) {
|
|
55
|
+
fullpath = filepath + 'c';
|
|
99
56
|
}
|
|
100
57
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
* 加载模块(子进程中使用)
|
|
106
|
-
*
|
|
107
|
-
* @param {String} filepath - fullpath
|
|
108
|
-
* @return {Object} exports
|
|
109
|
-
* @since 1.0.0
|
|
110
|
-
*/
|
|
111
|
-
requireModule (filepath, type = '') {
|
|
112
|
-
let fullpath;
|
|
113
|
-
const isAbsolute = path.isAbsolute(filepath);
|
|
114
|
-
if (!isAbsolute) {
|
|
115
|
-
filepath = path.join(Ps.getBaseDir(), type, filepath);
|
|
58
|
+
if (!fs.existsSync(filepath) && !fs.existsSync(fullpath)) {
|
|
59
|
+
let files = { filepath, fullpath }
|
|
60
|
+
console.warn(`[ee-core] [loader] resolveModule unknow filepath: ${files}`)
|
|
61
|
+
return undefined;
|
|
116
62
|
}
|
|
63
|
+
}
|
|
117
64
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
let errorMsg = `[ee-core] [loader] requireModule filepath: ${filepath} does not exist`;
|
|
121
|
-
throw new Error(errorMsg);
|
|
122
|
-
}
|
|
123
|
-
const ret = UtilsCore.loadFile(fullpath);
|
|
124
|
-
|
|
125
|
-
return ret;
|
|
126
|
-
},
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* 加载jobs模块(子进程中使用)
|
|
130
|
-
*
|
|
131
|
-
* @param {String} filepath - fullpath
|
|
132
|
-
* @return {Object} exports
|
|
133
|
-
* @since 1.0.0
|
|
134
|
-
*/
|
|
135
|
-
requireJobsModule (filepath) {
|
|
136
|
-
const ret = this.requireModule(filepath, 'jobs');
|
|
137
|
-
|
|
138
|
-
return ret;
|
|
139
|
-
},
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* 获取electron目录下文件的绝对路径
|
|
143
|
-
* @param {String} filepath - fullpath
|
|
144
|
-
*/
|
|
145
|
-
getFullpath(filepath) {
|
|
146
|
-
let fullpath;
|
|
147
|
-
const isAbsolute = path.isAbsolute(filepath);
|
|
148
|
-
if (!isAbsolute) {
|
|
149
|
-
filepath = path.join(Ps.getBaseDir(), filepath);
|
|
150
|
-
}
|
|
65
|
+
return fullpath;
|
|
66
|
+
}
|
|
151
67
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
68
|
+
// 获取electron目录下文件的绝对路径
|
|
69
|
+
function getFullpath(filepath) {
|
|
70
|
+
let fullpath;
|
|
71
|
+
const isAbsolute = path.isAbsolute(filepath);
|
|
72
|
+
if (!isAbsolute) {
|
|
73
|
+
filepath = path.join(getElectronDir(), filepath);
|
|
74
|
+
}
|
|
156
75
|
|
|
157
|
-
|
|
76
|
+
fullpath = resolveModule(filepath);
|
|
77
|
+
if (!fs.existsSync(fullpath)) {
|
|
78
|
+
throw new Error(`[ee-core] [loader] getFullpath filepath ${filepath} not exists`);
|
|
158
79
|
}
|
|
159
|
-
|
|
80
|
+
|
|
81
|
+
return fullpath;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
module.exports = {
|
|
85
|
+
loadFile,
|
|
86
|
+
execFile,
|
|
87
|
+
requireFile,
|
|
88
|
+
resolveModule,
|
|
89
|
+
getFullpath,
|
|
160
90
|
}
|
|
161
91
|
|
|
162
92
|
|
package/log/index.d.ts
ADDED
package/log/index.js
CHANGED
|
@@ -1,69 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
const Logger = require('./logger');
|
|
3
|
-
const EELoggers = Symbol('EeApplication#EELoggers');
|
|
4
|
-
let LogDate = 0;
|
|
1
|
+
'use strict';
|
|
5
2
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
* 创建日志实例
|
|
9
|
-
*/
|
|
10
|
-
create(config) {
|
|
11
|
-
this._delCache();
|
|
12
|
-
const eeLog = Logger.create(config);
|
|
3
|
+
const dayjs = require('dayjs');
|
|
4
|
+
const { create } = require('./logger');
|
|
13
5
|
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
const Instance = {
|
|
7
|
+
eelog: null,
|
|
8
|
+
logger: {},
|
|
9
|
+
coreLogger: {},
|
|
10
|
+
};
|
|
11
|
+
let logDate = 0;
|
|
12
|
+
const logProperties = ['error', 'warn', 'info', 'debug'];
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
_delCache() {
|
|
21
|
-
let now = parseInt(dayjs().format('YYYYMMDD'));
|
|
22
|
-
if (LogDate != now) {
|
|
23
|
-
LogDate = now;
|
|
24
|
-
this[EELoggers] = null;
|
|
25
|
-
}
|
|
26
|
-
},
|
|
14
|
+
// define logger/coreLogger properties
|
|
15
|
+
defineLoggerProperty();
|
|
16
|
+
defineCoreLoggerProperty();
|
|
27
17
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
this._delCache();
|
|
33
|
-
if (!this[EELoggers]) {
|
|
34
|
-
this[EELoggers] = Logger.create();
|
|
35
|
-
}
|
|
18
|
+
// Create a log instance
|
|
19
|
+
function createLog(config) {
|
|
20
|
+
_delCache();
|
|
21
|
+
const eeLog = create(config);
|
|
36
22
|
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
return eeLog;
|
|
24
|
+
}
|
|
39
25
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
this._delCache();
|
|
45
|
-
if (!this[EELoggers]) {
|
|
46
|
-
this[EELoggers] = Logger.create();
|
|
47
|
-
}
|
|
26
|
+
function loadLog() {
|
|
27
|
+
Instance.eelog = createLog();
|
|
28
|
+
return Instance.eelog;
|
|
29
|
+
}
|
|
48
30
|
|
|
49
|
-
|
|
50
|
-
|
|
31
|
+
function defineLoggerProperty() {
|
|
32
|
+
for (const property of logProperties) {
|
|
33
|
+
Object.defineProperty(Instance.logger, property, {
|
|
34
|
+
get() {
|
|
35
|
+
//console.log('emit logger property: ', property);
|
|
36
|
+
let log = getLogger();
|
|
37
|
+
let val = log[property].bind(log);
|
|
38
|
+
return val;
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
51
43
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
function defineCoreLoggerProperty() {
|
|
45
|
+
for (const property of logProperties) {
|
|
46
|
+
Object.defineProperty(Instance.coreLogger, property, {
|
|
47
|
+
get() {
|
|
48
|
+
let log = getCoreLogger();
|
|
49
|
+
let val = log[property].bind(log);
|
|
50
|
+
return val;
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
function _delCache() {
|
|
57
|
+
const now = parseInt(dayjs().format('YYYYMMDD'));
|
|
58
|
+
if (logDate != now) {
|
|
59
|
+
logDate = now;
|
|
60
|
+
Instance.eelog = null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
59
63
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
function getLogger() {
|
|
65
|
+
_delCache();
|
|
66
|
+
if (!Instance.eelog) {
|
|
67
|
+
loadLog();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return Instance.eelog["logger"];
|
|
71
|
+
}
|
|
63
72
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
73
|
+
function getCoreLogger() {
|
|
74
|
+
_delCache();
|
|
75
|
+
if (!Instance.eelog) {
|
|
76
|
+
loadLog();
|
|
77
|
+
}
|
|
78
|
+
return Instance.eelog["coreLogger"];
|
|
79
|
+
}
|
|
68
80
|
|
|
69
|
-
module.exports =
|
|
81
|
+
module.exports = {
|
|
82
|
+
createLog,
|
|
83
|
+
loadLog,
|
|
84
|
+
logger: Instance.logger,
|
|
85
|
+
coreLogger: Instance.coreLogger
|
|
86
|
+
};
|
package/log/logger.d.ts
ADDED
package/log/logger.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const debug = require('debug')('ee-core:log:logger');
|
|
1
4
|
const Loggers = require('egg-logger').EggLoggers;
|
|
2
|
-
const assert = require('assert');
|
|
3
5
|
const dayjs = require('dayjs');
|
|
4
6
|
const path = require('path');
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
7
|
+
const { extend } = require('../utils/extend');
|
|
8
|
+
const { getConfig } = require('../config');
|
|
9
|
+
const { getLogDir, env, isDev } = require('../ps');
|
|
8
10
|
|
|
9
11
|
let LogDate = 0;
|
|
10
12
|
const TmpFileName = {
|
|
@@ -13,88 +15,81 @@ const TmpFileName = {
|
|
|
13
15
|
errorLogName: '',
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
// 创建
|
|
19
|
+
function create(config = {}) {
|
|
20
|
+
let opt = {};
|
|
21
|
+
|
|
22
|
+
if (Object.keys(config).length == 0) {
|
|
23
|
+
const defaultConfig = {
|
|
24
|
+
logger: {
|
|
25
|
+
type: 'application',
|
|
26
|
+
dir: getLogDir(),
|
|
27
|
+
env: env(),
|
|
28
|
+
consoleLevel: 'INFO',
|
|
29
|
+
disableConsoleAfterReady: !isDev(),
|
|
30
|
+
coreLogger: {},
|
|
31
|
+
allowDebugAtProd: false,
|
|
32
|
+
agentLogName: 'ee-agent.log',
|
|
33
|
+
rotator: 'day',
|
|
34
|
+
},
|
|
35
|
+
customLogger: {}
|
|
36
|
+
};
|
|
37
|
+
const sysConfig = getConfig();
|
|
38
|
+
opt = extend(true, defaultConfig, {
|
|
39
|
+
logger: sysConfig.logger,
|
|
40
|
+
customLogger: sysConfig.customLogger || {}
|
|
41
|
+
});
|
|
42
|
+
} else {
|
|
43
|
+
opt.logger = config.logger;
|
|
44
|
+
opt.customLogger = config.customLogger;
|
|
45
|
+
}
|
|
17
46
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
create(config = {}) {
|
|
22
|
-
let opt = {};
|
|
23
|
-
|
|
24
|
-
if (Object.keys(config).length == 0) {
|
|
25
|
-
const defaultConfig = {
|
|
26
|
-
logger: {
|
|
27
|
-
type: 'application',
|
|
28
|
-
dir: Ps.getLogDir(),
|
|
29
|
-
encoding: 'utf8',
|
|
30
|
-
env: Ps.env(),
|
|
31
|
-
level: 'INFO',
|
|
32
|
-
consoleLevel: 'INFO',
|
|
33
|
-
disableConsoleAfterReady: !Ps.isDev(),
|
|
34
|
-
outputJSON: false,
|
|
35
|
-
buffer: true,
|
|
36
|
-
appLogName: `ee.log`,
|
|
37
|
-
coreLogName: 'ee-core.log',
|
|
38
|
-
agentLogName: 'ee-agent.log',
|
|
39
|
-
errorLogName: `ee-error.log`,
|
|
40
|
-
coreLogger: {},
|
|
41
|
-
allowDebugAtProd: false,
|
|
42
|
-
enablePerformanceTimer: false,
|
|
43
|
-
rotator: 'day',
|
|
44
|
-
},
|
|
45
|
-
customLogger: {}
|
|
46
|
-
}
|
|
47
|
+
if (Object.keys(opt).length == 0) {
|
|
48
|
+
throw new Error("logger config is null");
|
|
49
|
+
}
|
|
47
50
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
} else {
|
|
54
|
-
opt.logger = config.logger;
|
|
55
|
-
opt.customLogger = config.customLogger;
|
|
56
|
-
}
|
|
57
|
-
// console.log('log---------', opt);
|
|
51
|
+
let rotateType = opt.logger.rotator;
|
|
52
|
+
if (rotateType == 'day') {
|
|
53
|
+
opt = _rotateByDay(opt);
|
|
54
|
+
}
|
|
58
55
|
|
|
59
|
-
|
|
56
|
+
debug('[create] opt:%j', opt);
|
|
57
|
+
const loggers = new Loggers(opt);
|
|
60
58
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
return loggers;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 按天分割
|
|
64
|
+
*/
|
|
65
|
+
function _rotateByDay(logOpt) {
|
|
66
|
+
const now = parseInt(dayjs().format('YYYYMMDD'));
|
|
67
|
+
if (LogDate != now) {
|
|
68
|
+
LogDate = now;
|
|
65
69
|
|
|
66
|
-
|
|
70
|
+
// 保存一个临时文件名,防止文件名按日期累加
|
|
71
|
+
if (TmpFileName.appLogName.length == 0) {
|
|
72
|
+
TmpFileName.appLogName = logOpt.logger.appLogName;
|
|
73
|
+
}
|
|
74
|
+
if (TmpFileName.coreLogName.length == 0) {
|
|
75
|
+
TmpFileName.coreLogName = logOpt.logger.coreLogName;
|
|
76
|
+
}
|
|
77
|
+
if (TmpFileName.errorLogName.length == 0) {
|
|
78
|
+
TmpFileName.errorLogName = logOpt.logger.errorLogName;
|
|
79
|
+
}
|
|
67
80
|
|
|
68
|
-
|
|
69
|
-
|
|
81
|
+
const {appLogName, coreLogName, errorLogName} = TmpFileName;
|
|
82
|
+
const appLogExtname = path.extname(appLogName);
|
|
83
|
+
const coreLogExtname = path.extname(coreLogName);
|
|
84
|
+
const errorLogExtname = path.extname(errorLogName);
|
|
85
|
+
logOpt.logger.appLogName = path.basename(appLogName, appLogExtname) + '-' + now + appLogExtname;
|
|
86
|
+
logOpt.logger.coreLogName = path.basename(coreLogName, coreLogExtname) + '-' + now + coreLogExtname;
|
|
87
|
+
logOpt.logger.errorLogName = path.basename(errorLogName, errorLogExtname) + '-' + now + errorLogExtname;
|
|
88
|
+
}
|
|
70
89
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
*/
|
|
74
|
-
_rotateByDay(logOpt) {
|
|
75
|
-
let now = parseInt(dayjs().format('YYYYMMDD'));
|
|
76
|
-
if (LogDate != now) {
|
|
77
|
-
LogDate = now;
|
|
90
|
+
return logOpt;
|
|
91
|
+
}
|
|
78
92
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
TmpFileName.appLogName = logOpt.logger.appLogName;
|
|
82
|
-
}
|
|
83
|
-
if (TmpFileName.coreLogName.length == 0) {
|
|
84
|
-
TmpFileName.coreLogName = logOpt.logger.coreLogName;
|
|
85
|
-
}
|
|
86
|
-
if (TmpFileName.errorLogName.length == 0) {
|
|
87
|
-
TmpFileName.errorLogName = logOpt.logger.errorLogName;
|
|
88
|
-
}
|
|
89
|
-
let appLogName = TmpFileName.appLogName;
|
|
90
|
-
let coreLogName = TmpFileName.coreLogName;
|
|
91
|
-
let errorLogName = TmpFileName.errorLogName;
|
|
92
|
-
let appLogExtname = path.extname(appLogName);
|
|
93
|
-
let coreLogExtname = path.extname(coreLogName);
|
|
94
|
-
let errorLogExtname = path.extname(errorLogName);
|
|
95
|
-
logOpt.logger.appLogName = path.basename(appLogName, appLogExtname) + '-' + now + appLogExtname;
|
|
96
|
-
logOpt.logger.coreLogName = path.basename(coreLogName, coreLogExtname) + '-' + now + coreLogExtname;
|
|
97
|
-
logOpt.logger.errorLogName = path.basename(errorLogName, errorLogExtname) + '-' + now + errorLogExtname;
|
|
98
|
-
}
|
|
99
|
-
},
|
|
93
|
+
module.exports = {
|
|
94
|
+
create
|
|
100
95
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class ChildMessage {
|
|
2
|
+
// 向主进程发消息 for ChildJob 实例
|
|
3
|
+
sendToMain(eventName: string, params?: {}): boolean;
|
|
4
|
+
// 向主进程发消息 for task 实例
|
|
5
|
+
send(eventName: string, params: {}, receiver?: string): boolean;
|
|
6
|
+
// 进程退出
|
|
7
|
+
exit(code?: number): never;
|
|
8
|
+
// 发送错误到控制台
|
|
9
|
+
sendErrorToTerminal(err: any): void;
|
|
10
|
+
}
|
package/message/childMessage.js
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { Receiver, Processes } = require('../const/channel');
|
|
2
4
|
|
|
3
5
|
class ChildMessage {
|
|
4
|
-
constructor() {
|
|
5
|
-
// ...
|
|
6
|
-
}
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
* 向主进程发消息 for ChildJob 实例
|
|
10
|
-
*/
|
|
7
|
+
// Send a message to the main process for ChildJob instance
|
|
11
8
|
sendToMain(eventName, params = {}) {
|
|
12
|
-
|
|
9
|
+
const receiver = Receiver.childJob;
|
|
13
10
|
return this.send(eventName, params, receiver);
|
|
14
11
|
}
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
* 向主进程发消息 for task 实例
|
|
18
|
-
*/
|
|
13
|
+
// Send a message to the main process for a task instance
|
|
19
14
|
send(eventName, params = {}, receiver) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
channel:
|
|
15
|
+
const eventReceiver = receiver || Receiver.forkProcess;
|
|
16
|
+
const message = {
|
|
17
|
+
channel: Processes.sendToMain,
|
|
23
18
|
eventReceiver,
|
|
24
19
|
event: eventName,
|
|
25
20
|
data: params,
|
|
@@ -28,26 +23,21 @@ class ChildMessage {
|
|
|
28
23
|
return process.send(message);
|
|
29
24
|
}
|
|
30
25
|
|
|
31
|
-
/**
|
|
32
|
-
* 进程退出
|
|
33
|
-
*/
|
|
34
26
|
exit(code = 0) {
|
|
35
27
|
return process.exit(code);
|
|
36
28
|
}
|
|
37
29
|
|
|
38
|
-
/**
|
|
39
|
-
* 发送错误到控制台
|
|
40
|
-
*/
|
|
41
30
|
sendErrorToTerminal(err) {
|
|
42
31
|
let errTips = (err && typeof err == 'object') ? err.toString() : '';
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
errTips += ' Error !!! Please See file ee-core.log or ee-error-xxx.log for details !'
|
|
33
|
+
const message = {
|
|
34
|
+
channel: Processes.showException,
|
|
45
35
|
data: errTips
|
|
46
36
|
}
|
|
47
37
|
process.send(message);
|
|
48
38
|
}
|
|
49
39
|
}
|
|
50
40
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
module.exports = {
|
|
42
|
+
ChildMessage
|
|
43
|
+
};
|
package/message/index.js
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
const EEChildMessage = Symbol('EeCore#Module#ChildMessage');
|
|
1
|
+
'use strict';
|
|
3
2
|
|
|
4
|
-
const
|
|
3
|
+
const { ChildMessage } = require('./childMessage');
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
* childMessage
|
|
8
|
-
*/
|
|
9
|
-
get childMessage() {
|
|
10
|
-
if (!this[EEChildMessage]) {
|
|
11
|
-
this[EEChildMessage] = new ChildMessage();
|
|
12
|
-
}
|
|
5
|
+
const childMessage = new ChildMessage();
|
|
13
6
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
module.exports = message;
|
|
7
|
+
module.exports = {
|
|
8
|
+
ChildMessage,
|
|
9
|
+
childMessage
|
|
10
|
+
};
|