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.
Files changed (96) hide show
  1. package/app/application.js +31 -0
  2. package/app/boot.js +81 -0
  3. package/app/dir.js +27 -0
  4. package/app/events.js +56 -0
  5. package/app/index.js +7 -0
  6. package/config/config_loader.js +19 -23
  7. package/config/default_config.js +110 -0
  8. package/config/index.js +20 -37
  9. package/const/channel.js +26 -16
  10. package/const/index.js +0 -4
  11. package/controller/controller_loader.js +78 -0
  12. package/controller/index.js +18 -19
  13. package/core/index.js +6 -5
  14. package/core/{lib/loader → loader}/file_loader.js +39 -156
  15. package/core/utils/index.js +83 -0
  16. package/core/{lib/utils → utils}/timing.js +3 -2
  17. package/cross/cross.js +152 -0
  18. package/cross/index.js +6 -181
  19. package/cross/spawnProcess.js +34 -51
  20. package/electron/app/index.js +38 -54
  21. package/electron/index.js +13 -17
  22. package/electron/window/index.js +260 -65
  23. package/exception/index.js +34 -32
  24. package/html/index.js +7 -10
  25. package/index.js +4 -52
  26. package/jobs/child/app.js +10 -10
  27. package/jobs/child/forkProcess.js +29 -45
  28. package/jobs/child/index.js +13 -10
  29. package/jobs/child-pool/index.js +13 -11
  30. package/jobs/index.js +2 -4
  31. package/loader/index.js +91 -143
  32. package/log/index.js +74 -57
  33. package/log/logger.js +75 -80
  34. package/message/childMessage.js +13 -13
  35. package/message/index.js +7 -16
  36. package/package.json +2 -2
  37. package/ps/index.js +136 -229
  38. package/socket/httpServer.js +46 -43
  39. package/socket/index.js +52 -69
  40. package/socket/ipcServer.js +80 -94
  41. package/socket/socketServer.js +31 -24
  42. package/storage/index.js +5 -37
  43. package/storage/sqliteStorage.js +18 -18
  44. package/utils/extend.js +10 -5
  45. package/utils/helper.js +38 -42
  46. package/utils/index.js +40 -23
  47. package/utils/ip.js +5 -45
  48. package/utils/is.js +107 -141
  49. package/utils/json.js +15 -7
  50. package/utils/pargv.js +5 -1
  51. package/utils/{get-port → port}/index.js +4 -26
  52. package/utils/wrap.js +8 -3
  53. package/addon/index.js +0 -35
  54. package/addon/window/index.js +0 -99
  55. package/bin/tools.js +0 -8
  56. package/config/cache.js +0 -62
  57. package/config/config.default.js +0 -331
  58. package/controller/baseContextClass.js +0 -25
  59. package/core/lib/ee.js +0 -216
  60. package/core/lib/loader/context_loader.js +0 -106
  61. package/core/lib/loader/ee_loader.js +0 -435
  62. package/core/lib/loader/mixin/addon.js +0 -32
  63. package/core/lib/loader/mixin/config.js +0 -130
  64. package/core/lib/loader/mixin/controller.js +0 -125
  65. package/core/lib/loader/mixin/service.js +0 -28
  66. package/core/lib/utils/base_context_class.js +0 -34
  67. package/core/lib/utils/function.js +0 -30
  68. package/core/lib/utils/index.js +0 -133
  69. package/core/lib/utils/sequencify.js +0 -59
  70. package/ee/appLoader.js +0 -48
  71. package/ee/application.js +0 -101
  72. package/ee/baseApp.js +0 -99
  73. package/ee/eeApp.js +0 -406
  74. package/ee/index.js +0 -58
  75. package/electron/window/winState.js +0 -186
  76. package/httpclient/index.js +0 -161
  77. package/jobs/baseJobClass.js +0 -16
  78. package/jobs/renderer/index.js +0 -141
  79. package/jobs/renderer/loadView.js +0 -41
  80. package/jobs/unification.js +0 -64
  81. package/main/index.js +0 -57
  82. package/old-utils/index.js +0 -91
  83. package/services/baseContextClass.js +0 -24
  84. package/services/index.js +0 -41
  85. package/socket/io.js +0 -28
  86. package/storage/jsondb/adapters/Base.js +0 -23
  87. package/storage/jsondb/adapters/FileSync.js +0 -64
  88. package/storage/jsondb/main.js +0 -55
  89. package/storage/jsondbStorage.js +0 -196
  90. package/utils/co.js +0 -237
  91. package/utils/copyto.js +0 -161
  92. package/utils/depd/index.js +0 -538
  93. package/utils/depd/lib/browser/index.js +0 -77
  94. package/utils/get-port/index.d.ts +0 -64
  95. package/utils/time/index.js +0 -20
  96. package/utils/time/ms.js +0 -162
package/cross/index.js CHANGED
@@ -1,183 +1,8 @@
1
- const fs = require('fs');
2
- const EventEmitter = require('events');
3
- const Conf = require('../config/cache');
4
- const Helper = require('../utils/helper');
5
- const Ps = require('../ps');
6
- const SpawnProcess = require('./spawnProcess');
7
- const Channel = require('../const/channel');
8
- const extend = require('../utils/extend');
9
- const GetPort = require('../utils/get-port');
1
+ 'use strict';
10
2
 
11
- /**
12
- * Cross-language service
13
- * 跨语言服务
14
- */
15
- const CrossLanguageService = {
3
+ const { CrossProcess, cross} = require('./cross');
16
4
 
17
- emitter: undefined,
18
-
19
- /**
20
- * pid唯一
21
- * {pid:{name,entity}, pid:{name,entity}, ...}
22
- */
23
- children: {},
24
-
25
- /**
26
- * name唯一
27
- * {name:pid, name:pid, ...}
28
- */
29
- childrenMap: {},
30
-
31
- /**
32
- * create
33
- */
34
- async create() {
35
-
36
- // boot services
37
- const servicesCfg = Conf.getValue('cross');
38
- //await Helper.sleep(5 * 1000);
39
-
40
- for (let key of Object.keys(servicesCfg)) {
41
- let cfg = servicesCfg[key];
42
- if (cfg.enable == true) {
43
- this.run(key)
44
- }
45
- }
46
- },
47
-
48
- /**
49
- * _initEventEmitter
50
- */
51
- _initEventEmitter() {
52
- if (this.emitter) {
53
- return
54
- }
55
- this.emitter = new EventEmitter();
56
- this.emitter.on(Channel.events.childProcessExit, (data) => {
57
- const child = this.children[data.pid];
58
- delete this.childrenMap[child.name];
59
- delete this.children[data.pid];
60
- });
61
- this.emitter.on(Channel.events.childProcessError, (data) => {
62
- const child = this.children[data.pid];
63
- delete this.childrenMap[child.name];
64
- delete this.children[data.pid];
65
- });
66
- },
67
-
68
- /**
69
- * run
70
- */
71
- async run(service, opt = {}) {
72
- // init dir
73
- this._initPath();
74
-
75
- const allConfig = Conf.all();
76
- const defaultOpt = allConfig.cross[service] || {};
77
- const targetConf = extend(true, {}, defaultOpt, opt);
78
- if (Object.keys(targetConf).length == 0) {
79
- throw new Error(`[ee-core] [cross] The service [${service}] config does not exit`);
80
- }
81
-
82
- // eventEmitter
83
- this._initEventEmitter();
84
-
85
- // format params
86
- let tmpArgs = targetConf.args;
87
- let confPort = parseInt(Helper.getValueFromArgv(tmpArgs, 'port'));
88
- // 某些程序给它传入不存在的参数时会报错
89
- if (isNaN(confPort) && targetConf.port > 0) {
90
- confPort = targetConf.port;
91
- }
92
- if (confPort > 0) {
93
- // 动态生成port,传入的端口必须为int
94
- confPort = await GetPort({ port: confPort });
95
- // 替换port
96
- targetConf.args = Helper.replaceArgsValue(tmpArgs, "port", String(confPort));
97
- }
98
-
99
- // 创建进程
100
- const subProcess = new SpawnProcess(this, { targetConf, port: confPort });
101
- let uniqueName = targetConf.name;
102
- if (this.childrenMap.hasOwnProperty(uniqueName)) {
103
- uniqueName = uniqueName + "-" + String(subProcess.pid);
104
- }
105
- this.childrenMap[uniqueName] = subProcess.pid;
106
- subProcess.name = uniqueName;
107
- this.children[subProcess.pid] = {
108
- name: uniqueName,
109
- entity: subProcess
110
- };
111
-
112
- return subProcess;
113
- },
114
-
115
- killAll() {
116
- Object.keys(this.children).forEach(pid => {
117
- this.kill(pid)
118
- });
119
- },
120
-
121
- kill(pid) {
122
- const entity = this.getProc(pid);
123
- if (entity) {
124
- entity.kill();
125
- }
126
- },
127
-
128
- killByName(name) {
129
- const entity = this.getProcByName(name);
130
- if (entity) {
131
- entity.kill();
132
- }
133
- },
134
-
135
- getUrl(name) {
136
- const entity = this.getProcByName(name);
137
- const url = entity.getUrl();
138
-
139
- return url;
140
- },
141
-
142
- // 获取 proc
143
- getProcByName(name) {
144
- const pid = this.childrenMap[name];
145
- if (!pid) {
146
- throw new Error(`[ee-core] [cross] The process named [${name}] does not exit`);
147
- }
148
- const entity = this.getProc(pid);
149
-
150
- return entity;
151
- },
152
-
153
- // 获取 proc
154
- getProc(pid) {
155
- const child = this.children[pid];
156
- if (!pid) {
157
- throw new Error(`[ee-core] [cross] The process pid [${pid}] does not exit`);
158
- }
159
-
160
- return child.entity;
161
- },
162
-
163
- /**
164
- * 获取pids
165
- */
166
- getPids() {
167
- let pids = Object.keys(this.children);
168
- return pids;
169
- },
170
-
171
- /**
172
- * init path
173
- */
174
- _initPath() {
175
- const pathname = Ps.getUserHomeConfigDir();
176
- if (!fs.existsSync(pathname)) {
177
- Helper.mkdir(pathname, {mode: 0o755});
178
- }
179
- },
180
-
181
- }
182
-
183
- module.exports = CrossLanguageService;
5
+ module.exports = {
6
+ CrossProcess,
7
+ cross
8
+ };
@@ -1,13 +1,15 @@
1
+ 'use strict';
2
+
1
3
  const EventEmitter = require('events');
2
4
  const path = require('path');
3
5
  const crossSpawn = require('cross-spawn');
4
- const Log = require('../log');
5
- const Ps = require('../ps');
6
- const Channel = require('../const/channel');
7
- const EE = require('../ee');
8
- const Helper = require('../utils/helper');
9
- const UtilsIs = require('../utils/is');
10
- const UtilsPargv = require('../utils/pargv');
6
+ const { coreLogger } = require('../log');
7
+ const { getExtraResourcesDir, isPackaged, isDev, getBaseDir } = require('../ps');
8
+ const { Events } = require('../const/channel');
9
+ const { getRandomString, getValueFromArgv } = require('../utils/helper');
10
+ const { is } = require('../utils');
11
+ const { parseArgv } = require('../utils/pargv');
12
+ const { app: electronApp } = require('electron');
11
13
 
12
14
  class SpawnProcess {
13
15
  constructor(host, opt = {}) {
@@ -35,9 +37,9 @@ class SpawnProcess {
35
37
  // Launch executable program
36
38
  let cmdPath = '';
37
39
  let cmdArgs = targetConf.args;
38
- let execDir = Ps.getExtraResourcesDir();
40
+ let execDir = getExtraResourcesDir();
39
41
  let standardOutput = ['inherit', 'inherit', 'inherit', 'ipc'];
40
- if (Ps.isPackaged()) {
42
+ if (isPackaged()) {
41
43
  standardOutput = ['ignore', 'ignore', 'ignore', 'ipc'];
42
44
  }
43
45
  if (targetConf.stdio) {
@@ -51,18 +53,18 @@ class SpawnProcess {
51
53
  throw new Error(`[ee-core] [cross] The config [directory] attribute does not exist`);
52
54
  }
53
55
  cmdPath = cmd;
54
- if (!path.isAbsolute(cmd) && !Ps.isDev()) {
55
- cmdPath = path.join(Ps.getExtraResourcesDir(), cmd);
56
+ if (!path.isAbsolute(cmd) && !isDev()) {
57
+ cmdPath = path.join(getExtraResourcesDir(), cmd);
56
58
  }
57
59
  } else {
58
- cmdPath = path.join(Ps.getExtraResourcesDir(), targetConf.name);
60
+ cmdPath = path.join(getExtraResourcesDir(), targetConf.name);
59
61
  }
60
62
 
61
63
  // windows
62
- if (UtilsIs.windows() && path.extname(cmdPath) != '.exe') {
64
+ if (is.windows() && path.extname(cmdPath) != '.exe') {
63
65
  // Complete the executable program extension
64
66
  // notice: python.exe may bring up the App Store
65
- if (targetConf.windowsExtname === true || !Ps.isDev()) {
67
+ if (targetConf.windowsExtname === true || !isDev()) {
66
68
  cmdPath += ".exe";
67
69
  }
68
70
  }
@@ -71,16 +73,16 @@ class SpawnProcess {
71
73
  if (directory && path.isAbsolute(directory)) {
72
74
  execDir = directory;
73
75
  } else if (directory && !path.isAbsolute(directory)) {
74
- if (Ps.isDev()) {
75
- execDir = path.join(Ps.getHomeDir(), directory);
76
+ if (isDev()) {
77
+ execDir = path.join(getBaseDir(), directory);
76
78
  } else {
77
- execDir = path.join(Ps.getExtraResourcesDir(), directory);
79
+ execDir = path.join(getExtraResourcesDir(), directory);
78
80
  }
79
81
  } else {
80
- execDir = Ps.getExtraResourcesDir();
82
+ execDir = getExtraResourcesDir();
81
83
  }
82
84
 
83
- Log.coreLogger.info(`[ee-core] [cross/run] cmd: ${cmdPath}, args: ${cmdArgs}`);
85
+ coreLogger.info(`[ee-core] [cross/run] cmd: ${cmdPath}, args: ${cmdArgs}`);
84
86
  const coreProcess = crossSpawn(cmdPath, cmdArgs, {
85
87
  stdio: standardOutput,
86
88
  detached: false,
@@ -94,9 +96,9 @@ class SpawnProcess {
94
96
  let data = {
95
97
  pid: this.pid
96
98
  }
97
- this.host.emitter.emit(Channel.events.childProcessExit, data);
99
+ this.host.emitter.emit(Events.childProcessExit, data);
98
100
  // Child process closed: The child process was killed externally or an internal error caused the application to stop, resulting in the application exiting
99
- Log.coreLogger.info(`[ee-core] [corss/process] received a exit from child-process, code:${code}, signal:${signal}, pid:${this.pid}, cmd:${cmdPath}, args: ${cmdArgs}`);
101
+ coreLogger.info(`[ee-core] [corss/process] received a exit from child-process, code:${code}, signal:${signal}, pid:${this.pid}, cmd:${cmdPath}, args: ${cmdArgs}`);
100
102
  this._exitElectron();
101
103
  });
102
104
 
@@ -104,8 +106,8 @@ class SpawnProcess {
104
106
  let data = {
105
107
  pid: this.pid
106
108
  }
107
- this.host.emitter.emit(Channel.events.childProcessError, data);
108
- Log.coreLogger.error(`[ee-core] [corss/process] received a error from child-process, error: ${err}, pid:${this.pid}`);
109
+ this.host.emitter.emit(Events.childProcessError, data);
110
+ coreLogger.error(`[ee-core] [corss/process] received a error from child-process, error: ${err}, pid:${this.pid}`);
109
111
  this._exitElectron();
110
112
  });
111
113
  }
@@ -121,29 +123,9 @@ class SpawnProcess {
121
123
  }, timeout)
122
124
  }
123
125
 
124
- // send(message) {
125
- // return this.sendByType(message, 'message');
126
- // }
127
-
128
- // close() {
129
- // return this.sendByType('close', 'close');
130
- // }
131
-
132
- // async sendByType(message, type) {
133
- // const msg = typeof message === 'string' ? message : JSON.stringify(message);
134
- // const id = this._generateId();
135
-
136
- // this.child.send({
137
- // id,
138
- // type,
139
- // data: msg,
140
- // });
141
- // return;
142
- // }
143
-
144
126
  getUrl() {
145
- const ssl = Helper.getValueFromArgv(this.config.args, 'ssl');
146
- let hostname = Helper.getValueFromArgv(this.config.args, 'hostname')
127
+ const ssl = getValueFromArgv(this.config.args, 'ssl');
128
+ let hostname = getValueFromArgv(this.config.args, 'hostname')
147
129
  let protocol = 'http://';
148
130
  if (ssl && (ssl == 'true' || ssl == '1')) {
149
131
  protocol = 'https://';
@@ -155,7 +137,7 @@ class SpawnProcess {
155
137
  }
156
138
 
157
139
  getArgsObj() {
158
- const obj = UtilsPargv(this.config.args);
140
+ const obj = parseArgv(this.config.args);
159
141
  return obj;
160
142
  }
161
143
 
@@ -164,7 +146,7 @@ class SpawnProcess {
164
146
  }
165
147
 
166
148
  _generateId() {
167
- const rid = Helper.getRandomString();
149
+ const rid = getRandomString();
168
150
  return `node:${this.pid}:${rid}`;
169
151
  }
170
152
 
@@ -172,14 +154,15 @@ class SpawnProcess {
172
154
  * exit electron
173
155
  */
174
156
  _exitElectron(timeout = 1000) {
175
- const { CoreApp } = EE;
176
157
  if (this.config.appExit) {
177
158
  setTimeout(() => {
178
- // 进程退出前的一些清理工作
179
- CoreApp.appQuit();
159
+ // 主进程退出
160
+ electronApp.quit();
180
161
  }, timeout)
181
162
  }
182
163
  }
183
164
  }
184
165
 
185
- module.exports = SpawnProcess;
166
+ module.exports = {
167
+ SpawnProcess
168
+ };
@@ -1,64 +1,48 @@
1
- const { app } = require('electron');
2
- const EE = require('../../ee');
3
- const Log = require('../../log');
4
- const Electron = require('../index');
5
- const UtilsIs = require('../../utils/is');
6
- const Cross = require('../../cross');
7
- const Window = require('../window');
1
+ 'use strict';
2
+
3
+ const debug = require('debug')('ee-core:electron:app');
4
+ const { app: electronApp } = require('electron');
5
+ const { coreLogger } = require('../../log');
6
+ const { is } = require('../../utils');
7
+ const { cross } = require('../../cross');
8
+ const { createMainWindow, setCloseAndQuit, loadServer } = require('../window');
9
+ const { eventBus, ElectronAppReady, BeforeClose, Preload } = require('../../app/events');
10
+ const { getConfig } = require('../../config');
8
11
 
9
12
  /**
10
- * CoreElectronApp (框架封装的electron app对象)
13
+ * 创建electron应用
11
14
  */
12
- const CoreElectronApp = {
13
-
14
- /**
15
- * 创建electron应用
16
- */
17
- async create() {
18
- const { CoreApp } = EE;
19
-
20
- const gotTheLock = app.requestSingleInstanceLock();
21
- if (!gotTheLock) {
22
- app.quit();
23
- }
24
-
25
- app.whenReady().then(() => {
26
- CoreApp.createWindow();
27
- })
28
-
29
- // 显示首次打开的窗口
30
- app.on('second-instance', () => {
31
- Log.coreLogger.info('[ee-core] [lib/eeApp] second-instance');
32
- Window.restoreMainWindow();
33
- });
34
-
35
- app.on('window-all-closed', () => {
36
- if (!UtilsIs.macOS()) {
37
- Log.coreLogger.info('[ee-core] [lib/eeApp] window-all-closed quit');
38
- CoreApp.appQuit();
39
- }
40
- })
41
-
42
- app.on('before-quit', () => {
43
- Electron.extra.closeWindow = true;
15
+ function createElectron() {
16
+ const { singleLock } = getConfig();
17
+ // 允许多个实例
18
+ const gotTheLock = electronApp.requestSingleInstanceLock();
19
+ if (singleLock && !gotTheLock) {
20
+ electronApp.quit();
21
+ }
44
22
 
45
- // kill cross services
46
- Cross.killAll();
47
- })
23
+ electronApp.whenReady().then(() => {
24
+ createMainWindow();
25
+ eventBus.emitLifecycle(Preload);
26
+ loadServer();
27
+ })
48
28
 
49
- if (CoreApp.config.hardGpu.enable == false) {
50
- app.disableHardwareAcceleration();
29
+ electronApp.on('window-all-closed', () => {
30
+ if (!is.macOS()) {
31
+ coreLogger.info('[ee-core] [lib/eeApp] window-all-closed quit');
32
+ electronApp.quit();
51
33
  }
34
+ })
52
35
 
53
- return app;
54
- },
36
+ electronApp.on('before-quit', () => {
37
+ setCloseAndQuit(true);
38
+ eventBus.emitLifecycle(BeforeClose);
39
+ cross.killAll();
40
+ })
55
41
 
56
- /**
57
- * 退出app
58
- */
59
- quit() {
60
- app.quit();
61
- }
42
+ eventBus.emitLifecycle(ElectronAppReady);
62
43
  }
63
44
 
64
- module.exports = CoreElectronApp;
45
+ module.exports = {
46
+ electronApp,
47
+ createElectron,
48
+ };
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
+ };