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/electron/index.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const { createElectron } = require("./app");
|
|
4
|
+
const { getMainWindow, setCloseAndQuit, getCloseAndQuit } = require("./window");
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return Window.getMainWindow();
|
|
10
|
-
},
|
|
6
|
+
// load socket server
|
|
7
|
+
function loadElectron() {
|
|
8
|
+
createElectron();
|
|
9
|
+
}
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
module.exports = Electron;
|
|
11
|
+
module.exports = {
|
|
12
|
+
loadElectron,
|
|
13
|
+
getMainWindow,
|
|
14
|
+
setCloseAndQuit,
|
|
15
|
+
getCloseAndQuit
|
|
16
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function getMainWindow(): any;
|
|
2
|
+
export declare function createMainWindow(): any;
|
|
3
|
+
export declare function restoreMainWindow(): void;
|
|
4
|
+
export declare function setCloseAndQuit(flag: any): void;
|
|
5
|
+
export declare function getCloseAndQuit(): boolean;
|
|
6
|
+
export declare function loadServer(): Promise<void>;
|
package/electron/window/index.js
CHANGED
|
@@ -1,74 +1,269 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const debug = require('debug')('ee-core:electron:window');
|
|
1
4
|
const is = require('is-type-of');
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const axios = require('axios');
|
|
7
|
+
const { BrowserWindow } = require('electron');
|
|
8
|
+
const { getConfig } = require('../../config');
|
|
9
|
+
const { eventBus, WindowReady } = require('../../app/events');
|
|
10
|
+
const { env, isDev, getBaseDir } = require('../../ps');
|
|
11
|
+
const { loadFile } = require('../../loader');
|
|
12
|
+
const { isFileProtocol } = require('../../utils');
|
|
13
|
+
const { getHtmlFilepath } = require('../../html');
|
|
14
|
+
const { fileIsExist, sleep } = require('../../utils/helper');
|
|
15
|
+
const { coreLogger } = require('../../log');
|
|
16
|
+
const { extend } = require('../../utils/extend');
|
|
17
|
+
const { cross } = require('../../cross');
|
|
18
|
+
|
|
19
|
+
const Instance = {
|
|
20
|
+
mainWindow: null,
|
|
21
|
+
closeAndQuit: true,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// getMainWindow
|
|
25
|
+
function getMainWindow() {
|
|
26
|
+
return Instance.mainWindow;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Create the main application window
|
|
30
|
+
function createMainWindow() {
|
|
31
|
+
const { openDevTools, windowsOption } = getConfig();
|
|
32
|
+
const win = new BrowserWindow(windowsOption);
|
|
33
|
+
Instance.mainWindow = win;
|
|
16
34
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
this[EEMainWindow] = win;
|
|
36
|
-
|
|
37
|
-
// 菜单显示/隐藏
|
|
38
|
-
if (config.openAppMenu === 'dev-show' && Ps.isProd()) {
|
|
39
|
-
Menu.setApplicationMenu(null);
|
|
40
|
-
} else if (config.openAppMenu === false) {
|
|
41
|
-
Menu.setApplicationMenu(null);
|
|
42
|
-
} else {
|
|
43
|
-
// nothing
|
|
35
|
+
// DevTools
|
|
36
|
+
if (is.object(openDevTools)) {
|
|
37
|
+
win.webContents.openDevTools(openDevTools);
|
|
38
|
+
} else if (openDevTools === true) {
|
|
39
|
+
win.webContents.openDevTools({
|
|
40
|
+
mode: 'bottom'
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
eventBus.emitLifecycle(WindowReady);
|
|
45
|
+
return win;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// restored window
|
|
49
|
+
function restoreMainWindow() {
|
|
50
|
+
if (Instance.mainWindow) {
|
|
51
|
+
if (Instance.mainWindow.isMinimized()) {
|
|
52
|
+
Instance.mainWindow.restore();
|
|
44
53
|
}
|
|
54
|
+
Instance.mainWindow.show();
|
|
55
|
+
Instance.mainWindow.focus();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
45
58
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
// Set the flag for exiting after close all windows
|
|
60
|
+
function setCloseAndQuit(flag) {
|
|
61
|
+
Instance.closeAndQuit = flag;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getCloseAndQuit() {
|
|
65
|
+
return Instance.closeAndQuit;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// load server
|
|
69
|
+
// type: remote | single
|
|
70
|
+
async function loadServer() {
|
|
71
|
+
let type = 'spa';
|
|
72
|
+
let url = '';
|
|
73
|
+
const { remote, mainServer } = getConfig();
|
|
74
|
+
const win = getMainWindow();
|
|
75
|
+
|
|
76
|
+
// remote model
|
|
77
|
+
if (remote.enable == true) {
|
|
78
|
+
type = 'remote';
|
|
79
|
+
url = remote.url;
|
|
80
|
+
loadMainUrl(type, url);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 开发环境
|
|
85
|
+
if (isDev()) {
|
|
86
|
+
let url;
|
|
87
|
+
let load = 'url';
|
|
88
|
+
|
|
89
|
+
const binFile = path.join(getBaseDir(), "./cmd/bin.js");
|
|
90
|
+
const binConfig = loadFile(binFile);
|
|
91
|
+
const { dev } = binConfig;
|
|
92
|
+
// tips: match with ee-bin
|
|
93
|
+
const frontendConf = extend(true, {
|
|
94
|
+
protocol: 'http://',
|
|
95
|
+
hostname: 'localhost',
|
|
96
|
+
port: 8080,
|
|
97
|
+
indexPath: 'index.html',
|
|
98
|
+
}, dev.frontend);
|
|
99
|
+
const electronConf = extend(true, {
|
|
100
|
+
loadingPage: '/public/html/loading.html',
|
|
101
|
+
}, dev.electron);
|
|
102
|
+
|
|
103
|
+
url = frontendConf.protocol + frontendConf.hostname + ':' + frontendConf.port;
|
|
104
|
+
if (isFileProtocol(frontendConf.protocol)) {
|
|
105
|
+
url = path.join(getBaseDir(), frontendConf.directory, frontendConf.indexPath);
|
|
106
|
+
load = 'file';
|
|
55
107
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
108
|
+
|
|
109
|
+
// Check if UI serve is started, load a boot page first
|
|
110
|
+
if (load == 'url') {
|
|
111
|
+
// loading page
|
|
112
|
+
let lp = getHtmlFilepath('boot.html');
|
|
113
|
+
if (electronConf.hasOwnProperty('loadingPage') && electronConf.loadingPage != '') {
|
|
114
|
+
lp = path.join(getBaseDir(), electronConf.loadingPage);
|
|
115
|
+
}
|
|
116
|
+
_loadingPage(lp);
|
|
117
|
+
|
|
118
|
+
// check frontend is ready
|
|
119
|
+
const retryTimes = frontendConf.force === true ? 3 : 60;
|
|
120
|
+
let count = 0;
|
|
121
|
+
let frontendReady = false;
|
|
122
|
+
while(!frontendReady && count < retryTimes){
|
|
123
|
+
await sleep(1 * 1000);
|
|
124
|
+
try {
|
|
125
|
+
await axios({
|
|
126
|
+
method: 'get',
|
|
127
|
+
url,
|
|
128
|
+
timeout: 1000,
|
|
129
|
+
proxy: false,
|
|
130
|
+
headers: {
|
|
131
|
+
'Accept': 'text/html, application/json, text/plain, */*',
|
|
132
|
+
},
|
|
133
|
+
//responseType: 'text',
|
|
134
|
+
});
|
|
135
|
+
frontendReady = true;
|
|
136
|
+
} catch(err) {
|
|
137
|
+
// console.warn(err.stack)
|
|
138
|
+
}
|
|
139
|
+
count++;
|
|
140
|
+
}
|
|
141
|
+
debug('it takes %d seconds to start the frontend', count);
|
|
142
|
+
|
|
143
|
+
if (frontendReady == false && frontendConf.force !== true) {
|
|
144
|
+
const bootFailurePage = getHtmlFilepath('failure.html');
|
|
145
|
+
win.loadFile(bootFailurePage);
|
|
146
|
+
coreLogger.error(`[ee-core] Please check the ${url} !`);
|
|
147
|
+
return;
|
|
67
148
|
}
|
|
68
|
-
this[EEMainWindow].show();
|
|
69
|
-
this[EEMainWindow].focus();
|
|
70
149
|
}
|
|
150
|
+
|
|
151
|
+
loadMainUrl(type, url, load);
|
|
152
|
+
return;
|
|
71
153
|
}
|
|
72
|
-
};
|
|
73
154
|
|
|
74
|
-
|
|
155
|
+
// 生产环境
|
|
156
|
+
// cross takeover web
|
|
157
|
+
if (mainServer.takeover.length > 0) {
|
|
158
|
+
await crossTakeover()
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// 主进程
|
|
163
|
+
url = path.join(getBaseDir(), mainServer.indexPath);
|
|
164
|
+
loadMainUrl(type, url, 'file');
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* 主服务
|
|
169
|
+
* @params load <string> value: "url" 、 "file"
|
|
170
|
+
*/
|
|
171
|
+
function loadMainUrl(type, url, load = 'url') {
|
|
172
|
+
const { mainServer } = getConfig();
|
|
173
|
+
const mainWindow = getMainWindow();
|
|
174
|
+
coreLogger.info('[ee-core] Env: %s, Type: %s', env(), type);
|
|
175
|
+
coreLogger.info('[ee-core] App running at: %s', url);
|
|
176
|
+
if (load == 'file') {
|
|
177
|
+
mainWindow.loadFile(url, mainServer.options)
|
|
178
|
+
.then()
|
|
179
|
+
.catch((err)=>{
|
|
180
|
+
coreLogger.error(`[ee-core] Please check the ${url} !`);
|
|
181
|
+
});
|
|
182
|
+
} else {
|
|
183
|
+
mainWindow.loadURL(url, mainServer.options)
|
|
184
|
+
.then()
|
|
185
|
+
.catch((err)=>{
|
|
186
|
+
coreLogger.error(`[ee-core] Please check the ${url} !`);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// loading page
|
|
192
|
+
function _loadingPage(name) {
|
|
193
|
+
if (!fileIsExist(name)) {
|
|
194
|
+
return
|
|
195
|
+
}
|
|
196
|
+
const win = getMainWindow();
|
|
197
|
+
win.loadFile(name);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* cross takeover web
|
|
202
|
+
*/
|
|
203
|
+
async function crossTakeover() {
|
|
204
|
+
const crossConf = getConfig().cross;
|
|
205
|
+
const mainConf = getConfig().mainServer;
|
|
206
|
+
|
|
207
|
+
// loading page
|
|
208
|
+
if (mainConf.loadingPage.length > 0) {
|
|
209
|
+
const lp = path.join(getBaseDir, mainConf.loadingPage);
|
|
210
|
+
_loadingPage(lp);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// cross service url
|
|
214
|
+
const service = mainConf.takeover;
|
|
215
|
+
if (!crossConf.hasOwnProperty(service)) {
|
|
216
|
+
throw new Error(`[ee-core] Please Check the value of mainServer.takeover in the config file !`);
|
|
217
|
+
}
|
|
218
|
+
// check service
|
|
219
|
+
if (crossConf[service].enable != true) {
|
|
220
|
+
throw new Error(`[ee-core] Please Check the value of cross.${service} enable is true !`);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const entityName = crossConf[service].name;
|
|
224
|
+
const url = cross.getUrl(entityName);
|
|
225
|
+
|
|
226
|
+
// 循环检查
|
|
227
|
+
let count = 0;
|
|
228
|
+
let serviceReady = false;
|
|
229
|
+
const times = isDev() ? 20 : 100;
|
|
230
|
+
const sleeptime = isDev() ? 1000 : 200;
|
|
231
|
+
while(!serviceReady && count < times){
|
|
232
|
+
await sleep(sleeptime);
|
|
233
|
+
try {
|
|
234
|
+
await axios({
|
|
235
|
+
method: 'get',
|
|
236
|
+
url,
|
|
237
|
+
timeout: 100,
|
|
238
|
+
proxy: false,
|
|
239
|
+
headers: {
|
|
240
|
+
'Accept': 'text/html, application/json, text/plain, */*',
|
|
241
|
+
},
|
|
242
|
+
});
|
|
243
|
+
serviceReady = true;
|
|
244
|
+
} catch(err) {
|
|
245
|
+
// console.warn(err.stack)
|
|
246
|
+
}
|
|
247
|
+
count++;
|
|
248
|
+
}
|
|
249
|
+
debug('it takes %d seconds to start the cross serivce', count * sleeptime);
|
|
250
|
+
|
|
251
|
+
if (serviceReady == false) {
|
|
252
|
+
const bootFailurePage = getHtmlFilepath('cross-failure.html');
|
|
253
|
+
const mainWindow = getMainWindow();
|
|
254
|
+
mainWindow.loadFile(bootFailurePage);
|
|
255
|
+
throw new Error(`[ee-core] Please check cross service [${service}] ${url} !`)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
coreLogger.info(`[ee-core] cross service [${service}] is started successfully`);
|
|
259
|
+
loadMainUrl('spa', url);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
module.exports = {
|
|
263
|
+
getMainWindow,
|
|
264
|
+
createMainWindow,
|
|
265
|
+
restoreMainWindow,
|
|
266
|
+
setCloseAndQuit,
|
|
267
|
+
getCloseAndQuit,
|
|
268
|
+
loadServer
|
|
269
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Capture exceptions
|
|
2
|
+
export declare function loadException(): void;
|
|
3
|
+
// When an exception is thrown on a process without being caught, trigger the event and silence the exception
|
|
4
|
+
export declare function uncaughtExceptionHandler(): void;
|
|
5
|
+
// When the reject exception in the promise is not caught using catch in the synchronization task, it will trigger the event,
|
|
6
|
+
// Even if catch is used in asynchronous situations, it will trigger the event
|
|
7
|
+
export declare function unhandledRejectionHandler(): void;
|
|
8
|
+
// This event is triggered when an exception is thrown on the process without being caught.
|
|
9
|
+
export declare function uncaughtExceptionMonitorHandler(): void;
|
package/exception/index.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
const Ps = require('../ps');
|
|
3
|
-
const Conf = require('../config/cache');
|
|
4
|
-
const Message = require('../message');
|
|
1
|
+
'use strict';
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
const { coreLogger } = require('../log');
|
|
4
|
+
const { isForkedChild, isRenderer, isDev, isMain } = require('../ps');
|
|
5
|
+
const { getConfig } = require('../config');
|
|
6
|
+
const { childMessage } = require('../message');
|
|
7
|
+
|
|
8
|
+
// 捕获异常
|
|
9
|
+
function loadException() {
|
|
10
|
+
uncaughtExceptionHandler();
|
|
11
|
+
unhandledRejectionHandler();
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*/
|
|
17
|
-
exports.uncaughtExceptionHandler = function() {
|
|
14
|
+
// 当进程上抛出异常而没有被捕获时触发该事件,并且使异常静默。
|
|
15
|
+
function uncaughtExceptionHandler() {
|
|
18
16
|
process.on('uncaughtException', function(err) {
|
|
19
17
|
if (!(err instanceof Error)) {
|
|
20
18
|
err = new Error(String(err));
|
|
@@ -24,7 +22,7 @@ exports.uncaughtExceptionHandler = function() {
|
|
|
24
22
|
err.name = 'unhandledExceptionError';
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
coreLogger.error(err);
|
|
28
26
|
|
|
29
27
|
_devError(err);
|
|
30
28
|
|
|
@@ -32,24 +30,19 @@ exports.uncaughtExceptionHandler = function() {
|
|
|
32
30
|
});
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// Log.coreLogger.error('uncaughtExceptionMonitor:',err);
|
|
45
|
-
// });
|
|
33
|
+
// 当进程上抛出异常而没有被捕获时触发该事件。
|
|
34
|
+
function uncaughtExceptionMonitorHandler() {
|
|
35
|
+
process.on('uncaughtExceptionMonitor', function(err, origin) {
|
|
36
|
+
if (!(err instanceof Error)) {
|
|
37
|
+
err = new Error(String(err));
|
|
38
|
+
}
|
|
39
|
+
coreLogger.error('uncaughtExceptionMonitor:',err);
|
|
40
|
+
});
|
|
46
41
|
}
|
|
47
42
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*/
|
|
52
|
-
exports.unhandledRejectionHandler = function() {
|
|
43
|
+
// 当promise中reject的异常在同步任务中没有使用catch捕获就会触发该事件,
|
|
44
|
+
// 即便是在异步情况下使用了catch也会触发该事件
|
|
45
|
+
function unhandledRejectionHandler() {
|
|
53
46
|
process.on('unhandledRejection', function(err) {
|
|
54
47
|
if (!(err instanceof Error)) {
|
|
55
48
|
const newError = new Error(String(err));
|
|
@@ -64,50 +57,45 @@ exports.unhandledRejectionHandler = function() {
|
|
|
64
57
|
if (err.name === 'Error') {
|
|
65
58
|
err.name = 'unhandledRejectionError';
|
|
66
59
|
}
|
|
67
|
-
|
|
68
|
-
Log.coreLogger.error(err);
|
|
69
|
-
|
|
60
|
+
coreLogger.error(err);
|
|
70
61
|
_devError(err);
|
|
71
|
-
|
|
72
62
|
_exit();
|
|
73
63
|
});
|
|
74
64
|
}
|
|
75
65
|
|
|
76
|
-
|
|
77
|
-
* 如果是子进程,发送错误到主进程控制台
|
|
78
|
-
*/
|
|
66
|
+
// 如果是子进程,发送错误到主进程控制台
|
|
79
67
|
function _devError (err) {
|
|
80
|
-
if (
|
|
81
|
-
|
|
68
|
+
if (isForkedChild() && isDev()) {
|
|
69
|
+
childMessage.sendErrorToTerminal(err);
|
|
82
70
|
}
|
|
83
71
|
}
|
|
84
72
|
|
|
85
|
-
|
|
86
|
-
* 捕获异常后是否退出
|
|
87
|
-
*/
|
|
73
|
+
// 捕获异常后是否退出
|
|
88
74
|
function _exit () {
|
|
89
|
-
|
|
90
|
-
if (!cfg) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
75
|
+
const { mainExit, childExit, rendererExit } = getConfig().exception;
|
|
93
76
|
|
|
94
|
-
if (
|
|
77
|
+
if (isMain() && mainExit == true) {
|
|
95
78
|
_delayExit();
|
|
96
|
-
} else if (
|
|
79
|
+
} else if (isForkedChild() && childExit == true) {
|
|
97
80
|
_delayExit();
|
|
98
|
-
} else if (
|
|
81
|
+
} else if (isRenderer() && rendererExit == true) {
|
|
99
82
|
_delayExit();
|
|
100
83
|
} else {
|
|
101
84
|
// other
|
|
102
85
|
}
|
|
103
86
|
}
|
|
104
87
|
|
|
105
|
-
|
|
106
|
-
* 捕获异常后是否退出
|
|
107
|
-
*/
|
|
88
|
+
// 捕获异常后是否退出
|
|
108
89
|
function _delayExit() {
|
|
109
90
|
// 等待日志等异步写入完成
|
|
110
91
|
setTimeout(() => {
|
|
111
92
|
process.exit();
|
|
112
93
|
}, 1500)
|
|
113
|
-
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
module.exports = {
|
|
97
|
+
loadException,
|
|
98
|
+
uncaughtExceptionHandler,
|
|
99
|
+
unhandledRejectionHandler,
|
|
100
|
+
uncaughtExceptionMonitorHandler
|
|
101
|
+
};
|
package/html/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getHtmlFilepath(name: string): string;
|
package/html/index.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
getFilepath(name){
|
|
8
|
-
const pagePath = path.join(__dirname, name);
|
|
9
|
-
return pagePath;
|
|
10
|
-
},
|
|
11
|
-
|
|
3
|
+
// Html
|
|
4
|
+
function getHtmlFilepath(name){
|
|
5
|
+
const pagePath = path.join(__dirname, name);
|
|
6
|
+
return pagePath;
|
|
12
7
|
}
|
|
13
8
|
|
|
14
|
-
module.exports =
|
|
9
|
+
module.exports = {
|
|
10
|
+
getHtmlFilepath
|
|
11
|
+
};
|
package/index.d.ts
ADDED
package/index.js
CHANGED
|
@@ -1,55 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
* @namespace EeCore
|
|
3
|
-
*/
|
|
1
|
+
'use strict';
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
* @member {ElectronEgg} EeCore#Index
|
|
7
|
-
* @since 1.0.0
|
|
8
|
-
*/
|
|
9
|
-
const ElectronEgg = require('./main');
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @member {app} EeCore#app
|
|
13
|
-
* @since 1.0.0
|
|
14
|
-
*/
|
|
15
|
-
const EE = require('./ee');
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @member {Controller} EeCore#Controller
|
|
19
|
-
* @since 1.0.0
|
|
20
|
-
*/
|
|
21
|
-
const Controller = require('./controller/baseContextClass');
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @member {Service} EeCore#Service
|
|
25
|
-
* @since 1.0.0
|
|
26
|
-
*/
|
|
27
|
-
const Service = require('./services/baseContextClass');
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @member {Storage}
|
|
31
|
-
* @since 1.0.0
|
|
32
|
-
*/
|
|
33
|
-
const Storage = require('./storage');
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @member {Utils}
|
|
37
|
-
* @since 1.0.0
|
|
38
|
-
*/
|
|
39
|
-
const Utils = require('./old-utils');
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @member {Socket}
|
|
43
|
-
* @since 1.0.0
|
|
44
|
-
*/
|
|
45
|
-
const Socket = require('./socket');
|
|
3
|
+
const { ElectronEgg } = require('./app');
|
|
46
4
|
|
|
47
5
|
module.exports = {
|
|
48
|
-
ElectronEgg
|
|
49
|
-
|
|
50
|
-
Controller,
|
|
51
|
-
Service,
|
|
52
|
-
Storage,
|
|
53
|
-
Socket,
|
|
54
|
-
Utils
|
|
55
|
-
};
|
|
6
|
+
ElectronEgg
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/jobs/child/app.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
const is = require('is-type-of');
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
3
|
+
const { loadException } = require('ee-core/exception');
|
|
4
|
+
const { requireFile } = require('ee-core/loader');
|
|
5
|
+
const { coreLogger } = require('ee-core/log');
|
|
6
|
+
const { isBytecodeClass } = require('ee-core/core/utils');
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
loadException();
|
|
9
9
|
const commands = ['run'];
|
|
10
10
|
|
|
11
11
|
class ChildApp {
|
|
@@ -20,7 +20,7 @@ class ChildApp {
|
|
|
20
20
|
_initEvents() {
|
|
21
21
|
process.on('message', this._handleMessage.bind(this));
|
|
22
22
|
process.once('exit', (code) => {
|
|
23
|
-
|
|
23
|
+
coreLogger.info(`[ee-core] [jobs/child] received a exit from main-process, code:${code}, pid:${process.pid}`);
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -37,7 +37,7 @@ class ChildApp {
|
|
|
37
37
|
break;
|
|
38
38
|
default:
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
coreLogger.info(`[ee-core] [jobs/child] received a message from main-process, message: ${JSON.stringify(m)}`);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
/**
|
|
@@ -45,8 +45,8 @@ class ChildApp {
|
|
|
45
45
|
*/
|
|
46
46
|
run(msg = {}) {
|
|
47
47
|
const {jobPath, jobParams, jobFunc, jobFuncParams} = msg;
|
|
48
|
-
let mod =
|
|
49
|
-
if (is.class(mod) ||
|
|
48
|
+
let mod = requireFile(jobPath);
|
|
49
|
+
if (is.class(mod) || isBytecodeClass(mod)) {
|
|
50
50
|
if (!this.jobMap.has(jobPath)) {
|
|
51
51
|
const instance = new mod(...jobParams);
|
|
52
52
|
instance.handle(...jobParams);
|
|
@@ -58,7 +58,7 @@ class ChildApp {
|
|
|
58
58
|
|
|
59
59
|
} else if (is.function(mod)) {
|
|
60
60
|
mod(jobParams);
|
|
61
|
-
}
|
|
61
|
+
}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|