ee-core 2.0.0-beta.2 → 2.0.0-beta.3
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/bin/tools.js +1 -1
- package/core/lib/loader/context_loader.js +2 -2
- package/core/lib/loader/ee_loader.js +4 -4
- package/core/lib/loader/file_loader.js +6 -6
- package/core/lib/loader/mixin/config.js +1 -1
- package/core/lib/loader/mixin/controller.js +8 -8
- package/lib/eeApp.js +5 -5
- package/module/httpclient/index.js +2 -2
- package/module/jobs/child/app.js +30 -10
- package/module/jobs/child/forkProcess.js +45 -67
- package/module/jobs/child/index.js +46 -20
- package/module/jobs/child/pool.js +67 -0
- package/module/jobs/index.js +5 -54
- package/module/jobs/unification.js +64 -0
- package/module/loader/index.js +3 -3
- package/module/message/childMessage.js +63 -0
- package/module/message/index.js +24 -9
- package/module/message/manager.js +0 -0
- package/module/message/messenger.js +0 -0
- package/module/socket/httpServer.js +4 -3
- package/module/socket/ipcServer.js +3 -6
- package/module/socket/socketClient.js +1 -4
- package/module/socket/socketServer.js +4 -6
- package/module/utils/index.js +1 -35
- package/module/utils/ps.js +25 -0
- package/package.json +1 -1
- package/tools/encrypt.js +10 -10
- package/tools/replaceDist.js +6 -6
- package/utils/index.js +0 -23
package/bin/tools.js
CHANGED
|
@@ -7,7 +7,7 @@ const encrypt = require('../tools/encrypt');
|
|
|
7
7
|
const args = process.argv;
|
|
8
8
|
// console.log('[ee-core] args:', args);
|
|
9
9
|
const cmd = args[2];
|
|
10
|
-
console.log('[ee-core] cmd:', cmd);
|
|
10
|
+
console.log('[ee-core] [bin/tools] cmd:', cmd);
|
|
11
11
|
|
|
12
12
|
if (cmd == 'rd') {
|
|
13
13
|
replaceDist.run();
|
|
@@ -5,7 +5,7 @@ const is = require('is-type-of');
|
|
|
5
5
|
const FileLoader = require('./file_loader');
|
|
6
6
|
const CLASSLOADER = Symbol('classLoader');
|
|
7
7
|
const EXPORTS = FileLoader.EXPORTS;
|
|
8
|
-
const
|
|
8
|
+
const Utils = require('../utils');
|
|
9
9
|
|
|
10
10
|
class ClassLoader {
|
|
11
11
|
|
|
@@ -89,7 +89,7 @@ function getInstance(values, ctx) {
|
|
|
89
89
|
const Class = values[EXPORTS] ? values : null;
|
|
90
90
|
let instance;
|
|
91
91
|
if (Class) {
|
|
92
|
-
if (is.class(Class) ||
|
|
92
|
+
if (is.class(Class) || Utils.isBytecodeClass(Class)) {
|
|
93
93
|
instance = new Class(ctx);
|
|
94
94
|
} else {
|
|
95
95
|
// it's just an object
|
|
@@ -7,7 +7,7 @@ const is = require('is-type-of');
|
|
|
7
7
|
const debug = require('debug')('ee-core:EeLoader');
|
|
8
8
|
const FileLoader = require('./file_loader');
|
|
9
9
|
const ContextLoader = require('./context_loader');
|
|
10
|
-
const
|
|
10
|
+
const Utils = require('../utils');
|
|
11
11
|
const Timing = require('../utils/timing');
|
|
12
12
|
const Ps = require('../../../module/utils/ps');
|
|
13
13
|
|
|
@@ -255,7 +255,7 @@ class EeLoader {
|
|
|
255
255
|
if (inject.length === 0) inject = [ this.app ];
|
|
256
256
|
|
|
257
257
|
let ret = this.requireFile(filepath);
|
|
258
|
-
if (is.function(ret) && !is.class(ret) && !
|
|
258
|
+
if (is.function(ret) && !is.class(ret) && !Utils.isBytecodeClass(ret)) {
|
|
259
259
|
ret = ret(...inject);
|
|
260
260
|
}
|
|
261
261
|
return ret;
|
|
@@ -267,9 +267,9 @@ class EeLoader {
|
|
|
267
267
|
* @private
|
|
268
268
|
*/
|
|
269
269
|
requireFile(filepath) {
|
|
270
|
-
const timingKey = `Require(${this[REQUIRE_COUNT]++}) ${
|
|
270
|
+
const timingKey = `Require(${this[REQUIRE_COUNT]++}) ${Utils.getResolvedFilename(filepath, this.options.baseDir)}`;
|
|
271
271
|
this.timing.start(timingKey);
|
|
272
|
-
const ret =
|
|
272
|
+
const ret = Utils.loadFile(filepath);
|
|
273
273
|
this.timing.end(timingKey);
|
|
274
274
|
return ret;
|
|
275
275
|
}
|
|
@@ -7,7 +7,7 @@ const path = require('path');
|
|
|
7
7
|
const globby = require('globby');
|
|
8
8
|
const is = require('is-type-of');
|
|
9
9
|
const deprecate = require('depd')('ee');
|
|
10
|
-
const
|
|
10
|
+
const Utils = require('../utils');
|
|
11
11
|
const FULLPATH = Symbol('EE_LOADER_ITEM_FULLPATH');
|
|
12
12
|
const EXPORTS = Symbol('EE_LOADER_ITEM_EXPORTS');
|
|
13
13
|
|
|
@@ -125,7 +125,7 @@ class FileLoader {
|
|
|
125
125
|
parse() {
|
|
126
126
|
let files = this.options.match;
|
|
127
127
|
if (!files) {
|
|
128
|
-
files = (process.env.EE_TYPESCRIPT === 'true' &&
|
|
128
|
+
files = (process.env.EE_TYPESCRIPT === 'true' && Utils.extensions['.ts'])
|
|
129
129
|
? [ '**/*.(js|ts)', '!**/*.d.ts' ]
|
|
130
130
|
: [ '**/*.js', '**/*.jsc'];
|
|
131
131
|
} else {
|
|
@@ -164,7 +164,7 @@ class FileLoader {
|
|
|
164
164
|
if (exports == null || (filter && filter(exports) === false)) continue;
|
|
165
165
|
|
|
166
166
|
// set properties of class
|
|
167
|
-
if (is.class(exports) ||
|
|
167
|
+
if (is.class(exports) || Utils.isBytecodeClass(exports)) {
|
|
168
168
|
exports.prototype.pathName = pathName;
|
|
169
169
|
exports.prototype.fullPath = fullpath;
|
|
170
170
|
}
|
|
@@ -217,7 +217,7 @@ class FileLoader {
|
|
|
217
217
|
if (exports == null) continue;
|
|
218
218
|
|
|
219
219
|
const properties = [addonName];
|
|
220
|
-
if (is.class(exports) ||
|
|
220
|
+
if (is.class(exports) || Utils.isBytecodeClass(exports)) {
|
|
221
221
|
exports.prototype.pathName = addonName;
|
|
222
222
|
exports.prototype.fullPath = fullpath;
|
|
223
223
|
}
|
|
@@ -261,7 +261,7 @@ function getProperties(filepath, { caseStyle }) {
|
|
|
261
261
|
// Get exports from filepath
|
|
262
262
|
// If exports is null/undefined, it will be ignored
|
|
263
263
|
function getExports(fullpath, { initializer, call, inject }, pathName) {
|
|
264
|
-
let exports =
|
|
264
|
+
let exports = Utils.loadFile(fullpath);
|
|
265
265
|
|
|
266
266
|
// process exports as you like
|
|
267
267
|
if (initializer) {
|
|
@@ -275,7 +275,7 @@ function getExports(fullpath, { initializer, call, inject }, pathName) {
|
|
|
275
275
|
// module.exports = function*() {}
|
|
276
276
|
//new exports;
|
|
277
277
|
|
|
278
|
-
if (is.class(exports) || is.generatorFunction(exports) || is.asyncFunction(exports) ||
|
|
278
|
+
if (is.class(exports) || is.generatorFunction(exports) || is.asyncFunction(exports) || Utils.isBytecodeClass(exports)) {
|
|
279
279
|
return exports;
|
|
280
280
|
}
|
|
281
281
|
|
|
@@ -102,7 +102,7 @@ module.exports = {
|
|
|
102
102
|
this._setConfigMeta(envConfig, '<process.env.EE_APP_CONFIG>');
|
|
103
103
|
return envConfig;
|
|
104
104
|
} catch (err) {
|
|
105
|
-
this.options.logger.warn('[ee-
|
|
105
|
+
this.options.logger.warn('[ee-core] [core/.../config] process.env.EE_APP_CONFIG is not invalid JSON: %s', envConfigStr);
|
|
106
106
|
}
|
|
107
107
|
},
|
|
108
108
|
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const is = require('is-type-of');
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const UtilsFn = require('../../utils/function');
|
|
6
|
+
const Utils = require('../../utils');
|
|
7
7
|
const FULLPATH = require('../file_loader').FULLPATH;
|
|
8
8
|
|
|
9
9
|
module.exports = {
|
|
@@ -26,10 +26,10 @@ module.exports = {
|
|
|
26
26
|
// }
|
|
27
27
|
// ```
|
|
28
28
|
|
|
29
|
-
if (is.function(obj) && !is.generatorFunction(obj) && !is.class(obj) && !is.asyncFunction(obj) && !
|
|
29
|
+
if (is.function(obj) && !is.generatorFunction(obj) && !is.class(obj) && !is.asyncFunction(obj) && !Utils.isBytecodeClass(obj)) {
|
|
30
30
|
obj = obj(this.app);
|
|
31
31
|
}
|
|
32
|
-
if (is.class(obj) ||
|
|
32
|
+
if (is.class(obj) || Utils.isBytecodeClass(obj)) {
|
|
33
33
|
obj.prototype.pathName = opt.pathName;
|
|
34
34
|
obj.prototype.fullPath = opt.path;
|
|
35
35
|
return wrapClass(obj);
|
|
@@ -47,7 +47,7 @@ module.exports = {
|
|
|
47
47
|
const controllerBase = opt.directory;
|
|
48
48
|
|
|
49
49
|
this.loadToApp(controllerBase, 'controller', opt);
|
|
50
|
-
this.options.logger.info('[ee-core
|
|
50
|
+
this.options.logger.info('[ee-core] [core/.../controller] loaded: %s', controllerBase);
|
|
51
51
|
this.timing.end('Load Controller');
|
|
52
52
|
},
|
|
53
53
|
|
|
@@ -86,7 +86,7 @@ function wrapClass(Controller) {
|
|
|
86
86
|
// args = [ this ];
|
|
87
87
|
// }
|
|
88
88
|
//args = [ this ];
|
|
89
|
-
return
|
|
89
|
+
return Utils.callFn(controller[key], args, controller);
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
92
|
}
|
|
@@ -97,7 +97,7 @@ function wrapObject(obj, path, prefix) {
|
|
|
97
97
|
const ret = {};
|
|
98
98
|
for (const key of keys) {
|
|
99
99
|
if (is.function(obj[key])) {
|
|
100
|
-
const names =
|
|
100
|
+
const names = UtilsFn.getParamNames(obj[key]);
|
|
101
101
|
if (names[0] === 'next') {
|
|
102
102
|
throw new Error(`controller \`${prefix || ''}${key}\` should not use next as argument from file ${path}`);
|
|
103
103
|
}
|
|
@@ -114,7 +114,7 @@ function wrapObject(obj, path, prefix) {
|
|
|
114
114
|
// if (!this.app.config.controller || !this.app.config.controller.supportParams) {
|
|
115
115
|
// args = [ this ];
|
|
116
116
|
// }
|
|
117
|
-
return await
|
|
117
|
+
return await Utils.callFn(func, args, this);
|
|
118
118
|
};
|
|
119
119
|
for (const key in func) {
|
|
120
120
|
objectControllerMiddleware[key] = func[key];
|
package/lib/eeApp.js
CHANGED
|
@@ -80,7 +80,7 @@ class EeApp extends BaseApp {
|
|
|
80
80
|
|
|
81
81
|
app.on('window-all-closed', () => {
|
|
82
82
|
if (process.platform !== 'darwin') {
|
|
83
|
-
Log.coreLogger.info('[
|
|
83
|
+
Log.coreLogger.info('[ee-core] [lib/eeApp] window-all-closed quit');
|
|
84
84
|
self.appQuit();
|
|
85
85
|
}
|
|
86
86
|
})
|
|
@@ -105,7 +105,7 @@ class EeApp extends BaseApp {
|
|
|
105
105
|
const protocolName = 'eefile';
|
|
106
106
|
protocol.registerFileProtocol(protocolName, (request, callback) => {
|
|
107
107
|
const url = request.url.substring(protocolName.length + 3);
|
|
108
|
-
console.log('[ee-core
|
|
108
|
+
console.log('[ee-core] [lib/eeApp] registerFileProtocol ----url: ', url);
|
|
109
109
|
callback({ path: path.normalize(decodeURIComponent(url)) })
|
|
110
110
|
});
|
|
111
111
|
|
|
@@ -220,7 +220,7 @@ class EeApp extends BaseApp {
|
|
|
220
220
|
};
|
|
221
221
|
https.createServer(sslOpt, koaApp.callback()).listen(mainServer.port, (err) => {
|
|
222
222
|
if (err) {
|
|
223
|
-
Log.coreLogger.info('[
|
|
223
|
+
Log.coreLogger.info('[ee-core] [lib/eeApp] createServer error: ', err);
|
|
224
224
|
return
|
|
225
225
|
}
|
|
226
226
|
self.loadMainUrl(mode, url);
|
|
@@ -237,8 +237,8 @@ class EeApp extends BaseApp {
|
|
|
237
237
|
*/
|
|
238
238
|
loadMainUrl (type, url) {
|
|
239
239
|
const mainServer = this.config.mainServer;
|
|
240
|
-
Log.coreLogger.info('[ee-core
|
|
241
|
-
Log.coreLogger.info('[ee-core
|
|
240
|
+
Log.coreLogger.info('[ee-core] [main] Env: %s, Type: %s', this.config.env, type);
|
|
241
|
+
Log.coreLogger.info('[ee-core] [main] App running at: %s', url);
|
|
242
242
|
this.electron.mainWindow.loadURL(url, mainServer.options);
|
|
243
243
|
}
|
|
244
244
|
|
|
@@ -152,12 +152,12 @@ function normalizeConfig(httpConfig) {
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
if (config.httpAgent.timeout < 30000) {
|
|
155
|
-
Log.coreLogger.warn('[ee
|
|
155
|
+
Log.coreLogger.warn('[ee-core] [module/httpclient] config.httpclient.httpAgent.timeout(%s) can\'t below 30000, auto reset to 30000',
|
|
156
156
|
config.httpAgent.timeout);
|
|
157
157
|
config.httpAgent.timeout = 30000;
|
|
158
158
|
}
|
|
159
159
|
if (config.httpsAgent.timeout < 30000) {
|
|
160
|
-
Log.coreLogger.warn('[ee
|
|
160
|
+
Log.coreLogger.warn('[ee-core] [module/httpclient] config.httpclient.httpsAgent.timeout(%s) can\'t below 30000, auto reset to 30000',
|
|
161
161
|
config.httpsAgent.timeout);
|
|
162
162
|
config.httpsAgent.timeout = 30000;
|
|
163
163
|
}
|
package/module/jobs/child/app.js
CHANGED
|
@@ -1,23 +1,43 @@
|
|
|
1
|
+
|
|
1
2
|
const Exception = require('ee-core/module/exception');
|
|
2
3
|
Exception.start();
|
|
3
|
-
|
|
4
4
|
const Loader = require('ee-core/module/loader');
|
|
5
5
|
const Log = require('ee-core/module/log');
|
|
6
6
|
|
|
7
7
|
class ChildApp {
|
|
8
8
|
constructor() {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
this._initEvents();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 初始化事件监听
|
|
14
|
+
*/
|
|
15
|
+
_initEvents() {
|
|
16
|
+
Log.info('[ee-core] [child-process] init Events');
|
|
17
|
+
|
|
18
|
+
process.on('disconnect', () => {
|
|
19
|
+
Log.coreLogger.info(`[ee-core] [module/message/childMessage] child process disconnected:${process.pid} !`);
|
|
20
|
+
});
|
|
21
|
+
process.on('exit', () => {
|
|
22
|
+
Log.coreLogger.info(`[ee-core] [module/message/childMessage] child process exited:${process.pid} !`);
|
|
23
|
+
});
|
|
24
|
+
process.on('message', this._handleMessage.bind(this));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 监听消息
|
|
29
|
+
*/
|
|
30
|
+
_handleMessage(message) {
|
|
31
|
+
Log.coreLogger.info(`[ee-core] [module/message/childMessage] Received a message ${message} from the mainProcess`);
|
|
32
|
+
|
|
33
|
+
this.run(message);
|
|
11
34
|
}
|
|
12
35
|
|
|
13
|
-
run
|
|
14
|
-
Log.info('[child-process] run');
|
|
15
|
-
|
|
16
|
-
const jobFile = this.opt.jobPath;
|
|
36
|
+
run(msg = {}) {
|
|
37
|
+
Log.coreLogger.info('[ee-core] [child-process] run');
|
|
17
38
|
|
|
18
|
-
Loader.loadJobFile(
|
|
39
|
+
Loader.loadJobFile(msg.jobPath, msg.params);
|
|
19
40
|
}
|
|
20
41
|
}
|
|
21
42
|
|
|
22
|
-
|
|
23
|
-
app.run();
|
|
43
|
+
new ChildApp();
|
|
@@ -1,104 +1,82 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const { fork } = require('child_process');
|
|
3
|
+
const Log = require('../../log');
|
|
4
|
+
const Ps = require('../../utils/ps');
|
|
3
5
|
|
|
4
6
|
class ForkProcess {
|
|
5
|
-
constructor(host,
|
|
7
|
+
constructor(host, opt = {}) {
|
|
8
|
+
|
|
9
|
+
let processCWD = Ps.getHomeDir();
|
|
10
|
+
// if (Ps.isDev()) {
|
|
11
|
+
// cwd = path.join(Ps.getHomeDir());
|
|
12
|
+
// }
|
|
13
|
+
|
|
14
|
+
let options = Object.assign({
|
|
15
|
+
params: {},
|
|
16
|
+
processOptions: {
|
|
17
|
+
cwd: processCWD,
|
|
18
|
+
env: Ps.allEnv(),
|
|
19
|
+
stdio: 'pipe'
|
|
20
|
+
}
|
|
21
|
+
}, opt);
|
|
22
|
+
|
|
6
23
|
this.host = host;
|
|
7
|
-
this.
|
|
8
|
-
this.args;
|
|
9
|
-
this.options = processOptions;
|
|
24
|
+
this.args = [];
|
|
10
25
|
this.sleeping = false;
|
|
11
|
-
this.activitiesCount = 0;
|
|
12
|
-
this.activitiesMap = new Map();
|
|
13
26
|
|
|
14
27
|
// 传递给子进程的参数
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
processArgs.push(JSON.stringify(scriptArgs));
|
|
19
|
-
this.args = processArgs;
|
|
20
|
-
|
|
28
|
+
this.args.push(JSON.stringify(options.params));
|
|
29
|
+
|
|
21
30
|
const appPath = path.join(__dirname, 'app.js');
|
|
22
|
-
this.child = fork(appPath, this.args,
|
|
31
|
+
this.child = fork(appPath, this.args, options.processOptions);
|
|
23
32
|
|
|
24
33
|
this.pid = this.child.pid;
|
|
25
34
|
this._init();
|
|
26
35
|
}
|
|
27
36
|
|
|
28
|
-
/**
|
|
29
|
-
* 进程挂起
|
|
30
|
-
*/
|
|
31
|
-
sleep() {
|
|
32
|
-
if (this.activitiesCount) {
|
|
33
|
-
if (this.sleeping) return;
|
|
34
|
-
process.kill(this.pid, 'SIGSTOP');
|
|
35
|
-
this.sleeping = true;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 进程唤醒
|
|
41
|
-
*/
|
|
42
|
-
wakeup() {
|
|
43
|
-
if (!this.sleeping) return;
|
|
44
|
-
process.kill(this.pid, 'SIGCONT');
|
|
45
|
-
this.sleeping = false;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
37
|
/**
|
|
49
38
|
* 进程初始化
|
|
50
39
|
*/
|
|
51
40
|
_init() {
|
|
52
41
|
this.child.on('message', (data) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
42
|
+
Log.coreLogger.info(`[ee-core] [module/jobs/child/forkProcess] from childProcess event-message ${data}`);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
this.child.on('disconnect', () => {
|
|
46
|
+
Log.coreLogger.info(`[ee-core] [module/jobs/child/forkProcess] from childProcess event-disconnect !`);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
this.child.on('close', (code, signal) => {
|
|
50
|
+
Log.coreLogger.info(`[ee-core] [module/jobs/child/forkProcess] from childProcess event-close code:${code}, signal:${signal}`);
|
|
58
51
|
});
|
|
52
|
+
|
|
59
53
|
this.child.on('exit', (code, signal) => {
|
|
60
|
-
|
|
61
|
-
// this.host.emit('forked_error', code, this.pid);
|
|
62
|
-
// } else {
|
|
63
|
-
// this.host.emit('forked_exit', this.pid);
|
|
64
|
-
// }
|
|
54
|
+
Log.coreLogger.info(`[ee-core] [module/jobs/child/forkProcess] from childProcess event-exit code:${code}, signal:${signal}`);
|
|
65
55
|
});
|
|
56
|
+
|
|
66
57
|
this.child.on('error', (err) => {
|
|
67
|
-
|
|
68
|
-
// this.host.emit('forked_error', err, this.pid);
|
|
58
|
+
Log.coreLogger.error(`[ee-core] [module/jobs/child/forkProcess] from childProcess event-error :${err} !`);
|
|
69
59
|
});
|
|
70
60
|
}
|
|
71
61
|
|
|
72
62
|
/**
|
|
73
|
-
*
|
|
63
|
+
* 进程挂起
|
|
74
64
|
*/
|
|
75
|
-
|
|
76
|
-
if (this.sleeping)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.connectionsCountPlus(params.id);
|
|
80
|
-
this.child.send(params);
|
|
65
|
+
sleep() {
|
|
66
|
+
if (this.sleeping) return;
|
|
67
|
+
process.kill(this.pid, 'SIGSTOP');
|
|
68
|
+
this.sleeping = true;
|
|
81
69
|
}
|
|
82
70
|
|
|
83
71
|
/**
|
|
84
|
-
*
|
|
72
|
+
* 进程唤醒
|
|
85
73
|
*/
|
|
86
|
-
|
|
87
|
-
this.
|
|
88
|
-
this.
|
|
89
|
-
this.
|
|
74
|
+
wakeup() {
|
|
75
|
+
if (!this.sleeping) return;
|
|
76
|
+
process.kill(this.pid, 'SIGCONT');
|
|
77
|
+
this.sleeping = false;
|
|
90
78
|
}
|
|
91
79
|
|
|
92
|
-
/**
|
|
93
|
-
* 连接数-
|
|
94
|
-
*/
|
|
95
|
-
_connectionsCountMinus(id) {
|
|
96
|
-
if (this.activitiesMap.has(id)) {
|
|
97
|
-
this.activitiesCount = (this.activitiesCount > 0) ? (this.activitiesCount - 1) : 0;
|
|
98
|
-
this.activitiesMap.delete(id);
|
|
99
|
-
}
|
|
100
|
-
this.host.connectionsMap[this.pid] = this.activitiesCount;
|
|
101
|
-
}
|
|
102
80
|
}
|
|
103
81
|
|
|
104
82
|
module.exports = ForkProcess;
|
|
@@ -1,35 +1,61 @@
|
|
|
1
|
-
|
|
1
|
+
const EventEmitter = require('events');
|
|
2
2
|
const path = require('path');
|
|
3
|
+
const fs = require('fs');
|
|
3
4
|
const ForkProcess = require('./forkProcess');
|
|
4
5
|
const Ps = require('../../utils/ps');
|
|
5
|
-
const
|
|
6
|
+
const Loader = require('../../loader');
|
|
6
7
|
|
|
7
|
-
class ChildJob {
|
|
8
|
+
class ChildJob extends EventEmitter {
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this.jobList = new Map();
|
|
13
|
+
}
|
|
8
14
|
|
|
9
15
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
constructor(name, filepath, opt = {}) {
|
|
16
|
-
// todo
|
|
17
|
-
//processArgs: Ps.isDev() ? [`--inspect=${Constants.jobs.inspectStartIndex}`] : [],
|
|
16
|
+
* 运行任务
|
|
17
|
+
*/
|
|
18
|
+
run(name, filepath, opt = {}) {
|
|
19
|
+
|
|
20
|
+
const jobPath = this._getFullpath(filepath);
|
|
18
21
|
let options = Object.assign({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
env: Ps.allEnv(),
|
|
23
|
-
stdio: 'pipe'
|
|
22
|
+
times: 1,
|
|
23
|
+
params: {
|
|
24
|
+
jobPath
|
|
24
25
|
}
|
|
25
26
|
}, opt);
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
// 消息对象
|
|
29
|
+
let msg = {
|
|
30
|
+
jobPath: jobPath,
|
|
31
|
+
params: options.params
|
|
32
|
+
}
|
|
33
|
+
let subProcess;
|
|
34
|
+
for (let i = 1; i <= options.times; i++) {
|
|
35
|
+
subProcess = new ForkProcess(this, options);
|
|
36
|
+
this.jobList.set(name, i);
|
|
37
|
+
|
|
38
|
+
// 发消息到子进程
|
|
39
|
+
subProcess.child.send(msg);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return subProcess;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
_getFullpath(filepath) {
|
|
46
|
+
const isAbsolute = path.isAbsolute(filepath);
|
|
47
|
+
if (!isAbsolute) {
|
|
48
|
+
filepath = path.join(Ps.getBaseDir(), filepath);
|
|
49
|
+
}
|
|
28
50
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
51
|
+
const fullpath = Loader.resolveModule(filepath);
|
|
52
|
+
if (!fs.existsSync(fullpath)) {
|
|
53
|
+
throw new Error(`[ee-core] [module/jobs/child] file ${fullpath} not exists`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return fullpath;
|
|
32
57
|
}
|
|
58
|
+
|
|
33
59
|
}
|
|
34
60
|
|
|
35
61
|
module.exports = ChildJob;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const EventEmitter = require('events');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const ForkProcess = require('./forkProcess');
|
|
5
|
+
const Ps = require('../../utils/ps');
|
|
6
|
+
const Loader = require('../../loader');
|
|
7
|
+
const Log = require('../../log');
|
|
8
|
+
|
|
9
|
+
class ChildJob {
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* constructor
|
|
13
|
+
*/
|
|
14
|
+
constructor(name, filepath, opt) {
|
|
15
|
+
this.pools = new Map();
|
|
16
|
+
this.create(name, filepath, opt);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
_initEvents() {
|
|
20
|
+
// ddd
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
create(name, filepath, opt = {}) {
|
|
25
|
+
|
|
26
|
+
const isAbsolute = path.isAbsolute(filepath);
|
|
27
|
+
if (!isAbsolute) {
|
|
28
|
+
filepath = path.join(Ps.getBaseDir(), filepath);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const fullpath = Loader.resolveModule(filepath);
|
|
32
|
+
if (!fs.existsSync(fullpath)) {
|
|
33
|
+
throw new Error(`[ee-core] [module/jobs/child] file ${fullpath} not exists`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let options = Object.assign({
|
|
37
|
+
scriptArgs: {
|
|
38
|
+
name: name,
|
|
39
|
+
jobPath: fullpath
|
|
40
|
+
},
|
|
41
|
+
processArgs: [],
|
|
42
|
+
processOptions: {
|
|
43
|
+
//cwd: path.dirname(filepath),
|
|
44
|
+
env: Ps.allEnv(),
|
|
45
|
+
stdio: 'pipe'
|
|
46
|
+
}
|
|
47
|
+
}, opt);
|
|
48
|
+
|
|
49
|
+
const subProcess = new ForkProcess(this, options);
|
|
50
|
+
this.pools.set(subProcess.pid, subProcess);
|
|
51
|
+
|
|
52
|
+
return subProcess;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
sendToChild(pid, message, ...other) {
|
|
56
|
+
if (!this.pools.has(pid)) {
|
|
57
|
+
Log.coreLogger.warn(`[ee-core] [module/jobs/child] process dose not exist ${pid}`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const subProcess = this.pools.get(pid);
|
|
61
|
+
subProcess.child.send(message, ...other);
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = ChildJob;
|
package/module/jobs/index.js
CHANGED
|
@@ -1,56 +1,7 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const RendererJob = require('./renderer');
|
|
4
1
|
const ChildJob = require('./child');
|
|
5
|
-
const
|
|
6
|
-
const Loader = require('../loader');
|
|
7
|
-
|
|
8
|
-
class Jobs {
|
|
9
|
-
constructor() {
|
|
10
|
-
this.type = undefined;
|
|
11
|
-
this.instance = undefined;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 创建 job
|
|
16
|
-
*/
|
|
17
|
-
create (name, opt = {}) {
|
|
18
|
-
this.type = opt.type || 'child';
|
|
19
|
-
this.dev = opt.dev || false;
|
|
20
|
-
this.winOptions = opt.winOptions || {};
|
|
21
|
-
this.childOptions = opt.childOptions || {};
|
|
22
|
-
this.path = opt.path || null;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const isAbsolute = path.isAbsolute(this.path);
|
|
26
|
-
if (!isAbsolute) {
|
|
27
|
-
this.path = path.join(Utils.getBaseDir(), this.path);
|
|
28
|
-
}
|
|
29
|
-
const filepath = Loader.resolveModule(this.path);
|
|
30
|
-
|
|
31
|
-
if (!fs.existsSync(filepath)) {
|
|
32
|
-
throw new Error(`[ee-core] [jobs-create] file ${this.path} not exists`);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
this.path = filepath;
|
|
36
|
-
if (this.type == 'child') {
|
|
37
|
-
this.instance = new ChildJob(name, filepath, this.childOptions);
|
|
38
|
-
} else if (this.type == 'renderer') {
|
|
39
|
-
this.instance = new RendererJob(name, filepath, this.winOptions);
|
|
40
|
-
if (this.dev) {
|
|
41
|
-
this.openDevTools();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 显示开发者工具栏(仅支持 RendererJob)
|
|
50
|
-
*/
|
|
51
|
-
openDevTools () {
|
|
52
|
-
this.instance.openDevTools();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
2
|
+
const RendererJob = require('./renderer');
|
|
55
3
|
|
|
56
|
-
module.exports =
|
|
4
|
+
module.exports = {
|
|
5
|
+
ChildJob,
|
|
6
|
+
RendererJob
|
|
7
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const RendererJob = require('./renderer');
|
|
4
|
+
const ChildJob = require('./child/pool');
|
|
5
|
+
const Ps = require('../utils/ps');
|
|
6
|
+
const Loader = require('../loader');
|
|
7
|
+
|
|
8
|
+
class Jobs {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.type;
|
|
11
|
+
this.dev;
|
|
12
|
+
this.path;
|
|
13
|
+
this.instance;
|
|
14
|
+
this.child;
|
|
15
|
+
this.childOptions;
|
|
16
|
+
this.renderer;
|
|
17
|
+
this.winOptions;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 创建 job
|
|
22
|
+
*/
|
|
23
|
+
create (name, opt = {}) {
|
|
24
|
+
this.type = opt.type || 'child';
|
|
25
|
+
this.dev = opt.dev || false;
|
|
26
|
+
this.winOptions = opt.winOptions || {};
|
|
27
|
+
this.childOptions = opt.childOptions || {};
|
|
28
|
+
this.path = opt.path || null;
|
|
29
|
+
|
|
30
|
+
const isAbsolute = path.isAbsolute(this.path);
|
|
31
|
+
if (!isAbsolute) {
|
|
32
|
+
this.path = path.join(Ps.getBaseDir(), this.path);
|
|
33
|
+
}
|
|
34
|
+
const filepath = Loader.resolveModule(this.path);
|
|
35
|
+
|
|
36
|
+
if (!fs.existsSync(filepath)) {
|
|
37
|
+
throw new Error(`[ee-core] [jobs-create] file ${this.path} not exists`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this.path = filepath;
|
|
41
|
+
if (this.type == 'child') {
|
|
42
|
+
this.instance = new ChildJob(name, filepath, this.childOptions);
|
|
43
|
+
this.child = this.instance;
|
|
44
|
+
} else if (this.type == 'renderer') {
|
|
45
|
+
this.instance = new RendererJob(name, filepath, this.winOptions);
|
|
46
|
+
this.renderer = this.instance;
|
|
47
|
+
|
|
48
|
+
if (this.dev) {
|
|
49
|
+
this.openDevTools();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 显示开发者工具栏(仅支持 RendererJob)
|
|
58
|
+
*/
|
|
59
|
+
openDevTools () {
|
|
60
|
+
this.instance.openDevTools();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = Jobs;
|
package/module/loader/index.js
CHANGED
|
@@ -45,7 +45,7 @@ module.exports = {
|
|
|
45
45
|
*/
|
|
46
46
|
loadJobFile (filepath, ...inject) {
|
|
47
47
|
if (!fs.existsSync(filepath)) {
|
|
48
|
-
let warnMsg = `[ee-core] [module/loader
|
|
48
|
+
let warnMsg = `[ee-core] [module/loader] loadJobFile ${filepath} does not exist`;
|
|
49
49
|
Log.coreLogger.error(warnMsg);
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -75,7 +75,7 @@ module.exports = {
|
|
|
75
75
|
|
|
76
76
|
if (!fs.existsSync(filepath) && !fs.existsSync(fullpath)) {
|
|
77
77
|
let files = { filepath, fullpath }
|
|
78
|
-
Log.coreLogger.warn(`[ee-core] [module
|
|
78
|
+
Log.coreLogger.warn(`[ee-core] [module/loader] resolveModule unknow filepath: ${files}`)
|
|
79
79
|
return undefined;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -99,7 +99,7 @@ module.exports = {
|
|
|
99
99
|
|
|
100
100
|
fullpath = this.resolveModule(filepath);
|
|
101
101
|
if (!fs.existsSync(fullpath)) {
|
|
102
|
-
let errorMsg = `[ee-core] [module
|
|
102
|
+
let errorMsg = `[ee-core] [module/loader] requireModule filepath: ${filepath} does not exist`;
|
|
103
103
|
Log.coreLogger.error(errorMsg);
|
|
104
104
|
}
|
|
105
105
|
const ret = UtilsCore.loadFile(fullpath);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const Log = require('../log');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ChildMessage
|
|
5
|
+
*/
|
|
6
|
+
class ChildMessage {
|
|
7
|
+
constructor() {
|
|
8
|
+
// ...
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 初始化事件监听
|
|
13
|
+
*/
|
|
14
|
+
initEvents() {
|
|
15
|
+
process.on('disconnect', () => {
|
|
16
|
+
Log.coreLogger.info(`[ee-core] [module/message/childMessage] child process disconnected:${process.pid} !`);
|
|
17
|
+
});
|
|
18
|
+
process.on('exit', () => {
|
|
19
|
+
Log.coreLogger.info(`[ee-core] [module/message/childMessage] child process exited:${process.pid} !`);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 监听消息
|
|
25
|
+
*/
|
|
26
|
+
onMessage(handle) {
|
|
27
|
+
Log.coreLogger.info(`[ee-core] [module/message/childMessage] Received a message ${params} from the mainProcess`);
|
|
28
|
+
|
|
29
|
+
process.on('message', handle.bind(this));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 消息处理
|
|
34
|
+
*/
|
|
35
|
+
// _handleMessage(params = {}) {
|
|
36
|
+
// Log.coreLogger.info(`[ee-core] [module/message/childMessage] Received a message ${params} from the mainProcess`);
|
|
37
|
+
// }
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 向主进程发消息
|
|
41
|
+
*/
|
|
42
|
+
sendToMain(message, ...other) {
|
|
43
|
+
return process.send(message, ...other);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 断开连接
|
|
48
|
+
*/
|
|
49
|
+
disconnect() {
|
|
50
|
+
process.disconnect();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 进程退出
|
|
55
|
+
*/
|
|
56
|
+
exit() {
|
|
57
|
+
process.exit();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
module.exports = ChildMessage;
|
package/module/message/index.js
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
|
-
const
|
|
1
|
+
const Ps = require('../utils/ps');
|
|
2
|
+
const EEChildMessage = Symbol('EeCore#Module#ChildMessage');
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
+
const message = {
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
create () {
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
m.d = require();
|
|
11
|
-
}
|
|
11
|
+
},
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* childMessage
|
|
15
|
+
*/
|
|
16
|
+
get childMessage() {
|
|
17
|
+
if (!this[EEChildMessage]) {
|
|
18
|
+
this[EEChildMessage] = Logger.create();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return this[EEChildMessage] || null;
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
module.exports = message;
|
|
File without changes
|
|
File without changes
|
|
@@ -9,6 +9,7 @@ const https = require('https');
|
|
|
9
9
|
const fs = require('fs');
|
|
10
10
|
const path = require('path');
|
|
11
11
|
const _ = require('lodash');
|
|
12
|
+
const Log = require('../log');
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* http server
|
|
@@ -60,16 +61,16 @@ class HttpServer {
|
|
|
60
61
|
})
|
|
61
62
|
.use(this.dispatch);
|
|
62
63
|
|
|
63
|
-
let msg = '[ee-core
|
|
64
|
+
let msg = '[ee-core] [module/socket/httpServer] server is: ' + url;
|
|
64
65
|
if (isHttps) {
|
|
65
66
|
https.createServer(sslOptions, koaApp.callback()).listen(httpServer.port, (err) => {
|
|
66
67
|
msg = err ? err : msg;
|
|
67
|
-
|
|
68
|
+
Log.coreLogger.info(msg);
|
|
68
69
|
});
|
|
69
70
|
} else {
|
|
70
71
|
koaApp.listen(httpServer.port, (e) => {
|
|
71
72
|
msg = e ? e : msg;
|
|
72
|
-
|
|
73
|
+
Log.coreLogger.info(msg);
|
|
73
74
|
});
|
|
74
75
|
}
|
|
75
76
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const debug = require('debug')('ee-core:ipcServer');
|
|
2
|
-
const EggConsoleLogger = require('egg-logger').EggConsoleLogger;
|
|
3
2
|
const is = require('is-type-of');
|
|
4
3
|
const { ipcMain } = require('electron');
|
|
5
4
|
const path = require('path');
|
|
@@ -7,18 +6,16 @@ const fs = require('fs');
|
|
|
7
6
|
const globby = require('globby');
|
|
8
7
|
const Utils = require('../../core/lib/utils');
|
|
9
8
|
const Wrap = require('../utils/wrap');
|
|
9
|
+
const Log = require('../log');
|
|
10
10
|
|
|
11
11
|
class IpcServer {
|
|
12
12
|
constructor (app) {
|
|
13
|
-
|
|
14
13
|
this.app = app;
|
|
15
|
-
this.consoleLogger = new EggConsoleLogger();
|
|
16
|
-
this.consoleLogger.info('[ee-core:socket:ipcMain] start ipcMain');
|
|
17
14
|
this.register();
|
|
18
15
|
}
|
|
19
16
|
|
|
20
17
|
register () {
|
|
21
|
-
|
|
18
|
+
console.log('[ee-core] [module/socket/IpcServer] register channels');
|
|
22
19
|
|
|
23
20
|
const self = this;
|
|
24
21
|
// 遍历方法
|
|
@@ -78,7 +75,7 @@ class IpcServer {
|
|
|
78
75
|
|
|
79
76
|
return fn;
|
|
80
77
|
} catch (err) {
|
|
81
|
-
|
|
78
|
+
Log.coreLogger.error('[ee-core] [module/socket/IpcServer] throw error:', err);
|
|
82
79
|
}
|
|
83
80
|
return null;
|
|
84
81
|
}
|
|
@@ -3,19 +3,16 @@
|
|
|
3
3
|
const assert = require('assert');
|
|
4
4
|
const IoClient = require('socket.io-client');
|
|
5
5
|
const Constants = require('../const');
|
|
6
|
-
const EggConsoleLogger = require('egg-logger').EggConsoleLogger;
|
|
7
6
|
const Storage = require('../storage');
|
|
8
7
|
|
|
9
8
|
class SocketClient {
|
|
10
9
|
constructor (port) {
|
|
11
|
-
this.consoleLogger = new EggConsoleLogger();
|
|
12
10
|
port = port ? parseInt(port) : this.getSocketcPort();
|
|
13
11
|
|
|
14
12
|
assert(typeof port === 'number', 'port required, and must be a number');
|
|
15
|
-
this.consoleLogger.info('[ee-core:socket:client] start client');
|
|
16
13
|
|
|
17
14
|
const url = 'http://127.0.0.1:' + port;
|
|
18
|
-
|
|
15
|
+
console.log('[ee-core] [module/socket/socketClient] url:', url);
|
|
19
16
|
this.client = IoClient(url);
|
|
20
17
|
}
|
|
21
18
|
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
const assert = require('assert');
|
|
4
4
|
const { Server } = require('socket.io');
|
|
5
|
-
const EggConsoleLogger = require('egg-logger').EggConsoleLogger;
|
|
6
5
|
const is = require('is-type-of');
|
|
7
6
|
const Storage = require('../storage');
|
|
8
7
|
const Constants = require('../const');
|
|
8
|
+
const Log = require('../log');
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* socket server
|
|
@@ -14,7 +14,6 @@ class SocketServer {
|
|
|
14
14
|
constructor (app) {
|
|
15
15
|
this.app = app;
|
|
16
16
|
const options = this.app.config.socketServer;
|
|
17
|
-
this.consoleLogger = new EggConsoleLogger();
|
|
18
17
|
|
|
19
18
|
if (!options.enable) {
|
|
20
19
|
return;
|
|
@@ -22,7 +21,7 @@ class SocketServer {
|
|
|
22
21
|
|
|
23
22
|
let port = process.env.EE_SOCKET_PORT ? parseInt(process.env.EE_SOCKET_PORT) : parseInt(this.getSocketPort());
|
|
24
23
|
assert(typeof port === 'number', 'socekt port required, and must be a number');
|
|
25
|
-
this.consoleLogger.info('[ee-core
|
|
24
|
+
this.consoleLogger.info('[ee-core] [module/socket/socketServer] port is:', port);
|
|
26
25
|
|
|
27
26
|
// let opt = Object.assign({}, options);
|
|
28
27
|
// delete opt.enable;
|
|
@@ -32,11 +31,10 @@ class SocketServer {
|
|
|
32
31
|
|
|
33
32
|
connec () {
|
|
34
33
|
const self = this;
|
|
35
|
-
this.consoleLogger.info('[ee-core:socket:server] connection .....');
|
|
36
34
|
this.io.on('connection', (socket) => {
|
|
37
35
|
const channel = Constants.socketIo.channel.partySoftware;
|
|
38
36
|
socket.on(channel, async (message, callback) => {
|
|
39
|
-
|
|
37
|
+
console.log('[ee-core] [module/socket/socketServer] socket id:' + socket.id + ' message cmd: ' + message.cmd);
|
|
40
38
|
|
|
41
39
|
try {
|
|
42
40
|
// 找函数
|
|
@@ -57,7 +55,7 @@ class SocketServer {
|
|
|
57
55
|
const result = await fn.call(self.app, args);
|
|
58
56
|
callback(result);
|
|
59
57
|
} catch (err) {
|
|
60
|
-
|
|
58
|
+
Log.coreLogger.error('[ee-core] [module/socket/socketServer] throw error:', err);
|
|
61
59
|
}
|
|
62
60
|
});
|
|
63
61
|
});
|
package/module/utils/index.js
CHANGED
|
@@ -1,24 +1,14 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
|
-
const eis = require('electron-is');
|
|
3
2
|
const Storage = require('../storage');
|
|
4
3
|
const Constants = require('../const');
|
|
5
4
|
const Ps = require('./ps');
|
|
6
|
-
const Helper = require('./helper');
|
|
7
5
|
const UtilsJson = require('./json');
|
|
8
|
-
const Copy = require('./copyto');
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* other module
|
|
12
|
-
*/
|
|
13
|
-
Copy(Ps)
|
|
14
|
-
.and(Helper)
|
|
15
|
-
.to(exports);
|
|
16
6
|
|
|
17
7
|
/**
|
|
18
8
|
* 获取项目根目录package.json
|
|
19
9
|
*/
|
|
20
10
|
exports.getPackage = function() {
|
|
21
|
-
const json = UtilsJson.readSync(path.join(
|
|
11
|
+
const json = UtilsJson.readSync(path.join(Ps.getHomeDir(), 'package.json'));
|
|
22
12
|
|
|
23
13
|
return json;
|
|
24
14
|
};
|
|
@@ -93,28 +83,4 @@ exports.getSocketChannel = function() {
|
|
|
93
83
|
return Constants.socketIo.channel;
|
|
94
84
|
}
|
|
95
85
|
|
|
96
|
-
/**
|
|
97
|
-
* 获取 额外资源目录
|
|
98
|
-
*/
|
|
99
|
-
exports.getExtraResourcesDir = function() {
|
|
100
|
-
const execDir = this.getExecDir();
|
|
101
|
-
const isPackaged = this.isPackaged();
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
// 资源路径不同
|
|
105
|
-
let dir = '';
|
|
106
|
-
if (isPackaged) {
|
|
107
|
-
// 打包后 execDir为 应用程序 exe\dmg\dep软件所在目录;打包前该值是项目根目录
|
|
108
|
-
// windows和MacOs不一样
|
|
109
|
-
dir = path.join(execDir, "resources", "extraResources");
|
|
110
|
-
if (eis.macOS()) {
|
|
111
|
-
dir = path.join(execDir, "..", "Resources", "extraResources");
|
|
112
|
-
}
|
|
113
|
-
} else {
|
|
114
|
-
// 打包前
|
|
115
|
-
dir = path.join(execDir, "build", "extraResources");
|
|
116
|
-
}
|
|
117
|
-
return dir;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
86
|
|
package/module/utils/ps.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
|
+
const eis = require('electron-is');
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* 当前进程的所有env
|
|
@@ -125,6 +126,30 @@ exports.getElectronDir = function() {
|
|
|
125
126
|
return process.env.EE_BASE_DIR;
|
|
126
127
|
}
|
|
127
128
|
|
|
129
|
+
/**
|
|
130
|
+
* 获取 额外资源目录
|
|
131
|
+
*/
|
|
132
|
+
exports.getExtraResourcesDir = function() {
|
|
133
|
+
const execDir = this.getExecDir();
|
|
134
|
+
const isPackaged = this.isPackaged();
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
// 资源路径不同
|
|
138
|
+
let dir = '';
|
|
139
|
+
if (isPackaged) {
|
|
140
|
+
// 打包后 execDir为 应用程序 exe\dmg\dep软件所在目录;打包前该值是项目根目录
|
|
141
|
+
// windows和MacOs不一样
|
|
142
|
+
dir = path.join(execDir, "resources", "extraResources");
|
|
143
|
+
if (eis.macOS()) {
|
|
144
|
+
dir = path.join(execDir, "..", "Resources", "extraResources");
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
// 打包前
|
|
148
|
+
dir = path.join(execDir, "build", "extraResources");
|
|
149
|
+
}
|
|
150
|
+
return dir;
|
|
151
|
+
}
|
|
152
|
+
|
|
128
153
|
/**
|
|
129
154
|
* 获取 appUserData目录
|
|
130
155
|
*/
|
package/package.json
CHANGED
package/tools/encrypt.js
CHANGED
|
@@ -7,7 +7,7 @@ const is = require('is-type-of');
|
|
|
7
7
|
const bytenode = require('bytenode');
|
|
8
8
|
const crypto = require('crypto');
|
|
9
9
|
const JavaScriptObfuscator = require('javascript-obfuscator');
|
|
10
|
-
const
|
|
10
|
+
const UtilsJson = require('../module/utils/json');
|
|
11
11
|
|
|
12
12
|
class Encrypt {
|
|
13
13
|
constructor() {
|
|
@@ -41,20 +41,20 @@ class Encrypt {
|
|
|
41
41
|
this.dirs.push(directory[i]);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
console.log('[ee-core] [encrypt] dirs:', this.dirs);
|
|
44
|
+
console.log('[ee-core] [tools/encrypt] dirs:', this.dirs);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* 备份 electron 目录代码
|
|
49
49
|
*/
|
|
50
50
|
backup () {
|
|
51
|
-
console.log('[ee-core] [encrypt] backup start');
|
|
51
|
+
console.log('[ee-core] [tools/encrypt] backup start');
|
|
52
52
|
|
|
53
53
|
for (let i = 0; i < this.dirs.length; i++) {
|
|
54
54
|
// check code dir
|
|
55
55
|
let codeDirPath = path.join(this.basePath, this.dirs[i]);
|
|
56
56
|
if (!fs.existsSync(codeDirPath)) {
|
|
57
|
-
console.log('[ee-core] [encrypt] ERROR: backup %s is not exist', codeDirPath);
|
|
57
|
+
console.log('[ee-core] [tools/encrypt] ERROR: backup %s is not exist', codeDirPath);
|
|
58
58
|
return
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -64,7 +64,7 @@ class Encrypt {
|
|
|
64
64
|
this.rmBackup(targetDir);
|
|
65
65
|
|
|
66
66
|
// copy
|
|
67
|
-
console.log('[ee-core] [encrypt] backup target Dir:', targetDir);
|
|
67
|
+
console.log('[ee-core] [tools/encrypt] backup target Dir:', targetDir);
|
|
68
68
|
if (!fs.existsSync(targetDir)) {
|
|
69
69
|
this.mkdir(targetDir);
|
|
70
70
|
this.chmodPath(targetDir, '777');
|
|
@@ -72,7 +72,7 @@ class Encrypt {
|
|
|
72
72
|
|
|
73
73
|
fsPro.copySync(codeDirPath, targetDir);
|
|
74
74
|
}
|
|
75
|
-
console.log('[ee-core] [encrypt] backup end');
|
|
75
|
+
console.log('[ee-core] [tools/encrypt] backup end');
|
|
76
76
|
return true;
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -86,7 +86,7 @@ class Encrypt {
|
|
|
86
86
|
const content = {
|
|
87
87
|
nameMap: {}
|
|
88
88
|
};
|
|
89
|
-
|
|
89
|
+
UtilsJson.writeSync(this.tmpFile, content);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -97,13 +97,13 @@ class Encrypt {
|
|
|
97
97
|
* 加密代码
|
|
98
98
|
*/
|
|
99
99
|
encrypt () {
|
|
100
|
-
console.log('[ee-core] [encrypt] start ciphering');
|
|
100
|
+
console.log('[ee-core] [tools/encrypt] start ciphering');
|
|
101
101
|
for (let i = 0; i < this.dirs.length; i++) {
|
|
102
102
|
let codeDirPath = path.join(this.encryptCodeDir, this.dirs[i]);
|
|
103
103
|
this.loop(codeDirPath);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
console.log('[ee-core] [encrypt] end ciphering');
|
|
106
|
+
console.log('[ee-core] [tools/encrypt] end ciphering');
|
|
107
107
|
};
|
|
108
108
|
|
|
109
109
|
/**
|
|
@@ -183,7 +183,7 @@ class Encrypt {
|
|
|
183
183
|
*/
|
|
184
184
|
rmBackup (dir) {
|
|
185
185
|
if (fs.existsSync(dir)) {
|
|
186
|
-
console.log('[ee-core] [encrypt] clean old directory:', dir);
|
|
186
|
+
console.log('[ee-core] [tools/encrypt] clean old directory:', dir);
|
|
187
187
|
fsPro.removeSync(dir);
|
|
188
188
|
}
|
|
189
189
|
return;
|
package/tools/replaceDist.js
CHANGED
|
@@ -14,7 +14,7 @@ const fsPro = require('fs-extra');
|
|
|
14
14
|
* 执行
|
|
15
15
|
*/
|
|
16
16
|
run () {
|
|
17
|
-
console.log('[ee-core] [
|
|
17
|
+
console.log('[ee-core] [tools/rd] 开始移动资源');
|
|
18
18
|
const homeDir = process.cwd();
|
|
19
19
|
|
|
20
20
|
// argv
|
|
@@ -30,7 +30,7 @@ const fsPro = require('fs-extra');
|
|
|
30
30
|
try {
|
|
31
31
|
return fs.statSync(filePath).isFile();
|
|
32
32
|
} catch (err) {
|
|
33
|
-
console.error('[ee-core] [
|
|
33
|
+
console.error('[ee-core] [tools/rd] ERROR ', err);
|
|
34
34
|
return false;
|
|
35
35
|
}
|
|
36
36
|
};
|
|
@@ -39,7 +39,7 @@ const fsPro = require('fs-extra');
|
|
|
39
39
|
const sourceIndexFile = path.join(sourceDir, 'index.html');
|
|
40
40
|
|
|
41
41
|
if (!fileExist(sourceIndexFile)) {
|
|
42
|
-
console.error('[ee-core] [
|
|
42
|
+
console.error('[ee-core] [tools/rd] ERROR 前端资源不存在,请构建!!!');
|
|
43
43
|
return
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -48,12 +48,12 @@ const fsPro = require('fs-extra');
|
|
|
48
48
|
|
|
49
49
|
// 清空历史资源
|
|
50
50
|
fs.rmdirSync(eeResourceDir, {recursive: true});
|
|
51
|
-
console.log('[ee-core] [
|
|
51
|
+
console.log('[ee-core] [tools/rd] 清空历史资源:', eeResourceDir);
|
|
52
52
|
|
|
53
53
|
fsPro.copySync(sourceDir, eeResourceDir);
|
|
54
|
-
console.log('[ee-core] [
|
|
54
|
+
console.log('[ee-core] [tools/rd] 复制资源到:', eeResourceDir);
|
|
55
55
|
|
|
56
|
-
console.log('[ee-core] [
|
|
56
|
+
console.log('[ee-core] [tools/rd] 结束');
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
package/utils/index.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
const path = require('path');
|
|
6
|
-
const eis = require('electron-is');
|
|
7
6
|
const UtilsJson = require('../module/utils/json');
|
|
8
7
|
const UtilsPs = require('../module/utils/ps');
|
|
9
8
|
const UtilsHelper = require('../module/utils/helper');
|
|
@@ -105,25 +104,3 @@ exports.getSocketPort = function() {
|
|
|
105
104
|
exports.getSocketChannel = function() {
|
|
106
105
|
return Constants.socketIo.channel;
|
|
107
106
|
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* 获取 额外资源目录
|
|
111
|
-
*/
|
|
112
|
-
exports.getExtraResourcesDir = function() {
|
|
113
|
-
const execDir = this.getExecDir();
|
|
114
|
-
|
|
115
|
-
// 资源路径不同
|
|
116
|
-
let dir = '';
|
|
117
|
-
if (config.isPackaged) {
|
|
118
|
-
// 打包后 execDir为 应用程序 exe\dmg\dep软件所在目录;打包前该值是项目根目录
|
|
119
|
-
// windows和MacOs不一样
|
|
120
|
-
dir = path.join(execDir, "resources", "extraResources");
|
|
121
|
-
if (eis.macOS()) {
|
|
122
|
-
dir = path.join(execDir, "..", "Resources", "extraResources");
|
|
123
|
-
}
|
|
124
|
-
} else {
|
|
125
|
-
// 打包前
|
|
126
|
-
dir = path.join(execDir, "build", "extraResources");
|
|
127
|
-
}
|
|
128
|
-
return dir;
|
|
129
|
-
}
|