ee-core 4.1.0 → 4.1.2
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/boot.js +9 -2
- package/package.json +1 -4
- package/ps/index.d.ts +3 -1
- package/ps/index.js +26 -7
- package/socket/httpServer.js +43 -1
package/app/boot.js
CHANGED
|
@@ -4,7 +4,7 @@ const debug = require('debug')('ee-core:app:boot');
|
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const { loadException } = require('../exception');
|
|
6
6
|
const { electronApp } = require('../electron/app');
|
|
7
|
-
const { getArgumentByName, getBundleDir } = require('../ps');
|
|
7
|
+
const { getArgumentByName, getBundleDir, getElectronCodeDir } = require('../ps');
|
|
8
8
|
const { loadConfig } = require('../config');
|
|
9
9
|
const { loadLog } = require('../log');
|
|
10
10
|
const { app } = require('./application');
|
|
@@ -15,11 +15,18 @@ class ElectronEgg {
|
|
|
15
15
|
const baseDir = electronApp.getAppPath();
|
|
16
16
|
const { env } = process;
|
|
17
17
|
const environmet = getArgumentByName('env') || 'prod';
|
|
18
|
+
const debugging = getArgumentByName('debuger') == 'true'? true : false;
|
|
19
|
+
|
|
20
|
+
// Debugging source code
|
|
21
|
+
let electronDir = getBundleDir(baseDir);
|
|
22
|
+
if (debugging) {
|
|
23
|
+
electronDir = getElectronCodeDir(baseDir);
|
|
24
|
+
}
|
|
18
25
|
|
|
19
26
|
const options = {
|
|
20
27
|
env: environmet,
|
|
21
28
|
baseDir,
|
|
22
|
-
electronDir
|
|
29
|
+
electronDir,
|
|
23
30
|
appName: electronApp.getName(),
|
|
24
31
|
userHome: electronApp.getPath('home'),
|
|
25
32
|
appData: electronApp.getPath('appData'),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ee-core",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.2",
|
|
4
4
|
"description": "ee core",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,9 +8,6 @@
|
|
|
8
8
|
},
|
|
9
9
|
"author": "",
|
|
10
10
|
"license": "ISC",
|
|
11
|
-
"bin": {
|
|
12
|
-
"ee-core": "./bin/tools.js"
|
|
13
|
-
},
|
|
14
11
|
"dependencies": {
|
|
15
12
|
"agentkeepalive": "^4.2.0",
|
|
16
13
|
"axios": "^1.7.9",
|
package/ps/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export declare function appVersion(): string;
|
|
|
11
11
|
export declare function getDataDir(): string;
|
|
12
12
|
export declare function getLogDir(): string;
|
|
13
13
|
export declare function getBundleDir(basePath: string): string;
|
|
14
|
+
export declare function getElectronCodeDir(basePath: string): string;
|
|
15
|
+
export declare function getFrontendCodeDir(basePath: string): string;
|
|
14
16
|
export declare function getRootDir(): string;
|
|
15
17
|
export declare function getBaseDir(): string;
|
|
16
18
|
export declare function getElectronDir(): string;
|
|
@@ -34,4 +36,4 @@ export declare function makeMessage(msg?: {}): {
|
|
|
34
36
|
export declare function exitChildJob(code?: number): void;
|
|
35
37
|
export declare function isChildJob(): boolean;
|
|
36
38
|
export declare function isChildPoolJob(): boolean;
|
|
37
|
-
export declare function getArgumentByName(name: string): string;
|
|
39
|
+
export declare function getArgumentByName(name: string, args?: any): string;
|
package/ps/index.js
CHANGED
|
@@ -90,10 +90,18 @@ function getBundleDir(basePath) {
|
|
|
90
90
|
return dir;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
// 获取
|
|
94
|
-
function
|
|
95
|
-
const
|
|
96
|
-
|
|
93
|
+
// 获取electron 源码文件路径
|
|
94
|
+
function getElectronCodeDir(basePath) {
|
|
95
|
+
const base = basePath || process.cwd();
|
|
96
|
+
const dir = path.join(base, 'electron');
|
|
97
|
+
return dir;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 获取frontend 源码文件路径
|
|
101
|
+
function getFrontendCodeDir(basePath) {
|
|
102
|
+
const base = basePath || process.cwd();
|
|
103
|
+
const dir = path.join(base, 'frontend');
|
|
104
|
+
return dir;
|
|
97
105
|
}
|
|
98
106
|
|
|
99
107
|
// 获取base目录
|
|
@@ -133,6 +141,12 @@ function getExtraResourcesDir() {
|
|
|
133
141
|
return dir;
|
|
134
142
|
}
|
|
135
143
|
|
|
144
|
+
// 获取root目录 (dev-项目根目录,pro-app user data目录)
|
|
145
|
+
function getRootDir() {
|
|
146
|
+
const appDir = isDev() ? getBaseDir() : getAppUserDataDir();
|
|
147
|
+
return appDir;
|
|
148
|
+
}
|
|
149
|
+
|
|
136
150
|
// 获取 appUserData目录
|
|
137
151
|
function getAppUserDataDir() {
|
|
138
152
|
return process.env.EE_APP_USER_DATA;
|
|
@@ -230,9 +244,12 @@ function isChildPoolJob() {
|
|
|
230
244
|
}
|
|
231
245
|
|
|
232
246
|
// Get cmd parameter by name
|
|
233
|
-
function getArgumentByName(name) {
|
|
234
|
-
|
|
235
|
-
|
|
247
|
+
function getArgumentByName(name, args) {
|
|
248
|
+
if (!args) {
|
|
249
|
+
args = process.argv;
|
|
250
|
+
}
|
|
251
|
+
for (let i = 0; i < args.length; i++) {
|
|
252
|
+
const item = args[i];
|
|
236
253
|
const prefixKey = `--${name}=`;
|
|
237
254
|
if (item.indexOf(prefixKey) !== -1) {
|
|
238
255
|
return item.substring(prefixKey.length);
|
|
@@ -254,6 +271,8 @@ module.exports = {
|
|
|
254
271
|
getDataDir,
|
|
255
272
|
getLogDir,
|
|
256
273
|
getBundleDir,
|
|
274
|
+
getElectronCodeDir,
|
|
275
|
+
getFrontendCodeDir,
|
|
257
276
|
getRootDir,
|
|
258
277
|
getBaseDir,
|
|
259
278
|
getElectronDir,
|
package/socket/httpServer.js
CHANGED
|
@@ -50,6 +50,9 @@ class HttpServer {
|
|
|
50
50
|
*/
|
|
51
51
|
_create () {
|
|
52
52
|
const config = this.config;
|
|
53
|
+
// config.default 增加koaConfig配置项
|
|
54
|
+
const koaConfig = config.koaConfig || {};
|
|
55
|
+
const { preMiddleware = [], postMiddleware = [], errorHandler = null } = koaConfig;
|
|
53
56
|
const isHttps = config?.https?.enable ?? false;
|
|
54
57
|
const sslOptions = {};
|
|
55
58
|
|
|
@@ -67,11 +70,22 @@ class HttpServer {
|
|
|
67
70
|
const corsOptions = config.cors;
|
|
68
71
|
|
|
69
72
|
const koaApp = new Koa();
|
|
73
|
+
|
|
74
|
+
// 设置错误处理器,便于统一错误代码处理
|
|
75
|
+
this._setupErrorHandler(koaApp, errorHandler);
|
|
76
|
+
|
|
77
|
+
// 加载前置中间件
|
|
78
|
+
this._loadMiddlewares(koaApp, preMiddleware);
|
|
79
|
+
|
|
80
|
+
// 核心中间件
|
|
70
81
|
koaApp
|
|
71
82
|
.use(cors(corsOptions))
|
|
72
83
|
.use(koaBody(config.body))
|
|
73
84
|
.use(this._dispatch);
|
|
74
85
|
|
|
86
|
+
// 加载后置中间件
|
|
87
|
+
this._loadMiddlewares(koaApp, postMiddleware, 'post');
|
|
88
|
+
|
|
75
89
|
let msg = '[ee-core] [socket/http] server is: ' + url;
|
|
76
90
|
const listenOpt = {
|
|
77
91
|
host: config.host,
|
|
@@ -88,7 +102,7 @@ class HttpServer {
|
|
|
88
102
|
coreLogger.info(msg);
|
|
89
103
|
});
|
|
90
104
|
}
|
|
91
|
-
|
|
105
|
+
|
|
92
106
|
this.httpApp = koaApp;
|
|
93
107
|
}
|
|
94
108
|
|
|
@@ -150,6 +164,34 @@ class HttpServer {
|
|
|
150
164
|
getHttpApp() {
|
|
151
165
|
return this.httpApp;
|
|
152
166
|
}
|
|
167
|
+
|
|
168
|
+
// 设置错误处理函数
|
|
169
|
+
_setupErrorHandler(app, errorHandler) {
|
|
170
|
+
if (is.function(errorHandler)) {
|
|
171
|
+
app.on('error', errorHandler)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* 加载前置、后置中间件
|
|
177
|
+
* @param {*} app koaApp示例
|
|
178
|
+
* @param {*} middlewares 中间件数组
|
|
179
|
+
* @param {*} type 类型,pre/post
|
|
180
|
+
*/
|
|
181
|
+
_loadMiddlewares(app, middlewares = [], type = 'pre') {
|
|
182
|
+
if (is.array(middlewares)) {
|
|
183
|
+
middlewares.forEach((middleware) => {
|
|
184
|
+
if (is.function(middleware)) {
|
|
185
|
+
// middleware是一个方法
|
|
186
|
+
// 返回值是中间件(ctx, next) => {}的异步函数
|
|
187
|
+
// 便于使用async/await进行同步编程
|
|
188
|
+
app.use(middleware());
|
|
189
|
+
} else {
|
|
190
|
+
coreLogger.warn(`[ee-core/httpServer] Invalid ${type} middleware detected, skipping.`);
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
}
|
|
153
195
|
}
|
|
154
196
|
|
|
155
197
|
module.exports = {
|