ee-core 2.9.2 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +65 -65
- package/addon/index.js +34 -34
- package/addon/window/index.js +98 -98
- package/bin/tools.js +8 -8
- package/config/cache.js +41 -38
- package/config/config.default.js +331 -330
- package/config/index.js +75 -73
- package/const/channel.js +17 -17
- package/const/index.js +8 -8
- package/controller/baseContextClass.js +34 -34
- package/controller/index.js +34 -34
- package/core/index.js +10 -10
- package/core/lib/ee.js +216 -216
- package/core/lib/loader/context_loader.js +106 -106
- package/core/lib/loader/ee_loader.js +435 -435
- package/core/lib/loader/file_loader.js +326 -326
- package/core/lib/loader/mixin/addon.js +32 -32
- package/core/lib/loader/mixin/config.js +130 -130
- package/core/lib/loader/mixin/controller.js +125 -125
- package/core/lib/loader/mixin/service.js +28 -28
- package/core/lib/utils/base_context_class.js +34 -34
- package/core/lib/utils/function.js +30 -30
- package/core/lib/utils/index.js +133 -133
- package/core/lib/utils/sequencify.js +59 -59
- package/core/lib/utils/timing.js +77 -77
- package/cross/index.js +183 -183
- package/cross/spawnProcess.js +183 -183
- package/ee/appLoader.js +48 -48
- package/ee/application.js +99 -99
- package/ee/baseApp.js +103 -102
- package/ee/eeApp.js +408 -408
- package/ee/index.js +57 -57
- package/electron/app/index.js +64 -58
- package/electron/index.js +19 -19
- package/electron/window/index.js +73 -73
- package/electron/window/winState.js +186 -186
- package/exception/index.js +112 -112
- package/html/boot.html +98 -98
- package/html/cross-failure.html +28 -28
- package/html/failure.html +28 -28
- package/html/index.js +13 -13
- package/httpclient/index.js +161 -161
- package/index.js +54 -54
- package/jobs/baseJobClass.js +16 -16
- package/jobs/child/app.js +65 -65
- package/jobs/child/forkProcess.js +145 -145
- package/jobs/child/index.js +82 -82
- package/jobs/child-pool/index.js +213 -213
- package/jobs/index.js +8 -8
- package/jobs/load-balancer/algorithm/index.js +11 -11
- package/jobs/load-balancer/algorithm/minimumConnection.js +18 -18
- package/jobs/load-balancer/algorithm/polling.js +11 -11
- package/jobs/load-balancer/algorithm/random.js +9 -9
- package/jobs/load-balancer/algorithm/specify.js +14 -14
- package/jobs/load-balancer/algorithm/weights.js +21 -21
- package/jobs/load-balancer/algorithm/weightsMinimumConnection.js +29 -29
- package/jobs/load-balancer/algorithm/weightsPolling.js +22 -22
- package/jobs/load-balancer/algorithm/weightsRandom.js +16 -16
- package/jobs/load-balancer/consts.js +9 -9
- package/jobs/load-balancer/index.js +201 -201
- package/jobs/load-balancer/scheduler.js +31 -31
- package/jobs/renderer/index.js +141 -141
- package/jobs/renderer/loadView.js +40 -40
- package/jobs/unification.js +63 -63
- package/loader/index.js +172 -172
- package/log/index.js +68 -68
- package/log/logger.js +86 -80
- package/main/index.js +56 -56
- package/message/childMessage.js +54 -54
- package/message/index.js +18 -18
- package/old-utils/index.js +91 -91
- package/package.json +38 -38
- package/ps/index.js +371 -371
- package/services/baseContextClass.js +34 -34
- package/services/index.js +40 -40
- package/socket/httpServer.js +147 -147
- package/socket/index.js +81 -81
- package/socket/io.js +27 -27
- package/socket/ipcServer.js +112 -112
- package/socket/socketServer.js +69 -67
- package/storage/index.js +38 -38
- package/storage/jsondb/adapters/Base.js +23 -23
- package/storage/jsondb/adapters/FileSync.js +64 -52
- package/storage/jsondb/main.js +55 -42
- package/storage/jsondbStorage.js +195 -195
- package/storage/sqliteStorage.js +123 -123
- package/utils/co.js +237 -237
- package/utils/copyto.js +160 -160
- package/utils/depd/index.js +538 -538
- package/utils/depd/lib/browser/index.js +77 -77
- package/utils/extend.js +73 -73
- package/utils/get-port/index.d.ts +64 -64
- package/utils/get-port/index.js +148 -148
- package/utils/helper.js +220 -220
- package/utils/index.js +160 -160
- package/utils/ip.js +261 -261
- package/utils/is.js +145 -145
- package/utils/json.js +72 -72
- package/utils/pargv.js +263 -263
- package/utils/time/index.js +19 -19
- package/utils/time/ms.js +162 -162
- package/utils/wrap.js +35 -35
package/utils/index.js
CHANGED
|
@@ -1,160 +1,160 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const os = require("os");
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const { exec, execSync } = require('child_process');
|
|
7
|
-
const { createHash } = require('crypto');
|
|
8
|
-
const Ps = require('../ps');
|
|
9
|
-
const UtilsJson = require('./json');
|
|
10
|
-
|
|
11
|
-
// machine id
|
|
12
|
-
const { platform } = process;
|
|
13
|
-
const win32RegBinPath = {
|
|
14
|
-
native: '%windir%\\System32',
|
|
15
|
-
mixed: '%windir%\\sysnative\\cmd.exe /c %windir%\\System32'
|
|
16
|
-
};
|
|
17
|
-
const MachineGuid = {
|
|
18
|
-
darwin: 'ioreg -rd1 -c IOPlatformExpertDevice',
|
|
19
|
-
win32: `${win32RegBinPath[isWindowsProcessMixedOrNativeArchitecture()]}\\REG.exe ` +
|
|
20
|
-
'QUERY HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography ' +
|
|
21
|
-
'/v MachineGuid',
|
|
22
|
-
linux: '( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname ) | head -n 1 || :',
|
|
23
|
-
freebsd: 'kenv -q smbios.system.uuid || sysctl -n kern.hostuuid'
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* 获取项目根目录package.json
|
|
28
|
-
*/
|
|
29
|
-
exports.getPackage = function() {
|
|
30
|
-
const json = UtilsJson.readSync(path.join(Ps.getHomeDir(), 'package.json'));
|
|
31
|
-
|
|
32
|
-
return json;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Get the first proper MAC address
|
|
37
|
-
* @param iface If provided, restrict MAC address fetching to this interface
|
|
38
|
-
*/
|
|
39
|
-
exports.getMAC = function(iface) {
|
|
40
|
-
const zeroRegex = /(?:[0]{1,2}[:-]){5}[0]{1,2}/;
|
|
41
|
-
const list = os.networkInterfaces();
|
|
42
|
-
if (iface) {
|
|
43
|
-
const parts = list[iface];
|
|
44
|
-
if (!parts) {
|
|
45
|
-
throw new Error(`interface ${iface} was not found`);
|
|
46
|
-
}
|
|
47
|
-
for (const part of parts) {
|
|
48
|
-
if (zeroRegex.test(part.mac) === false) {
|
|
49
|
-
return part.mac;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
throw new Error(`interface ${iface} had no valid mac addresses`);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
for (const [key, parts] of Object.entries(list)) {
|
|
56
|
-
// for some reason beyond me, this is needed to satisfy typescript
|
|
57
|
-
// fix https://github.com/bevry/getmac/issues/100
|
|
58
|
-
if (!parts)
|
|
59
|
-
continue;
|
|
60
|
-
for (const part of parts) {
|
|
61
|
-
if (zeroRegex.test(part.mac) === false) {
|
|
62
|
-
return part.mac;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
throw new Error('failed to get the MAC address');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Check if the input is a valid MAC address
|
|
72
|
-
*/
|
|
73
|
-
exports.isMAC = function(macAddress) {
|
|
74
|
-
const macRegex = /(?:[a-z0-9]{1,2}[:-]){5}[a-z0-9]{1,2}/i;
|
|
75
|
-
return macRegex.test(macAddress);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* is encrypt
|
|
80
|
-
*/
|
|
81
|
-
exports.isEncrypt = function(basePath) {
|
|
82
|
-
const encryptDir = Ps.getEncryptDir(basePath);
|
|
83
|
-
if (fs.existsSync(encryptDir)) {
|
|
84
|
-
return true;
|
|
85
|
-
}
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* get machine id
|
|
91
|
-
*/
|
|
92
|
-
exports.machineIdSync = function(original) {
|
|
93
|
-
let id = expose(execSync(MachineGuid[platform]).toString());
|
|
94
|
-
return original ? id : hash(id);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* get machine id (promise)
|
|
99
|
-
* original <Boolean>, If true return original value of machine id, otherwise return hashed value (sha-256), default: false
|
|
100
|
-
*/
|
|
101
|
-
exports.machineId = function(original) {
|
|
102
|
-
return new Promise((resolve, reject) => {
|
|
103
|
-
return exec(MachineGuid[platform], {}, (err, stdout, stderr) => {
|
|
104
|
-
if (err) {
|
|
105
|
-
return reject(
|
|
106
|
-
new Error(`Error while obtaining machine id: ${err.stack}`)
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
let id = expose(stdout.toString());
|
|
110
|
-
return resolve(original ? id : hash(id));
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function isWindowsProcessMixedOrNativeArchitecture() {
|
|
116
|
-
// detect if the node binary is the same arch as the Windows OS.
|
|
117
|
-
// or if this is 32 bit node on 64 bit windows.
|
|
118
|
-
if(process.platform !== 'win32') {
|
|
119
|
-
return '';
|
|
120
|
-
}
|
|
121
|
-
if( process.arch === 'ia32' && process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432') ) {
|
|
122
|
-
return 'mixed';
|
|
123
|
-
}
|
|
124
|
-
return 'native';
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function hash(guid) {
|
|
128
|
-
return createHash('sha256').update(guid).digest('hex');
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function expose(result) {
|
|
132
|
-
switch (platform) {
|
|
133
|
-
case 'darwin':
|
|
134
|
-
return result
|
|
135
|
-
.split('IOPlatformUUID')[1]
|
|
136
|
-
.split('\n')[0].replace(/\=|\s+|\"/ig, '')
|
|
137
|
-
.toLowerCase();
|
|
138
|
-
case 'win32':
|
|
139
|
-
return result
|
|
140
|
-
.toString()
|
|
141
|
-
.split('REG_SZ')[1]
|
|
142
|
-
.replace(/\r+|\n+|\s+/ig, '')
|
|
143
|
-
.toLowerCase();
|
|
144
|
-
case 'linux':
|
|
145
|
-
return result
|
|
146
|
-
.toString()
|
|
147
|
-
.replace(/\r+|\n+|\s+/ig, '')
|
|
148
|
-
.toLowerCase();
|
|
149
|
-
case 'freebsd':
|
|
150
|
-
return result
|
|
151
|
-
.toString()
|
|
152
|
-
.replace(/\r+|\n+|\s+/ig, '')
|
|
153
|
-
.toLowerCase();
|
|
154
|
-
default:
|
|
155
|
-
throw new Error(`Unsupported platform: ${process.platform}`);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const os = require("os");
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const { exec, execSync } = require('child_process');
|
|
7
|
+
const { createHash } = require('crypto');
|
|
8
|
+
const Ps = require('../ps');
|
|
9
|
+
const UtilsJson = require('./json');
|
|
10
|
+
|
|
11
|
+
// machine id
|
|
12
|
+
const { platform } = process;
|
|
13
|
+
const win32RegBinPath = {
|
|
14
|
+
native: '%windir%\\System32',
|
|
15
|
+
mixed: '%windir%\\sysnative\\cmd.exe /c %windir%\\System32'
|
|
16
|
+
};
|
|
17
|
+
const MachineGuid = {
|
|
18
|
+
darwin: 'ioreg -rd1 -c IOPlatformExpertDevice',
|
|
19
|
+
win32: `${win32RegBinPath[isWindowsProcessMixedOrNativeArchitecture()]}\\REG.exe ` +
|
|
20
|
+
'QUERY HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography ' +
|
|
21
|
+
'/v MachineGuid',
|
|
22
|
+
linux: '( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname ) | head -n 1 || :',
|
|
23
|
+
freebsd: 'kenv -q smbios.system.uuid || sysctl -n kern.hostuuid'
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 获取项目根目录package.json
|
|
28
|
+
*/
|
|
29
|
+
exports.getPackage = function() {
|
|
30
|
+
const json = UtilsJson.readSync(path.join(Ps.getHomeDir(), 'package.json'));
|
|
31
|
+
|
|
32
|
+
return json;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Get the first proper MAC address
|
|
37
|
+
* @param iface If provided, restrict MAC address fetching to this interface
|
|
38
|
+
*/
|
|
39
|
+
exports.getMAC = function(iface) {
|
|
40
|
+
const zeroRegex = /(?:[0]{1,2}[:-]){5}[0]{1,2}/;
|
|
41
|
+
const list = os.networkInterfaces();
|
|
42
|
+
if (iface) {
|
|
43
|
+
const parts = list[iface];
|
|
44
|
+
if (!parts) {
|
|
45
|
+
throw new Error(`interface ${iface} was not found`);
|
|
46
|
+
}
|
|
47
|
+
for (const part of parts) {
|
|
48
|
+
if (zeroRegex.test(part.mac) === false) {
|
|
49
|
+
return part.mac;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
throw new Error(`interface ${iface} had no valid mac addresses`);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
for (const [key, parts] of Object.entries(list)) {
|
|
56
|
+
// for some reason beyond me, this is needed to satisfy typescript
|
|
57
|
+
// fix https://github.com/bevry/getmac/issues/100
|
|
58
|
+
if (!parts)
|
|
59
|
+
continue;
|
|
60
|
+
for (const part of parts) {
|
|
61
|
+
if (zeroRegex.test(part.mac) === false) {
|
|
62
|
+
return part.mac;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
throw new Error('failed to get the MAC address');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Check if the input is a valid MAC address
|
|
72
|
+
*/
|
|
73
|
+
exports.isMAC = function(macAddress) {
|
|
74
|
+
const macRegex = /(?:[a-z0-9]{1,2}[:-]){5}[a-z0-9]{1,2}/i;
|
|
75
|
+
return macRegex.test(macAddress);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* is encrypt
|
|
80
|
+
*/
|
|
81
|
+
exports.isEncrypt = function(basePath) {
|
|
82
|
+
const encryptDir = Ps.getEncryptDir(basePath);
|
|
83
|
+
if (fs.existsSync(encryptDir)) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* get machine id
|
|
91
|
+
*/
|
|
92
|
+
exports.machineIdSync = function(original) {
|
|
93
|
+
let id = expose(execSync(MachineGuid[platform]).toString());
|
|
94
|
+
return original ? id : hash(id);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* get machine id (promise)
|
|
99
|
+
* original <Boolean>, If true return original value of machine id, otherwise return hashed value (sha-256), default: false
|
|
100
|
+
*/
|
|
101
|
+
exports.machineId = function(original) {
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
return exec(MachineGuid[platform], {}, (err, stdout, stderr) => {
|
|
104
|
+
if (err) {
|
|
105
|
+
return reject(
|
|
106
|
+
new Error(`Error while obtaining machine id: ${err.stack}`)
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
let id = expose(stdout.toString());
|
|
110
|
+
return resolve(original ? id : hash(id));
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function isWindowsProcessMixedOrNativeArchitecture() {
|
|
116
|
+
// detect if the node binary is the same arch as the Windows OS.
|
|
117
|
+
// or if this is 32 bit node on 64 bit windows.
|
|
118
|
+
if(process.platform !== 'win32') {
|
|
119
|
+
return '';
|
|
120
|
+
}
|
|
121
|
+
if( process.arch === 'ia32' && process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432') ) {
|
|
122
|
+
return 'mixed';
|
|
123
|
+
}
|
|
124
|
+
return 'native';
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function hash(guid) {
|
|
128
|
+
return createHash('sha256').update(guid).digest('hex');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function expose(result) {
|
|
132
|
+
switch (platform) {
|
|
133
|
+
case 'darwin':
|
|
134
|
+
return result
|
|
135
|
+
.split('IOPlatformUUID')[1]
|
|
136
|
+
.split('\n')[0].replace(/\=|\s+|\"/ig, '')
|
|
137
|
+
.toLowerCase();
|
|
138
|
+
case 'win32':
|
|
139
|
+
return result
|
|
140
|
+
.toString()
|
|
141
|
+
.split('REG_SZ')[1]
|
|
142
|
+
.replace(/\r+|\n+|\s+/ig, '')
|
|
143
|
+
.toLowerCase();
|
|
144
|
+
case 'linux':
|
|
145
|
+
return result
|
|
146
|
+
.toString()
|
|
147
|
+
.replace(/\r+|\n+|\s+/ig, '')
|
|
148
|
+
.toLowerCase();
|
|
149
|
+
case 'freebsd':
|
|
150
|
+
return result
|
|
151
|
+
.toString()
|
|
152
|
+
.replace(/\r+|\n+|\s+/ig, '')
|
|
153
|
+
.toLowerCase();
|
|
154
|
+
default:
|
|
155
|
+
throw new Error(`Unsupported platform: ${process.platform}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|