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.
Files changed (159) hide show
  1. package/app/application.d.ts +5 -0
  2. package/app/application.js +31 -0
  3. package/app/boot.d.ts +5 -0
  4. package/app/boot.js +74 -0
  5. package/app/dir.d.ts +1 -0
  6. package/app/dir.js +27 -0
  7. package/app/events.d.ts +14 -0
  8. package/app/events.js +56 -0
  9. package/app/index.d.ts +2 -0
  10. package/app/index.js +7 -0
  11. package/config/config_loader.d.ts +13 -0
  12. package/config/config_loader.js +19 -23
  13. package/config/default_config.d.ts +95 -0
  14. package/config/default_config.js +111 -0
  15. package/config/index.d.ts +28 -0
  16. package/config/index.js +20 -37
  17. package/const/channel.d.ts +16 -0
  18. package/const/channel.js +26 -16
  19. package/controller/controller_loader.d.ts +9 -0
  20. package/controller/controller_loader.js +78 -0
  21. package/controller/index.d.ts +2 -0
  22. package/controller/index.js +18 -19
  23. package/core/index.d.ts +2 -0
  24. package/core/index.js +6 -5
  25. package/core/loader/file_loader.d.ts +66 -0
  26. package/core/{lib/loader → loader}/file_loader.js +39 -156
  27. package/core/utils/index.d.ts +12 -0
  28. package/core/utils/index.js +83 -0
  29. package/core/utils/timing.d.ts +22 -0
  30. package/core/{lib/utils → utils}/timing.js +3 -2
  31. package/cross/cross.d.ts +19 -0
  32. package/cross/cross.js +152 -0
  33. package/cross/crossProcess.d.ts +29 -0
  34. package/cross/{spawnProcess.js → crossProcess.js} +36 -53
  35. package/cross/index.d.ts +2 -0
  36. package/cross/index.js +6 -181
  37. package/electron/app/index.d.ts +5 -0
  38. package/electron/app/index.js +38 -54
  39. package/electron/index.d.ts +3 -0
  40. package/electron/index.js +13 -17
  41. package/electron/window/index.d.ts +6 -0
  42. package/electron/window/index.js +260 -65
  43. package/exception/index.d.ts +9 -0
  44. package/exception/index.js +42 -54
  45. package/html/index.d.ts +1 -0
  46. package/html/index.js +7 -10
  47. package/index.d.ts +2 -0
  48. package/index.js +4 -52
  49. package/jobs/child/app.d.ts +1 -0
  50. package/jobs/child/app.js +10 -10
  51. package/jobs/child/index.d.ts +13 -0
  52. package/jobs/child/index.js +14 -11
  53. package/jobs/child/jobProcess.d.ts +16 -0
  54. package/jobs/child/{forkProcess.js → jobProcess.js} +31 -62
  55. package/jobs/child-pool/index.d.ts +26 -0
  56. package/jobs/child-pool/index.js +25 -48
  57. package/jobs/index.d.ts +3 -0
  58. package/jobs/index.js +2 -4
  59. package/jobs/load-balancer/algorithm/index.d.ts +4 -0
  60. package/jobs/load-balancer/algorithm/minimumConnection.d.ts +2 -0
  61. package/jobs/load-balancer/algorithm/polling.d.ts +2 -0
  62. package/jobs/load-balancer/algorithm/random.d.ts +2 -0
  63. package/jobs/load-balancer/algorithm/specify.d.ts +2 -0
  64. package/jobs/load-balancer/algorithm/weights.d.ts +2 -0
  65. package/jobs/load-balancer/algorithm/weightsMinimumConnection.d.ts +2 -0
  66. package/jobs/load-balancer/algorithm/weightsPolling.d.ts +2 -0
  67. package/jobs/load-balancer/algorithm/weightsRandom.d.ts +2 -0
  68. package/jobs/load-balancer/consts.d.ts +8 -0
  69. package/jobs/load-balancer/index.d.ts +96 -0
  70. package/jobs/load-balancer/scheduler.d.ts +16 -0
  71. package/loader/index.d.ts +9 -0
  72. package/loader/index.js +73 -143
  73. package/log/index.d.ts +5 -0
  74. package/log/index.js +74 -57
  75. package/log/logger.d.ts +2 -0
  76. package/log/logger.js +75 -80
  77. package/message/childMessage.d.ts +10 -0
  78. package/message/childMessage.js +15 -25
  79. package/message/index.d.ts +3 -0
  80. package/message/index.js +7 -16
  81. package/package.json +8 -2
  82. package/ps/index.d.ts +37 -0
  83. package/ps/index.js +135 -238
  84. package/socket/httpServer.d.ts +8 -0
  85. package/socket/httpServer.js +55 -45
  86. package/socket/index.d.ts +10 -0
  87. package/socket/index.js +52 -69
  88. package/socket/ipcServer.d.ts +9 -0
  89. package/socket/ipcServer.js +87 -94
  90. package/socket/socketServer.d.ts +10 -0
  91. package/socket/socketServer.js +37 -25
  92. package/storage/index.d.ts +5 -0
  93. package/storage/index.js +5 -37
  94. package/storage/sqliteStorage.d.ts +16 -0
  95. package/storage/sqliteStorage.js +20 -20
  96. package/tsconfig.json +14 -0
  97. package/utils/extend.d.ts +2 -0
  98. package/utils/extend.js +10 -5
  99. package/utils/helper.d.ts +14 -0
  100. package/utils/helper.js +39 -53
  101. package/utils/index.d.ts +10 -0
  102. package/utils/index.js +47 -40
  103. package/utils/ip.d.ts +2 -0
  104. package/utils/ip.js +5 -45
  105. package/utils/is.d.ts +14 -0
  106. package/utils/is.js +107 -141
  107. package/utils/json.d.ts +5 -0
  108. package/utils/json.js +15 -7
  109. package/utils/pargv.d.ts +3 -0
  110. package/utils/pargv.js +5 -1
  111. package/utils/port/index.d.ts +1 -0
  112. package/utils/{get-port → port}/index.js +4 -26
  113. package/utils/wrap.d.ts +4 -0
  114. package/utils/wrap.js +8 -3
  115. package/addon/index.js +0 -35
  116. package/addon/window/index.js +0 -99
  117. package/bin/tools.js +0 -8
  118. package/config/cache.js +0 -62
  119. package/config/config.default.js +0 -331
  120. package/const/index.js +0 -9
  121. package/controller/baseContextClass.js +0 -25
  122. package/core/lib/ee.js +0 -216
  123. package/core/lib/loader/context_loader.js +0 -106
  124. package/core/lib/loader/ee_loader.js +0 -435
  125. package/core/lib/loader/mixin/addon.js +0 -32
  126. package/core/lib/loader/mixin/config.js +0 -130
  127. package/core/lib/loader/mixin/controller.js +0 -125
  128. package/core/lib/loader/mixin/service.js +0 -28
  129. package/core/lib/utils/base_context_class.js +0 -34
  130. package/core/lib/utils/function.js +0 -30
  131. package/core/lib/utils/index.js +0 -133
  132. package/core/lib/utils/sequencify.js +0 -59
  133. package/ee/appLoader.js +0 -48
  134. package/ee/application.js +0 -101
  135. package/ee/baseApp.js +0 -99
  136. package/ee/eeApp.js +0 -406
  137. package/ee/index.js +0 -58
  138. package/electron/window/winState.js +0 -186
  139. package/httpclient/index.js +0 -161
  140. package/jobs/baseJobClass.js +0 -16
  141. package/jobs/renderer/index.js +0 -141
  142. package/jobs/renderer/loadView.js +0 -41
  143. package/jobs/unification.js +0 -64
  144. package/main/index.js +0 -57
  145. package/old-utils/index.js +0 -91
  146. package/services/baseContextClass.js +0 -24
  147. package/services/index.js +0 -41
  148. package/socket/io.js +0 -28
  149. package/storage/jsondb/adapters/Base.js +0 -23
  150. package/storage/jsondb/adapters/FileSync.js +0 -64
  151. package/storage/jsondb/main.js +0 -55
  152. package/storage/jsondbStorage.js +0 -196
  153. package/utils/co.js +0 -237
  154. package/utils/copyto.js +0 -161
  155. package/utils/depd/index.js +0 -538
  156. package/utils/depd/lib/browser/index.js +0 -77
  157. package/utils/get-port/index.d.ts +0 -64
  158. package/utils/time/index.js +0 -20
  159. package/utils/time/ms.js +0 -162
@@ -0,0 +1,3 @@
1
+ import { getMainWindow, setCloseAndQuit, getCloseAndQuit } from "./window";
2
+ export declare function loadElectron(): void;
3
+ export { getMainWindow, setCloseAndQuit, getCloseAndQuit };
package/electron/index.js CHANGED
@@ -1,20 +1,16 @@
1
- const Window = require('./window');
1
+ 'use strict';
2
2
 
3
- const Electron = {
3
+ const { createElectron } = require("./app");
4
+ const { getMainWindow, setCloseAndQuit, getCloseAndQuit } = require("./window");
4
5
 
5
- /**
6
- * 兼容1.x版本api
7
- */
8
- get mainWindow() {
9
- return Window.getMainWindow();
10
- },
6
+ // load socket server
7
+ function loadElectron() {
8
+ createElectron();
9
+ }
11
10
 
12
- /**
13
- * extra
14
- */
15
- extra: {
16
- closeWindow: false,
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>;
@@ -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 { BrowserWindow, Menu } = require('electron');
3
- const Conf = require('../../config/cache');
4
- const Ps = require('../../ps');
5
- const EEMainWindow = Symbol('Ee#electron#mainWindow');
6
-
7
- const Window = {
8
-
9
- /**
10
- * 获取 mainWindow
11
- */
12
- getMainWindow() {
13
- if (!this[EEMainWindow]) {
14
- this[EEMainWindow] = this.createMainWindow();
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
- return this[EEMainWindow] || null;
18
- },
19
-
20
- /**
21
- * 创建应用主窗口
22
- */
23
- createMainWindow() {
24
-
25
- // todo
26
- // const protocolName = 'eefile';
27
- // protocol.registerFileProtocol(protocolName, (request, callback) => {
28
- // const url = request.url.substring(protocolName.length + 3);
29
- // console.log('[ee-core] [lib/eeApp] registerFileProtocol ----url: ', url);
30
- // callback({ path: path.normalize(decodeURIComponent(url)) })
31
- // });
32
-
33
- const config = Conf.all();
34
- const win = new BrowserWindow(config.windowsOption);
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
- // DevTools
47
- if (is.object(config.openDevTools)) {
48
- win.webContents.openDevTools(config.openDevTools);
49
- } else if (config.openDevTools === true) {
50
- win.webContents.openDevTools({
51
- mode: 'undocked'
52
- });
53
- } else {
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
- return win;
58
- },
59
-
60
- /**
61
- * 还原窗口
62
- */
63
- restoreMainWindow() {
64
- if (this[EEMainWindow]) {
65
- if (this[EEMainWindow].isMinimized()) {
66
- this[EEMainWindow].restore();
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
- module.exports = Window;
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;
@@ -1,20 +1,18 @@
1
- const Log = require('../log');
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
- exports.start = function() {
10
- this.uncaughtExceptionHandler();
11
- this.unhandledRejectionHandler();
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
- Log.coreLogger.error(err);
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
- exports.uncaughtExceptionMonitorHandler = function() {
39
- // process.on('uncaughtExceptionMonitor', function(err, origin) {
40
- // if (!(err instanceof Error)) {
41
- // err = new Error(String(err));
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
- * 当promise中reject的异常在同步任务中没有使用catch捕获就会触发该事件,
50
- * 即便是在异步情况下使用了catch也会触发该事件
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 (Ps.isForkedChild() && Ps.isDev()) {
81
- Message.childMessage.sendErrorToTerminal(err);
68
+ if (isForkedChild() && isDev()) {
69
+ childMessage.sendErrorToTerminal(err);
82
70
  }
83
71
  }
84
72
 
85
- /**
86
- * 捕获异常后是否退出
87
- */
73
+ // 捕获异常后是否退出
88
74
  function _exit () {
89
- let cfg = Conf.getValue('exception');
90
- if (!cfg) {
91
- return;
92
- }
75
+ const { mainExit, childExit, rendererExit } = getConfig().exception;
93
76
 
94
- if (Ps.isMain() && cfg.mainExit == true) {
77
+ if (isMain() && mainExit == true) {
95
78
  _delayExit();
96
- } else if (Ps.isForkedChild() && cfg.childExit == true) {
79
+ } else if (isForkedChild() && childExit == true) {
97
80
  _delayExit();
98
- } else if (Ps.isRenderer() && cfg.rendererExit == true) {
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
+ };
@@ -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
- * Html
5
- */
6
- const Html = {
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 = Html;
9
+ module.exports = {
10
+ getHtmlFilepath
11
+ };
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { ElectronEgg };
2
+ import { ElectronEgg } from "./app";
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
- Application: EE.Application,
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 Exception = require('ee-core/exception');
4
- const Loader = require('ee-core/loader');
5
- const Log = require('ee-core/log');
6
- const UtilsCore = require('ee-core/core/lib/utils');
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
- Exception.start();
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
- Log.coreLogger.info(`[ee-core] [jobs/child] received a exit from main-process, code:${code}, pid:${process.pid}`);
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
- Log.coreLogger.info(`[ee-core] [jobs/child] received a message from main-process, message: ${JSON.stringify(m)}`);
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 = Loader.loadJsFile(jobPath);
49
- if (is.class(mod) || UtilsCore.isBytecodeClass(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