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.
- package/app/application.js +31 -0
- package/app/boot.js +81 -0
- package/app/dir.js +27 -0
- package/app/events.js +56 -0
- package/app/index.js +7 -0
- package/config/config_loader.js +19 -23
- package/config/default_config.js +110 -0
- package/config/index.js +20 -37
- package/const/channel.js +26 -16
- package/const/index.js +0 -4
- package/controller/controller_loader.js +78 -0
- package/controller/index.js +18 -19
- package/core/index.js +6 -5
- package/core/{lib/loader → loader}/file_loader.js +39 -156
- package/core/utils/index.js +83 -0
- package/core/{lib/utils → utils}/timing.js +3 -2
- package/cross/cross.js +152 -0
- package/cross/index.js +6 -181
- package/cross/spawnProcess.js +34 -51
- package/electron/app/index.js +38 -54
- package/electron/index.js +13 -17
- package/electron/window/index.js +260 -65
- package/exception/index.js +34 -32
- package/html/index.js +7 -10
- package/index.js +4 -52
- package/jobs/child/app.js +10 -10
- package/jobs/child/forkProcess.js +29 -45
- package/jobs/child/index.js +13 -10
- package/jobs/child-pool/index.js +13 -11
- package/jobs/index.js +2 -4
- package/loader/index.js +91 -143
- package/log/index.js +74 -57
- package/log/logger.js +75 -80
- package/message/childMessage.js +13 -13
- package/message/index.js +7 -16
- package/package.json +2 -2
- package/ps/index.js +136 -229
- package/socket/httpServer.js +46 -43
- package/socket/index.js +52 -69
- package/socket/ipcServer.js +80 -94
- package/socket/socketServer.js +31 -24
- package/storage/index.js +5 -37
- package/storage/sqliteStorage.js +18 -18
- package/utils/extend.js +10 -5
- package/utils/helper.js +38 -42
- package/utils/index.js +40 -23
- package/utils/ip.js +5 -45
- package/utils/is.js +107 -141
- package/utils/json.js +15 -7
- package/utils/pargv.js +5 -1
- package/utils/{get-port → port}/index.js +4 -26
- package/utils/wrap.js +8 -3
- package/addon/index.js +0 -35
- package/addon/window/index.js +0 -99
- package/bin/tools.js +0 -8
- package/config/cache.js +0 -62
- package/config/config.default.js +0 -331
- package/controller/baseContextClass.js +0 -25
- package/core/lib/ee.js +0 -216
- package/core/lib/loader/context_loader.js +0 -106
- package/core/lib/loader/ee_loader.js +0 -435
- package/core/lib/loader/mixin/addon.js +0 -32
- package/core/lib/loader/mixin/config.js +0 -130
- package/core/lib/loader/mixin/controller.js +0 -125
- package/core/lib/loader/mixin/service.js +0 -28
- package/core/lib/utils/base_context_class.js +0 -34
- package/core/lib/utils/function.js +0 -30
- package/core/lib/utils/index.js +0 -133
- package/core/lib/utils/sequencify.js +0 -59
- package/ee/appLoader.js +0 -48
- package/ee/application.js +0 -101
- package/ee/baseApp.js +0 -99
- package/ee/eeApp.js +0 -406
- package/ee/index.js +0 -58
- package/electron/window/winState.js +0 -186
- package/httpclient/index.js +0 -161
- package/jobs/baseJobClass.js +0 -16
- package/jobs/renderer/index.js +0 -141
- package/jobs/renderer/loadView.js +0 -41
- package/jobs/unification.js +0 -64
- package/main/index.js +0 -57
- package/old-utils/index.js +0 -91
- package/services/baseContextClass.js +0 -24
- package/services/index.js +0 -41
- package/socket/io.js +0 -28
- package/storage/jsondb/adapters/Base.js +0 -23
- package/storage/jsondb/adapters/FileSync.js +0 -64
- package/storage/jsondb/main.js +0 -55
- package/storage/jsondbStorage.js +0 -196
- package/utils/co.js +0 -237
- package/utils/copyto.js +0 -161
- package/utils/depd/index.js +0 -538
- package/utils/depd/lib/browser/index.js +0 -77
- package/utils/get-port/index.d.ts +0 -64
- package/utils/time/index.js +0 -20
- package/utils/time/ms.js +0 -162
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const debug = require('debug')('ee-core:app:appliaction');
|
|
4
|
+
const { loadController } = require('../controller');
|
|
5
|
+
const { eventBus, Ready } = require('./events');
|
|
6
|
+
const { loadSocket } = require('../socket');
|
|
7
|
+
const { loadElectron } = require('../electron');
|
|
8
|
+
|
|
9
|
+
class Appliaction {
|
|
10
|
+
constructor() {
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
register(eventName, handler) {
|
|
15
|
+
return eventBus.register(eventName, handler);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
run() {
|
|
19
|
+
loadController();
|
|
20
|
+
loadSocket();
|
|
21
|
+
eventBus.emitLifecycle(Ready);
|
|
22
|
+
loadElectron();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const app = new Appliaction();
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
Appliaction,
|
|
30
|
+
app,
|
|
31
|
+
};
|
package/app/boot.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const debug = require('debug')('ee-core:app:boot');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { loadException } = require('../exception');
|
|
6
|
+
const { electronApp } = require('../electron/app');
|
|
7
|
+
const { getArgumentByName, getBundleDir } = require('../ps');
|
|
8
|
+
const { loadConfig } = require('../config');
|
|
9
|
+
const { loadLog } = require('../log');
|
|
10
|
+
const { app } = require('./application');
|
|
11
|
+
const { loadDir } = require('./dir');
|
|
12
|
+
// const { isJsProject } = require('../utils');
|
|
13
|
+
|
|
14
|
+
class ElectronEgg {
|
|
15
|
+
constructor() {
|
|
16
|
+
const baseDir = electronApp.getAppPath();
|
|
17
|
+
const { env } = process;
|
|
18
|
+
const environmet = getArgumentByName('env') || 'prod';
|
|
19
|
+
console.log('argv:', process.argv);
|
|
20
|
+
|
|
21
|
+
const options = {
|
|
22
|
+
env: environmet,
|
|
23
|
+
baseDir,
|
|
24
|
+
electronDir: getBundleDir(baseDir),
|
|
25
|
+
appName: electronApp.getName(),
|
|
26
|
+
userHome: electronApp.getPath('home'),
|
|
27
|
+
appData: electronApp.getPath('appData'),
|
|
28
|
+
appUserData: electronApp.getPath('userData'),
|
|
29
|
+
appVersion: electronApp.getVersion(),
|
|
30
|
+
isPackaged: electronApp.isPackaged,
|
|
31
|
+
execDir: baseDir,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// exec directory (exe dmg dep) for prod
|
|
35
|
+
if (environmet == 'prod' && options.isPackaged) {
|
|
36
|
+
options.execDir = path.dirname(electronApp.getPath('exe'));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// js开发环境使用源码目录
|
|
40
|
+
// if (isJsProject(baseDir) && environmet !== 'prod' ) {
|
|
41
|
+
// options.electronDir = path.join(baseDir, 'electron');
|
|
42
|
+
// }
|
|
43
|
+
|
|
44
|
+
// normalize env
|
|
45
|
+
env.EE_ENV = environmet;
|
|
46
|
+
env.EE_APP_NAME = options.appName;
|
|
47
|
+
env.EE_APP_VERSION = options.appVersion;
|
|
48
|
+
env.EE_BASE_DIR = options.baseDir;
|
|
49
|
+
env.EE_ELECTRON_DIR = options.electronDir;
|
|
50
|
+
env.EE_USER_HOME = options.userHome;
|
|
51
|
+
env.EE_APP_DATA = options.appData;
|
|
52
|
+
env.EE_APP_USER_DATA = options.appUserData;
|
|
53
|
+
env.EE_EXEC_DIR = options.execDir;
|
|
54
|
+
env.EE_IS_PACKAGED = options.isPackaged;
|
|
55
|
+
env.EE_SOCKET_PORT = null;
|
|
56
|
+
env.EE_HTTP_PORT = null;
|
|
57
|
+
debug('[constructor] options:%j', options)
|
|
58
|
+
|
|
59
|
+
this.init();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
init() {
|
|
63
|
+
// basic functions
|
|
64
|
+
loadException();
|
|
65
|
+
loadConfig();
|
|
66
|
+
loadDir();
|
|
67
|
+
loadLog();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
register(eventName, handler) {
|
|
71
|
+
return app.register(eventName, handler);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
run() {
|
|
75
|
+
app.run();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
module.exports = {
|
|
80
|
+
ElectronEgg,
|
|
81
|
+
};
|
package/app/dir.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const { getUserHomeHiddenAppDir, getLogDir, getDataDir } = require('../ps');
|
|
5
|
+
const { mkdir } = require('../utils/helper');
|
|
6
|
+
function loadDir() {
|
|
7
|
+
initDir();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function initDir() {
|
|
11
|
+
const homeHiddenAppDir = getUserHomeHiddenAppDir();
|
|
12
|
+
if (!fs.existsSync(homeHiddenAppDir)) {
|
|
13
|
+
mkdir(homeHiddenAppDir, { mode: 0o755 });
|
|
14
|
+
}
|
|
15
|
+
const dataDir = getDataDir();
|
|
16
|
+
if (!fs.existsSync(dataDir)) {
|
|
17
|
+
mkdir(dataDir, { mode: 0o755 });
|
|
18
|
+
}
|
|
19
|
+
const logDir = getLogDir();
|
|
20
|
+
if (!fs.existsSync(logDir)) {
|
|
21
|
+
mkdir(logDir, { mode: 0o755 });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = {
|
|
26
|
+
loadDir
|
|
27
|
+
};
|
package/app/events.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Ready = "ready";
|
|
4
|
+
const ElectronAppReady = "electron-app-ready";
|
|
5
|
+
const WindowReady = "window-ready";
|
|
6
|
+
const BeforeClose = "before-close";
|
|
7
|
+
const Preload = "preload";
|
|
8
|
+
|
|
9
|
+
class EventBus {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.lifecycleEvents = {};
|
|
12
|
+
this.eventsMap = {};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// add lifecycle event
|
|
16
|
+
register(eventName, handler) {
|
|
17
|
+
if (!this.lifecycleEvents[eventName]) {
|
|
18
|
+
this.lifecycleEvents[eventName] = handler;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// call lifecycle event
|
|
23
|
+
emitLifecycle(eventName, ...args) {
|
|
24
|
+
const eventFn = this.lifecycleEvents[eventName];
|
|
25
|
+
if (eventFn) {
|
|
26
|
+
eventFn(...args);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// add listener
|
|
31
|
+
on(eventName, handler) {
|
|
32
|
+
if (!this.eventsMap[eventName]) {
|
|
33
|
+
this.eventsMap[eventName] = handler;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// emit listener
|
|
38
|
+
emit(eventName, ...args) {
|
|
39
|
+
const eventFn = this.eventsMap[eventName];
|
|
40
|
+
if (eventFn) {
|
|
41
|
+
eventFn(...args);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const eventBus = new EventBus();
|
|
47
|
+
|
|
48
|
+
module.exports = {
|
|
49
|
+
EventBus,
|
|
50
|
+
eventBus,
|
|
51
|
+
Ready,
|
|
52
|
+
ElectronAppReady,
|
|
53
|
+
WindowReady,
|
|
54
|
+
Preload,
|
|
55
|
+
BeforeClose
|
|
56
|
+
};
|
package/app/index.js
ADDED
package/config/config_loader.js
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
const debug = require('debug')('ee-core:config:config_loader');
|
|
4
4
|
const path = require('path');
|
|
5
|
-
const
|
|
6
|
-
const extend = require('../utils/extend');
|
|
7
|
-
const
|
|
8
|
-
const
|
|
5
|
+
const { appName, env, getElectronDir, getBaseDir, getRootDir } = require('../ps');
|
|
6
|
+
const { extend } = require('../utils/extend');
|
|
7
|
+
const { loadFile } = require('../loader');
|
|
8
|
+
const { Timing } = require('../core/utils/timing');
|
|
9
|
+
const defaultConfig = require('./default_config');
|
|
9
10
|
|
|
10
11
|
class ConfigLoader {
|
|
11
12
|
constructor() {
|
|
12
13
|
this.timing = new Timing();
|
|
13
|
-
this.config = {};
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -21,21 +21,24 @@ class ConfigLoader {
|
|
|
21
21
|
|
|
22
22
|
// Load Application config
|
|
23
23
|
const appConfig = this._AppConfig();
|
|
24
|
-
debug("[load] appConfig: %
|
|
25
|
-
|
|
24
|
+
// debug("[load] appConfig: %O", appConfig);
|
|
25
|
+
|
|
26
|
+
const defaultConf = defaultConfig();
|
|
27
|
+
const config = extend(true, defaultConf, appConfig);
|
|
28
|
+
debug("[load] config: %o", config);
|
|
26
29
|
|
|
27
30
|
this.timing.end('Load Config');
|
|
28
|
-
return
|
|
31
|
+
return config;
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
_AppConfig() {
|
|
32
35
|
const names = [
|
|
33
36
|
'config.default',
|
|
34
|
-
`config.${
|
|
37
|
+
`config.${env()}`,
|
|
35
38
|
];
|
|
36
39
|
const target = {};
|
|
37
40
|
for (const filename of names) {
|
|
38
|
-
const config = this._loadConfig(
|
|
41
|
+
const config = this._loadConfig(getElectronDir(), filename);
|
|
39
42
|
extend(true, target, config);
|
|
40
43
|
}
|
|
41
44
|
return target;
|
|
@@ -43,21 +46,14 @@ class ConfigLoader {
|
|
|
43
46
|
|
|
44
47
|
_loadConfig(dirpath, filename) {
|
|
45
48
|
const appInfo = {
|
|
46
|
-
name:
|
|
47
|
-
baseDir:
|
|
48
|
-
electronDir:
|
|
49
|
-
env:
|
|
50
|
-
|
|
51
|
-
root: Ps.getRootDir(),
|
|
52
|
-
appUserDataDir: Ps.getAppUserDataDir(),
|
|
53
|
-
userHome: Ps.getUserHomeDir(),
|
|
54
|
-
appVersion: Ps.appVersion(),
|
|
55
|
-
isPackaged: Ps.isPackaged(),
|
|
56
|
-
isEncrypted: Ps.isEncrypted(),
|
|
57
|
-
execDir: Ps.getExecDir(),
|
|
49
|
+
name: appName(),
|
|
50
|
+
baseDir: getBaseDir(),
|
|
51
|
+
electronDir: getElectronDir(),
|
|
52
|
+
env: env(),
|
|
53
|
+
root: getRootDir(),
|
|
58
54
|
}
|
|
59
55
|
const filepath = path.join(dirpath, 'config', filename);
|
|
60
|
-
const config =
|
|
56
|
+
const config = loadFile(filepath, appInfo);
|
|
61
57
|
debug("[_loadConfig] filepath: %s", filepath);
|
|
62
58
|
if (!config) return null;
|
|
63
59
|
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { env, getBaseDir, getLogDir } = require('../ps');
|
|
5
|
+
const { SocketIO } = require('../const/channel');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* default
|
|
9
|
+
*/
|
|
10
|
+
module.exports = () => {
|
|
11
|
+
return {
|
|
12
|
+
openDevTools: false,
|
|
13
|
+
singleLock: true,
|
|
14
|
+
windowsOption: {
|
|
15
|
+
title: 'electron-egg',
|
|
16
|
+
width: 980,
|
|
17
|
+
height: 650,
|
|
18
|
+
minWidth: 400,
|
|
19
|
+
minHeight: 300,
|
|
20
|
+
webPreferences: {
|
|
21
|
+
//webSecurity: false,
|
|
22
|
+
contextIsolation: false, // false -> 可在渲染进程中使用electron的api,true->需要bridge.js(contextBridge)
|
|
23
|
+
nodeIntegration: true,
|
|
24
|
+
//preload: path.join(appInfo.electronDir, 'preload', 'bridge.js'),
|
|
25
|
+
},
|
|
26
|
+
frame: true,
|
|
27
|
+
show: false,
|
|
28
|
+
icon: path.join(getBaseDir(), 'public', 'images', 'logo-32.png'),
|
|
29
|
+
},
|
|
30
|
+
logger: {
|
|
31
|
+
type: 'application',
|
|
32
|
+
dir: getLogDir(),
|
|
33
|
+
encoding: 'utf8',
|
|
34
|
+
env: env(),
|
|
35
|
+
level: 'INFO',
|
|
36
|
+
consoleLevel: 'INFO',
|
|
37
|
+
disableConsoleAfterReady: env() !== 'local',
|
|
38
|
+
outputJSON: false,
|
|
39
|
+
buffer: true,
|
|
40
|
+
appLogName: `ee.log`,
|
|
41
|
+
coreLogName: 'ee-core.log',
|
|
42
|
+
agentLogName: 'ee-agent.log',
|
|
43
|
+
errorLogName: `ee-error.log`,
|
|
44
|
+
coreLogger: {},
|
|
45
|
+
allowDebugAtProd: false,
|
|
46
|
+
enablePerformanceTimer: false,
|
|
47
|
+
rotator: 'day',
|
|
48
|
+
},
|
|
49
|
+
socketServer: {
|
|
50
|
+
enable: false, // is it enabled
|
|
51
|
+
port: 7070, // default port (if the port is in use, randomly select one)
|
|
52
|
+
path: "/socket.io/", // path
|
|
53
|
+
connectTimeout: 45000, // client connection timeout
|
|
54
|
+
pingTimeout: 30000, // heartbeat detection timeout
|
|
55
|
+
pingInterval: 25000, // heartbeat detection interval
|
|
56
|
+
maxHttpBufferSize: 1e8, // the data size of each message 1M
|
|
57
|
+
transports: ["polling", "websocket"], // http polling or websocket
|
|
58
|
+
cors: {
|
|
59
|
+
origin: true, // http协议时,要设置跨域 类型 Boolean String RegExp Array Function
|
|
60
|
+
},
|
|
61
|
+
channel: SocketIO.partySoftware
|
|
62
|
+
},
|
|
63
|
+
httpServer: {
|
|
64
|
+
enable: false, // Is it enabled
|
|
65
|
+
https: {
|
|
66
|
+
enable: false,
|
|
67
|
+
key: '/public/ssl/localhost+1.key',
|
|
68
|
+
cert: '/public/ssl/localhost+1.pem'
|
|
69
|
+
},
|
|
70
|
+
protocol: 'http://',
|
|
71
|
+
host: '127.0.0.1',
|
|
72
|
+
port: 7071, // Default port (if the port is in use, randomly select one)
|
|
73
|
+
cors: {
|
|
74
|
+
origin: "*"
|
|
75
|
+
},
|
|
76
|
+
body: {
|
|
77
|
+
multipart: true,
|
|
78
|
+
formidable: {
|
|
79
|
+
keepExtensions: true
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
filterRequest: {
|
|
83
|
+
uris: [
|
|
84
|
+
'favicon.ico'
|
|
85
|
+
],
|
|
86
|
+
returnData: ''
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
remote: {
|
|
90
|
+
enable: false,
|
|
91
|
+
url: ''
|
|
92
|
+
},
|
|
93
|
+
mainServer: {
|
|
94
|
+
protocol: 'file://', // file://
|
|
95
|
+
indexPath: '/public/dist/index.html',
|
|
96
|
+
options: {},
|
|
97
|
+
takeover: '',
|
|
98
|
+
loadingPage: '',
|
|
99
|
+
},
|
|
100
|
+
exception: {
|
|
101
|
+
mainExit: false,
|
|
102
|
+
childExit: true,
|
|
103
|
+
rendererExit: true,
|
|
104
|
+
},
|
|
105
|
+
jobs: {
|
|
106
|
+
messageLog: false
|
|
107
|
+
},
|
|
108
|
+
cross: {}
|
|
109
|
+
}
|
|
110
|
+
}
|
package/config/index.js
CHANGED
|
@@ -1,42 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const { ConfigLoader } = require('./config_loader');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
all() {
|
|
9
|
-
const cacheValue = ConfigCache.all();
|
|
10
|
-
return cacheValue;
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* getValue
|
|
15
|
-
*/
|
|
16
|
-
getValue(key) {
|
|
17
|
-
const cacheValue = ConfigCache.getValue(key);
|
|
18
|
-
return cacheValue;
|
|
19
|
-
},
|
|
5
|
+
const Instance = {
|
|
6
|
+
config: null,
|
|
7
|
+
};
|
|
20
8
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
return false;
|
|
29
|
-
},
|
|
9
|
+
function loadConfig() {
|
|
10
|
+
const configLoader = new ConfigLoader();
|
|
11
|
+
Instance["config"] = configLoader.load();
|
|
12
|
+
return Instance["config"];
|
|
13
|
+
}
|
|
30
14
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
return false;
|
|
39
|
-
},
|
|
40
|
-
};
|
|
15
|
+
function getConfig() {
|
|
16
|
+
if (!Instance["config"]) {
|
|
17
|
+
loadConfig();
|
|
18
|
+
};
|
|
19
|
+
return Instance["config"];
|
|
20
|
+
}
|
|
41
21
|
|
|
42
|
-
module.exports =
|
|
22
|
+
module.exports = {
|
|
23
|
+
loadConfig,
|
|
24
|
+
getConfig,
|
|
25
|
+
};
|
package/const/channel.js
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Processes = {
|
|
4
|
+
showException: 'ee#showException',
|
|
5
|
+
sendToMain: 'ee#sendToMain'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const SocketIO = {
|
|
9
|
+
partySoftware: 'c1',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const Events = {
|
|
13
|
+
childProcessExit: 'ee#childProcess#exit',
|
|
14
|
+
childProcessError: 'ee#childProcess#error',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const Receiver = {
|
|
18
|
+
childJob: 'job',
|
|
19
|
+
forkProcess: 'task',
|
|
20
|
+
all: 'all'
|
|
21
|
+
}
|
|
22
|
+
|
|
1
23
|
module.exports = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
socketIo: {
|
|
7
|
-
partySoftware: 'c1',
|
|
8
|
-
},
|
|
9
|
-
events: {
|
|
10
|
-
childProcessExit: 'ee#childProcess#exit',
|
|
11
|
-
childProcessError: 'ee#childProcess#error',
|
|
12
|
-
},
|
|
13
|
-
receiver: {
|
|
14
|
-
childJob: 'job',
|
|
15
|
-
forkProcess: 'task',
|
|
16
|
-
all: 'all'
|
|
17
|
-
}
|
|
24
|
+
Processes,
|
|
25
|
+
SocketIO,
|
|
26
|
+
Events,
|
|
27
|
+
Receiver
|
|
18
28
|
};
|
package/const/index.js
CHANGED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const debug = require('debug')('ee-core:controller:controller_loader');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const is = require('is-type-of');
|
|
6
|
+
const { getElectronDir } = require('../ps');
|
|
7
|
+
const { Timing } = require('../core/utils/timing');
|
|
8
|
+
const { FileLoader, FULLPATH } = require('../core/loader/file_loader');
|
|
9
|
+
const { isBytecodeClass, callFn } = require('../core/utils');
|
|
10
|
+
|
|
11
|
+
class ControllerLoader {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.timing = new Timing();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Load controller/xxx.js
|
|
18
|
+
*/
|
|
19
|
+
load() {
|
|
20
|
+
this.timing.start('Load Controller');
|
|
21
|
+
|
|
22
|
+
const opt = {
|
|
23
|
+
caseStyle: 'lower',
|
|
24
|
+
directory: path.join(getElectronDir(), 'controller'),
|
|
25
|
+
initializer: (obj, opt) => {
|
|
26
|
+
if (is.class(obj) || isBytecodeClass(obj)) {
|
|
27
|
+
obj.prototype.pathName = opt.pathName;
|
|
28
|
+
obj.prototype.fullPath = opt.path;
|
|
29
|
+
return wrapClass(obj);
|
|
30
|
+
}
|
|
31
|
+
return obj;
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const target = new FileLoader(opt).load();
|
|
35
|
+
debug("[load] controllers: %o", target);
|
|
36
|
+
this.timing.end('Load Controller');
|
|
37
|
+
return target;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// wrap the class, yield a object with middlewares
|
|
42
|
+
function wrapClass(Controller) {
|
|
43
|
+
let proto = Controller.prototype;
|
|
44
|
+
const ret = {};
|
|
45
|
+
// tracing the prototype chain
|
|
46
|
+
while (proto !== Object.prototype) {
|
|
47
|
+
const keys = Object.getOwnPropertyNames(proto);
|
|
48
|
+
// debug("[wrapClass] keys:", keys);
|
|
49
|
+
for (const key of keys) {
|
|
50
|
+
// getOwnPropertyNames will return constructor
|
|
51
|
+
// that should be ignored
|
|
52
|
+
if (key === 'constructor') {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
// skip getter, setter & non-function properties
|
|
56
|
+
const d = Object.getOwnPropertyDescriptor(proto, key);
|
|
57
|
+
// prevent to override sub method
|
|
58
|
+
if (is.function(d.value) && !ret.hasOwnProperty(key)) {
|
|
59
|
+
ret[key] = methodToMiddleware(Controller, key);
|
|
60
|
+
ret[key][FULLPATH] = Controller.prototype.fullPath + '#' + Controller.name + '.' + key + '()';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
proto = Object.getPrototypeOf(proto);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return ret;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function methodToMiddleware(Controller, key) {
|
|
70
|
+
return function classControllerMiddleware(...args) {
|
|
71
|
+
const controller = new Controller();
|
|
72
|
+
return callFn(controller[key], args, controller);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = {
|
|
77
|
+
ControllerLoader
|
|
78
|
+
};
|
package/controller/index.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* BaseContextClass is a base class that can be extended,
|
|
5
|
-
* it's instantiated in context level,
|
|
6
|
-
*/
|
|
7
|
-
class BaseContextClass {
|
|
3
|
+
const { ControllerLoader } = require('./controller_loader');
|
|
8
4
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* @since 1.1.0
|
|
13
|
-
*/
|
|
14
|
-
constructor(ctx) {
|
|
5
|
+
const Instance = {
|
|
6
|
+
controller: null,
|
|
7
|
+
};
|
|
15
8
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
function loadController() {
|
|
10
|
+
const controllerLoader = new ControllerLoader();
|
|
11
|
+
Instance.controller = controllerLoader.load();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getController() {
|
|
15
|
+
if (!Instance.controller) {
|
|
16
|
+
loadController();
|
|
22
17
|
}
|
|
18
|
+
return Instance.controller;
|
|
23
19
|
}
|
|
24
20
|
|
|
25
|
-
module.exports =
|
|
21
|
+
module.exports = {
|
|
22
|
+
loadController,
|
|
23
|
+
getController
|
|
24
|
+
};
|
package/core/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const EeLoader = require('./loader/ee_loader');
|
|
4
|
+
const BaseContextClass = require('./utils/base_context_class');
|
|
5
|
+
const utils = require('./utils');
|
|
6
|
+
|
|
5
7
|
|
|
6
8
|
module.exports = {
|
|
7
|
-
EeCore,
|
|
8
9
|
EeLoader,
|
|
9
10
|
BaseContextClass,
|
|
10
11
|
utils,
|