ee-core 2.12.0 → 4.0.0-beta.1
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.js +31 -0
- package/app/boot.js +81 -0
- package/app/dir.js +27 -0
- package/app/events.js +56 -0
- package/app/index.js +7 -0
- package/config/config_loader.js +19 -23
- package/config/default_config.js +110 -0
- package/config/index.js +20 -37
- package/const/channel.js +26 -16
- package/const/index.js +0 -4
- package/controller/controller_loader.js +78 -0
- package/controller/index.js +18 -19
- package/core/index.js +6 -5
- package/core/{lib/loader → loader}/file_loader.js +39 -156
- package/core/utils/index.js +83 -0
- package/core/{lib/utils → utils}/timing.js +3 -2
- package/cross/cross.js +152 -0
- package/cross/index.js +6 -181
- package/cross/spawnProcess.js +34 -51
- package/electron/app/index.js +38 -54
- package/electron/index.js +13 -17
- package/electron/window/index.js +260 -65
- package/exception/index.js +34 -32
- package/html/index.js +7 -10
- package/index.js +4 -52
- package/jobs/child/app.js +10 -10
- package/jobs/child/forkProcess.js +29 -45
- package/jobs/child/index.js +13 -10
- package/jobs/child-pool/index.js +13 -11
- package/jobs/index.js +2 -4
- package/loader/index.js +91 -143
- package/log/index.js +74 -57
- package/log/logger.js +75 -80
- package/message/childMessage.js +13 -13
- package/message/index.js +7 -16
- package/package.json +2 -2
- package/ps/index.js +136 -229
- package/socket/httpServer.js +46 -43
- package/socket/index.js +52 -69
- package/socket/ipcServer.js +80 -94
- package/socket/socketServer.js +31 -24
- package/storage/index.js +5 -37
- package/storage/sqliteStorage.js +18 -18
- package/utils/extend.js +10 -5
- package/utils/helper.js +38 -42
- package/utils/index.js +40 -23
- package/utils/ip.js +5 -45
- package/utils/is.js +107 -141
- package/utils/json.js +15 -7
- package/utils/pargv.js +5 -1
- package/utils/{get-port → port}/index.js +4 -26
- 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/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
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const EventEmitter = require('events');
|
|
3
|
-
const { fork } = require('child_process');
|
|
4
3
|
const serialize = require('serialize-javascript');
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
4
|
+
const { fork } = require('child_process');
|
|
5
|
+
const { coreLogger } = require('../../log');
|
|
6
|
+
const { getBaseDir, isPackaged, allEnv } = require('../../ps');
|
|
7
|
+
const { Processes, Events, Receiver } = require('../../const/channel');
|
|
8
|
+
const { getRandomString } = require('../../utils/helper');
|
|
9
|
+
const { getFullpath } = require('../../loader');
|
|
10
|
+
const { extend } = require('../../utils/extend');
|
|
11
11
|
|
|
12
12
|
class ForkProcess {
|
|
13
13
|
constructor(host, opt = {}) {
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (
|
|
15
|
+
const cwd = getBaseDir();
|
|
16
|
+
const appPath = path.join(__dirname, 'app.js');
|
|
17
|
+
if (isPackaged()) {
|
|
18
18
|
// todo fork的cwd目录为什么要在app.asar外 ?
|
|
19
|
-
cwd = path.join(
|
|
19
|
+
cwd = path.join(getBaseDir(), '..');
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
const options = extend(true, {
|
|
23
23
|
processArgs: {},
|
|
24
24
|
processOptions: {
|
|
25
25
|
cwd: cwd,
|
|
26
|
-
env:
|
|
26
|
+
env: allEnv(),
|
|
27
27
|
stdio: 'ignore' // pipe
|
|
28
28
|
}
|
|
29
29
|
}, opt);
|
|
@@ -48,15 +48,15 @@ class ForkProcess {
|
|
|
48
48
|
const { messageLog } = this.host.config;
|
|
49
49
|
this.child.on('message', (m) => {
|
|
50
50
|
if (messageLog == true) {
|
|
51
|
-
|
|
51
|
+
coreLogger.info(`[ee-core] [jobs/child] received a message from child-process, message: ${serialize(m)}`);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
if (m.channel ==
|
|
55
|
-
|
|
54
|
+
if (m.channel == Processes.showException) {
|
|
55
|
+
coreLogger.error(`${m.data}`);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// 收到子进程消息,转发到 event
|
|
59
|
-
if (m.channel ==
|
|
59
|
+
if (m.channel == Processes.sendToMain) {
|
|
60
60
|
this._eventEmit(m);
|
|
61
61
|
}
|
|
62
62
|
});
|
|
@@ -65,16 +65,16 @@ class ForkProcess {
|
|
|
65
65
|
let data = {
|
|
66
66
|
pid: this.pid
|
|
67
67
|
}
|
|
68
|
-
this.host.emit(
|
|
69
|
-
|
|
68
|
+
this.host.emit(Events.childProcessExit, data);
|
|
69
|
+
coreLogger.info(`[ee-core] [jobs/child] received a exit from child-process, code:${code}, signal:${signal}, pid:${this.pid}`);
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
this.child.on('error', (err) => {
|
|
73
73
|
let data = {
|
|
74
74
|
pid: this.pid
|
|
75
75
|
}
|
|
76
|
-
this.host.emit(
|
|
77
|
-
|
|
76
|
+
this.host.emit(Events.childProcessError, data);
|
|
77
|
+
coreLogger.error(`[ee-core] [jobs/child] received a error from child-process, error: ${err}, pid:${this.pid}`);
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -83,10 +83,10 @@ class ForkProcess {
|
|
|
83
83
|
*/
|
|
84
84
|
_eventEmit(m) {
|
|
85
85
|
switch (m.eventReceiver) {
|
|
86
|
-
case
|
|
86
|
+
case Receiver.forkProcess:
|
|
87
87
|
this.emitter.emit(m.event, m.data);
|
|
88
88
|
break;
|
|
89
|
-
case
|
|
89
|
+
case Receiver.childJob:
|
|
90
90
|
this.host.emit(m.event, m.data);
|
|
91
91
|
break;
|
|
92
92
|
default:
|
|
@@ -101,7 +101,7 @@ class ForkProcess {
|
|
|
101
101
|
*/
|
|
102
102
|
dispatch(cmd, jobPath = '', ...params) {
|
|
103
103
|
// 消息对象
|
|
104
|
-
const mid =
|
|
104
|
+
const mid = getRandomString();
|
|
105
105
|
let msg = {
|
|
106
106
|
mid,
|
|
107
107
|
cmd,
|
|
@@ -118,10 +118,10 @@ class ForkProcess {
|
|
|
118
118
|
* 调用job的方法
|
|
119
119
|
*/
|
|
120
120
|
callFunc(jobPath = '', funcName = '', ...params) {
|
|
121
|
-
jobPath =
|
|
121
|
+
jobPath = getFullpath(jobPath);
|
|
122
122
|
|
|
123
123
|
// 消息对象
|
|
124
|
-
const mid =
|
|
124
|
+
const mid = getRandomString();
|
|
125
125
|
let msg = {
|
|
126
126
|
mid,
|
|
127
127
|
cmd:'run',
|
|
@@ -142,24 +142,8 @@ class ForkProcess {
|
|
|
142
142
|
this.child.kill('SIGKILL');
|
|
143
143
|
}, timeout)
|
|
144
144
|
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* sleep (仅Unix平台)
|
|
148
|
-
*/
|
|
149
|
-
sleep() {
|
|
150
|
-
if (this.sleeping) return;
|
|
151
|
-
process.kill(this.pid, 'SIGSTOP');
|
|
152
|
-
this.sleeping = true;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* wakeup (仅Unix平台)
|
|
157
|
-
*/
|
|
158
|
-
wakeup() {
|
|
159
|
-
if (!this.sleeping) return;
|
|
160
|
-
process.kill(this.pid, 'SIGCONT');
|
|
161
|
-
this.sleeping = false;
|
|
162
|
-
}
|
|
163
145
|
}
|
|
164
146
|
|
|
165
|
-
module.exports =
|
|
147
|
+
module.exports = {
|
|
148
|
+
ForkProcess
|
|
149
|
+
};
|
package/jobs/child/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
const EventEmitter = require('events');
|
|
2
|
-
const ForkProcess = require('./forkProcess');
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
2
|
+
const { ForkProcess } = require('./forkProcess');
|
|
3
|
+
const { getFullpath } = require('../../loader');
|
|
4
|
+
const { Events } = require('../../const/channel');
|
|
5
|
+
const { getConfig } = require('../../config');
|
|
6
|
+
const { extend } = require('../../utils/extend');
|
|
6
7
|
|
|
7
8
|
class ChildJob extends EventEmitter {
|
|
8
9
|
|
|
@@ -11,7 +12,7 @@ class ChildJob extends EventEmitter {
|
|
|
11
12
|
this.jobs = {};
|
|
12
13
|
this.config = {};
|
|
13
14
|
|
|
14
|
-
const cfg =
|
|
15
|
+
const cfg = getConfig().jobs;
|
|
15
16
|
if (cfg) {
|
|
16
17
|
this.config = cfg;
|
|
17
18
|
}
|
|
@@ -23,10 +24,10 @@ class ChildJob extends EventEmitter {
|
|
|
23
24
|
* 初始化监听
|
|
24
25
|
*/
|
|
25
26
|
_initEvents() {
|
|
26
|
-
this.on(
|
|
27
|
+
this.on(Events.childProcessExit, (data) => {
|
|
27
28
|
delete this.jobs[data.pid];
|
|
28
29
|
});
|
|
29
|
-
this.on(
|
|
30
|
+
this.on(Events.childProcessError, (data) => {
|
|
30
31
|
delete this.jobs[data.pid];
|
|
31
32
|
});
|
|
32
33
|
}
|
|
@@ -35,7 +36,7 @@ class ChildJob extends EventEmitter {
|
|
|
35
36
|
* 执行一个job文件
|
|
36
37
|
*/
|
|
37
38
|
exec(filepath, params = {}, opt = {}) {
|
|
38
|
-
const jobPath =
|
|
39
|
+
const jobPath = getFullpath(filepath);
|
|
39
40
|
const proc = this.createProcess(opt);
|
|
40
41
|
const cmd = 'run';
|
|
41
42
|
proc.dispatch(cmd, jobPath, params);
|
|
@@ -47,7 +48,7 @@ class ChildJob extends EventEmitter {
|
|
|
47
48
|
* 创建子进程
|
|
48
49
|
*/
|
|
49
50
|
createProcess(opt = {}) {
|
|
50
|
-
|
|
51
|
+
const options = extend(true, {
|
|
51
52
|
processArgs: {
|
|
52
53
|
type: 'childJob'
|
|
53
54
|
}
|
|
@@ -79,4 +80,6 @@ class ChildJob extends EventEmitter {
|
|
|
79
80
|
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
module.exports =
|
|
83
|
+
module.exports = {
|
|
84
|
+
ChildJob
|
|
85
|
+
};
|
package/jobs/child-pool/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const EventEmitter = require('events');
|
|
2
2
|
const LoadBalancer = require('../load-balancer');
|
|
3
|
-
const
|
|
4
|
-
const ForkProcess = require('../child/forkProcess');
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
3
|
+
const { getFullpath } = require('../../loader');
|
|
4
|
+
const { ForkProcess } = require('../child/forkProcess');
|
|
5
|
+
const { Events } = require('../../const/channel');
|
|
6
|
+
const { validValue } = require('../../utils/helper');
|
|
7
|
+
const { getConfig } = require('../../config');
|
|
8
8
|
|
|
9
9
|
class ChildPoolJob extends EventEmitter {
|
|
10
10
|
|
|
@@ -21,7 +21,7 @@ class ChildPoolJob extends EventEmitter {
|
|
|
21
21
|
this.max = 6;
|
|
22
22
|
this.strategy = 'polling';
|
|
23
23
|
this.weights = new Array(this.max).fill().map((v, i) => {
|
|
24
|
-
let w =
|
|
24
|
+
let w = validValue(options.weights[i]) ? options.weights[i] : 1
|
|
25
25
|
return w;
|
|
26
26
|
});
|
|
27
27
|
|
|
@@ -31,7 +31,7 @@ class ChildPoolJob extends EventEmitter {
|
|
|
31
31
|
}
|
|
32
32
|
this.LB = new LoadBalancer(lbOpt);
|
|
33
33
|
|
|
34
|
-
const cfg =
|
|
34
|
+
const cfg = getConfig().jobs;
|
|
35
35
|
if (cfg) {
|
|
36
36
|
this.config = cfg;
|
|
37
37
|
}
|
|
@@ -43,10 +43,10 @@ class ChildPoolJob extends EventEmitter {
|
|
|
43
43
|
* 初始化监听
|
|
44
44
|
*/
|
|
45
45
|
_initEvents() {
|
|
46
|
-
this.on(
|
|
46
|
+
this.on(Events.childProcessExit, (data) => {
|
|
47
47
|
this._removeChild(data.pid);
|
|
48
48
|
});
|
|
49
|
-
this.on(
|
|
49
|
+
this.on(Events.childProcessError, (data) => {
|
|
50
50
|
this._removeChild(data.pid);
|
|
51
51
|
});
|
|
52
52
|
}
|
|
@@ -115,7 +115,7 @@ class ChildPoolJob extends EventEmitter {
|
|
|
115
115
|
* 执行一个job文件
|
|
116
116
|
*/
|
|
117
117
|
run(filepath, params = {}) {
|
|
118
|
-
const jobPath =
|
|
118
|
+
const jobPath = getFullpath(filepath);
|
|
119
119
|
const childProcess = this.getChild();
|
|
120
120
|
childProcess.dispatch('run', jobPath, params);
|
|
121
121
|
|
|
@@ -210,4 +210,6 @@ class ChildPoolJob extends EventEmitter {
|
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
module.exports =
|
|
213
|
+
module.exports = {
|
|
214
|
+
ChildPoolJob
|
|
215
|
+
};
|
package/jobs/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
const ChildJob = require('./child');
|
|
2
|
-
const
|
|
3
|
-
const ChildPoolJob = require('./child-pool');
|
|
1
|
+
const { ChildJob } = require('./child');
|
|
2
|
+
const { ChildPoolJob } = require('./child-pool');
|
|
4
3
|
|
|
5
4
|
module.exports = {
|
|
6
5
|
ChildJob,
|
|
7
|
-
RendererJob,
|
|
8
6
|
ChildPoolJob
|
|
9
7
|
};
|
package/loader/index.js
CHANGED
|
@@ -1,162 +1,110 @@
|
|
|
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
|
+
* 加载单个文件(如果是函数,将被执行)
|
|
9
|
+
*
|
|
10
|
+
* @param {String} filepath - fullpath
|
|
11
|
+
* @param {Array} inject - pass rest arguments into the function when invoke
|
|
12
|
+
* @return {Object} exports
|
|
13
|
+
*/
|
|
14
|
+
function loadFile(filepath, ...inject) {
|
|
15
|
+
const isAbsolute = path.isAbsolute(filepath);
|
|
16
|
+
if (!isAbsolute) {
|
|
17
|
+
filepath = path.join(getElectronDir(), filepath);
|
|
18
|
+
}
|
|
8
19
|
|
|
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
|
-
}
|
|
20
|
+
filepath = filepath && resolveModule(filepath);
|
|
21
|
+
if (!fs.existsSync(filepath)) {
|
|
22
|
+
let errorMsg = `[ee-core] [loader/index] loadFile ${filepath} does not exist`;
|
|
23
|
+
throw new Error(errorMsg);
|
|
24
|
+
}
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
let ret = CoreUtils.loadFile(filepath);
|
|
27
|
+
if (is.function(ret) && !is.class(ret) && !CoreUtils.isBytecodeClass(ret)) {
|
|
28
|
+
ret = ret(...inject);
|
|
29
|
+
}
|
|
30
|
+
return ret;
|
|
31
|
+
}
|
|
28
32
|
|
|
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
|
-
}
|
|
33
|
+
// requireFile
|
|
34
|
+
function requireFile(filepath) {
|
|
35
|
+
return CoreUtils.loadFile(filepath);
|
|
36
|
+
}
|
|
48
37
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
let errMsg = `[ee-core] [loader] loadJobFile ${filepath} does not exist`;
|
|
64
|
-
throw new Error(errMsg);
|
|
65
|
-
}
|
|
38
|
+
/**
|
|
39
|
+
* 加载并运行文件
|
|
40
|
+
*
|
|
41
|
+
* @param {String} filepath - fullpath
|
|
42
|
+
* @param {Array} inject - pass rest arguments into the function when invoke
|
|
43
|
+
* @return {Any}
|
|
44
|
+
*/
|
|
45
|
+
function execFile(filepath, ...inject) {
|
|
46
|
+
let ret = CoreUtils.loadFile(filepath);
|
|
47
|
+
if (is.class(ret) || CoreUtils.isBytecodeClass(ret)) {
|
|
48
|
+
ret = new ret(inject);
|
|
49
|
+
} else if (is.function(ret)) {
|
|
50
|
+
ret = ret(inject);
|
|
51
|
+
}
|
|
66
52
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
ret = new ret(inject);
|
|
70
|
-
} else if (is.function(ret)) {
|
|
71
|
-
ret = ret(inject);
|
|
72
|
-
}
|
|
53
|
+
return ret;
|
|
54
|
+
}
|
|
73
55
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
}
|
|
56
|
+
/**
|
|
57
|
+
* 模块的绝对路径
|
|
58
|
+
* @param {String} filepath - fullpath
|
|
59
|
+
*/
|
|
60
|
+
function resolveModule(filepath) {
|
|
61
|
+
let fullpath;
|
|
62
|
+
try {
|
|
63
|
+
fullpath = require.resolve(filepath);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
|
|
66
|
+
// 特殊后缀处理
|
|
67
|
+
if (filepath && (filepath.endsWith('.defalut') || filepath.endsWith('.prod'))) {
|
|
68
|
+
fullpath = filepath + '.jsc';
|
|
69
|
+
} else if (filepath && filepath.endsWith('.js')) {
|
|
70
|
+
fullpath = filepath + 'c';
|
|
99
71
|
}
|
|
100
72
|
|
|
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);
|
|
73
|
+
if (!fs.existsSync(filepath) && !fs.existsSync(fullpath)) {
|
|
74
|
+
let files = { filepath, fullpath }
|
|
75
|
+
console.warn(`[ee-core] [loader] resolveModule unknow filepath: ${files}`)
|
|
76
|
+
return undefined;
|
|
116
77
|
}
|
|
78
|
+
}
|
|
117
79
|
|
|
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
|
-
}
|
|
80
|
+
return fullpath;
|
|
81
|
+
}
|
|
151
82
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
83
|
+
/**
|
|
84
|
+
* 获取electron目录下文件的绝对路径
|
|
85
|
+
* @param {String} filepath - fullpath
|
|
86
|
+
*/
|
|
87
|
+
function getFullpath(filepath) {
|
|
88
|
+
let fullpath;
|
|
89
|
+
const isAbsolute = path.isAbsolute(filepath);
|
|
90
|
+
if (!isAbsolute) {
|
|
91
|
+
filepath = path.join(getElectronDir(), filepath);
|
|
92
|
+
}
|
|
156
93
|
|
|
157
|
-
|
|
94
|
+
fullpath = resolveModule(filepath);
|
|
95
|
+
if (!fs.existsSync(fullpath)) {
|
|
96
|
+
throw new Error(`[ee-core] [loader] getFullpath filepath ${filepath} not exists`);
|
|
158
97
|
}
|
|
159
|
-
|
|
98
|
+
|
|
99
|
+
return fullpath;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
module.exports = {
|
|
103
|
+
loadFile,
|
|
104
|
+
execFile,
|
|
105
|
+
requireFile,
|
|
106
|
+
resolveModule,
|
|
107
|
+
getFullpath,
|
|
160
108
|
}
|
|
161
109
|
|
|
162
110
|
|
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
|
+
};
|