ee-core 1.5.2-beta.1 → 2.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/LICENSE +21 -21
- package/README.md +2 -2
- package/addon/window/index.js +91 -91
- package/bin/tools.js +18 -18
- package/config/config.default.js +287 -280
- package/core/index.js +12 -12
- package/core/lib/ee.js +218 -218
- package/core/lib/loader/context_loader.js +106 -106
- package/core/lib/loader/ee_loader.js +461 -457
- package/core/lib/loader/file_loader.js +325 -325
- package/core/lib/loader/mixin/addon.js +32 -32
- package/core/lib/loader/mixin/config.js +135 -135
- package/core/lib/loader/mixin/controller.js +125 -124
- 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 -0
- package/core/lib/utils/index.js +127 -127
- package/core/lib/utils/sequencify.js +59 -59
- package/core/lib/utils/timing.js +77 -77
- package/index.js +49 -49
- package/lib/appLoader.js +48 -53
- package/lib/application.js +85 -84
- package/lib/baseApp.js +114 -131
- package/lib/eeApp.js +325 -359
- package/{lib/constant.js → module/const/index.js} +12 -9
- package/{lib/httpclient.js → module/httpclient/index.js} +170 -136
- package/module/jobs/child/forkProcess.js +99 -0
- package/module/jobs/child/index.js +33 -0
- package/module/jobs/index.js +55 -0
- package/module/jobs/renderer/index.js +140 -0
- package/module/jobs/renderer/loadView.js +40 -0
- package/module/loader/index.js +78 -0
- package/module/log/index.js +53 -0
- package/module/log/logger.js +61 -0
- package/module/message/index.js +13 -0
- package/module/message/ipcMain.js +160 -0
- package/module/message/ipcRender.js +0 -0
- package/{lib → module}/socket/httpServer.js +142 -142
- package/{lib → module}/socket/io.js +23 -23
- package/{lib → module}/socket/ipcServer.js +106 -108
- package/{lib → module}/socket/socketClient.js +51 -50
- package/{lib → module}/socket/socketServer.js +77 -76
- package/module/socket/start.js +22 -0
- package/{lib → module}/storage/index.js +35 -34
- package/module/storage/jsondb/adapters/Base.js +14 -0
- package/module/storage/jsondb/adapters/FileSync.js +32 -0
- package/{lib/storage/lowdb → module/storage/jsondb}/main.js +42 -46
- package/{lib/storage/lowdbStorage.js → module/storage/jsondbStorage.js} +98 -99
- package/{lib → module}/storage/sqliteStorage.js +123 -127
- package/module/utils/copyto.js +161 -0
- package/module/utils/helper.js +117 -0
- package/module/utils/index.js +120 -0
- package/module/utils/json.js +72 -0
- package/module/utils/ps.js +175 -0
- package/{utils → module/utils}/wrap.js +35 -37
- package/package.json +44 -48
- package/tools/encrypt.js +274 -274
- package/tools/replaceDist.js +61 -61
- package/utils/index.js +128 -246
- package/lib/logger.js +0 -47
- package/lib/socket/start.js +0 -22
- package/lib/storage/lowdb/adapters/Base.js +0 -15
- package/lib/storage/lowdb/adapters/FileAsync.js +0 -41
- package/lib/storage/lowdb/adapters/FileSync.js +0 -39
- package/lib/storage/lowdb/adapters/LocalStorage.js +0 -20
- package/lib/storage/lowdb/adapters/Memory.js +0 -8
- package/lib/storage/lowdb/adapters/_stringify.js +0 -4
- package/lib/storage/lowdb/common.js +0 -33
- package/lib/storage/lowdb/fp.js +0 -23
- package/lib/storage/lowdb/is-promise.js +0 -6
- package/lib/storage/lowdb/nano.js +0 -5
- package/utils/common.js +0 -91
package/tools/replaceDist.js
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const fsPro = require('fs-extra');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 资源替换
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
module.exports = {
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 执行
|
|
15
|
-
*/
|
|
16
|
-
run () {
|
|
17
|
-
console.log('[ee-core] [replace_dist] 开始移动资源');
|
|
18
|
-
const homeDir = process.cwd();
|
|
19
|
-
|
|
20
|
-
// argv
|
|
21
|
-
let distDir = '';
|
|
22
|
-
for (let i = 0; i < process.argv.length; i++) {
|
|
23
|
-
let tmpArgv = process.argv[i]
|
|
24
|
-
if (tmpArgv.indexOf('--dist_dir=') !== -1) {
|
|
25
|
-
distDir = tmpArgv.substring(11)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const fileExist = (filePath) => {
|
|
30
|
-
try {
|
|
31
|
-
return fs.statSync(filePath).isFile();
|
|
32
|
-
} catch (err) {
|
|
33
|
-
console.error('[ee-core] [replace_dist] ERROR ', err);
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const sourceDir = path.join(homeDir, distDir);
|
|
39
|
-
const sourceIndexFile = path.join(sourceDir, 'index.html');
|
|
40
|
-
|
|
41
|
-
if (!fileExist(sourceIndexFile)) {
|
|
42
|
-
console.error('[ee-core] [replace_dist] ERROR 前端资源不存在,请构建!!!');
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// 复制到ee资源目录
|
|
47
|
-
const eeResourceDir = path.join(homeDir, 'public', 'dist');
|
|
48
|
-
|
|
49
|
-
// 清空历史资源
|
|
50
|
-
fs.rmdirSync(eeResourceDir, {recursive: true});
|
|
51
|
-
console.log('[ee-core] [replace_dist] 清空历史资源:', eeResourceDir);
|
|
52
|
-
|
|
53
|
-
fsPro.copySync(sourceDir, eeResourceDir);
|
|
54
|
-
console.log('[ee-core] [replace_dist] 复制资源到:', eeResourceDir);
|
|
55
|
-
|
|
56
|
-
console.log('[ee-core] [replace_dist] 结束');
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const fsPro = require('fs-extra');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 资源替换
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 执行
|
|
15
|
+
*/
|
|
16
|
+
run () {
|
|
17
|
+
console.log('[ee-core] [replace_dist] 开始移动资源');
|
|
18
|
+
const homeDir = process.cwd();
|
|
19
|
+
|
|
20
|
+
// argv
|
|
21
|
+
let distDir = '';
|
|
22
|
+
for (let i = 0; i < process.argv.length; i++) {
|
|
23
|
+
let tmpArgv = process.argv[i]
|
|
24
|
+
if (tmpArgv.indexOf('--dist_dir=') !== -1) {
|
|
25
|
+
distDir = tmpArgv.substring(11)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const fileExist = (filePath) => {
|
|
30
|
+
try {
|
|
31
|
+
return fs.statSync(filePath).isFile();
|
|
32
|
+
} catch (err) {
|
|
33
|
+
console.error('[ee-core] [replace_dist] ERROR ', err);
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const sourceDir = path.join(homeDir, distDir);
|
|
39
|
+
const sourceIndexFile = path.join(sourceDir, 'index.html');
|
|
40
|
+
|
|
41
|
+
if (!fileExist(sourceIndexFile)) {
|
|
42
|
+
console.error('[ee-core] [replace_dist] ERROR 前端资源不存在,请构建!!!');
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 复制到ee资源目录
|
|
47
|
+
const eeResourceDir = path.join(homeDir, 'public', 'dist');
|
|
48
|
+
|
|
49
|
+
// 清空历史资源
|
|
50
|
+
fs.rmdirSync(eeResourceDir, {recursive: true});
|
|
51
|
+
console.log('[ee-core] [replace_dist] 清空历史资源:', eeResourceDir);
|
|
52
|
+
|
|
53
|
+
fsPro.copySync(sourceDir, eeResourceDir);
|
|
54
|
+
console.log('[ee-core] [replace_dist] 复制资源到:', eeResourceDir);
|
|
55
|
+
|
|
56
|
+
console.log('[ee-core] [replace_dist] 结束');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
package/utils/index.js
CHANGED
|
@@ -1,247 +1,129 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const cdb = this.getCoreDB();
|
|
130
|
-
const dataPath = cdb.getItem('config').appUserDataDir;
|
|
131
|
-
return dataPath;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* 获取 app version
|
|
136
|
-
*/
|
|
137
|
-
exports.getAppVersion = function() {
|
|
138
|
-
const cdb = this.getCoreDB();
|
|
139
|
-
const v = cdb.getItem('config').appVersion;
|
|
140
|
-
return v;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* 获取 exec目录
|
|
145
|
-
*/
|
|
146
|
-
exports.getExecDir = function() {
|
|
147
|
-
const cdb = this.getCoreDB();
|
|
148
|
-
const execPath = cdb.getItem('config').execDir;
|
|
149
|
-
return execPath;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* 获取 插件配置
|
|
154
|
-
*/
|
|
155
|
-
exports.getAddonConfig = function() {
|
|
156
|
-
const cdb = this.getCoreDB();
|
|
157
|
-
const cfg = cdb.getItem('config').addons;
|
|
158
|
-
return cfg;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* 获取 mainServer配置
|
|
163
|
-
*/
|
|
164
|
-
exports.getMainServerConfig = function() {
|
|
165
|
-
const cdb = this.getCoreDB();
|
|
166
|
-
const cfg = cdb.getItem('config').mainServer;
|
|
167
|
-
return cfg;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* 获取 httpServer配置
|
|
172
|
-
*/
|
|
173
|
-
exports.getHttpServerConfig = function() {
|
|
174
|
-
const cdb = this.getCoreDB();
|
|
175
|
-
const cfg = cdb.getItem('config').httpServer;
|
|
176
|
-
return cfg;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* 获取 socketServer配置
|
|
181
|
-
*/
|
|
182
|
-
exports.getSocketServerConfig = function() {
|
|
183
|
-
const cdb = this.getCoreDB();
|
|
184
|
-
const cfg = cdb.getItem('config').socketServer;
|
|
185
|
-
return cfg;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* 获取 socketio port
|
|
190
|
-
*/
|
|
191
|
-
exports.getSocketPort = function() {
|
|
192
|
-
const cdb = this.getCoreDB();
|
|
193
|
-
const port = cdb.getItem('config').socketServer.port;
|
|
194
|
-
return parseInt(port);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* 获取 socket channel
|
|
199
|
-
*/
|
|
200
|
-
exports.getSocketChannel = function() {
|
|
201
|
-
return constant.socketIo.channel;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* 获取 额外资源目录
|
|
206
|
-
*/
|
|
207
|
-
exports.getExtraResourcesDir = function() {
|
|
208
|
-
const cdb = this.getCoreDB();
|
|
209
|
-
const config = cdb.getItem('config');
|
|
210
|
-
const execDir = config.execDir;
|
|
211
|
-
|
|
212
|
-
// 资源路径不同
|
|
213
|
-
let dir = '';
|
|
214
|
-
if (config.isPackaged) {
|
|
215
|
-
// 打包后 execDir为 应用程序 exe\dmg\dep软件所在目录;打包前该值是项目根目录
|
|
216
|
-
// windows和MacOs不一样
|
|
217
|
-
dir = path.join(execDir, "resources", "extraResources");
|
|
218
|
-
if (eis.macOS()) {
|
|
219
|
-
dir = path.join(execDir, "..", "Resources", "extraResources");
|
|
220
|
-
}
|
|
221
|
-
} else {
|
|
222
|
-
// 打包前
|
|
223
|
-
dir = path.join(execDir, "build", "extraResources");
|
|
224
|
-
}
|
|
225
|
-
return dir;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* 执行一个函数
|
|
230
|
-
*/
|
|
231
|
-
exports.callFn = async function (fn, args, ctx) {
|
|
232
|
-
args = args || [];
|
|
233
|
-
if (!is.function(fn)) return;
|
|
234
|
-
if (is.generatorFunction(fn)) fn = co.wrap(fn);
|
|
235
|
-
return ctx ? fn.call(ctx, ...args) : fn(...args);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
exports.middleware = function (fn) {
|
|
239
|
-
return is.generatorFunction(fn) ? convert(fn) : fn;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* 版本号比较
|
|
244
|
-
*/
|
|
245
|
-
exports.compareVersion = function (v1, v2) {
|
|
246
|
-
return utilsCommon.compareVersion(v1, v2);
|
|
1
|
+
/**
|
|
2
|
+
* 该模块不在增加新功能,请使用 /module/utils/index 模块
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const eis = require('electron-is');
|
|
7
|
+
const UtilsJson = require('../module/utils/json');
|
|
8
|
+
const UtilsPs = require('../module/utils/ps');
|
|
9
|
+
const UtilsHelper = require('../module/utils/helper');
|
|
10
|
+
const Copy = require('../module/utils/copyto');
|
|
11
|
+
const Storage = require('../module/storage');
|
|
12
|
+
const Constants = require('../module/const');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* other module
|
|
16
|
+
*/
|
|
17
|
+
Copy(UtilsPs)
|
|
18
|
+
.and(UtilsHelper)
|
|
19
|
+
.to(exports);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 获取项目根目录package.json
|
|
23
|
+
*/
|
|
24
|
+
exports.getPackage = function() {
|
|
25
|
+
const json = UtilsJson.readSync(path.join(this.getHomeDir(), 'package.json'));
|
|
26
|
+
|
|
27
|
+
return json;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 获取 coredb
|
|
32
|
+
*/
|
|
33
|
+
exports.getCoreDB = function() {
|
|
34
|
+
const coreDB = Storage.connection('system');
|
|
35
|
+
return coreDB;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 获取 ee配置
|
|
40
|
+
*/
|
|
41
|
+
exports.getEeConfig = function() {
|
|
42
|
+
const cdb = this.getCoreDB();
|
|
43
|
+
const config = cdb.getItem('config');
|
|
44
|
+
|
|
45
|
+
return config;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 获取 app version
|
|
50
|
+
*/
|
|
51
|
+
exports.getAppVersion = function() {
|
|
52
|
+
const cdb = this.getCoreDB();
|
|
53
|
+
const v = cdb.getItem('config').appVersion;
|
|
54
|
+
return v;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 获取 插件配置
|
|
59
|
+
*/
|
|
60
|
+
exports.getAddonConfig = function() {
|
|
61
|
+
const cdb = this.getCoreDB();
|
|
62
|
+
const cfg = cdb.getItem('config').addons;
|
|
63
|
+
return cfg;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 获取 mainServer配置
|
|
68
|
+
*/
|
|
69
|
+
exports.getMainServerConfig = function() {
|
|
70
|
+
const cdb = this.getCoreDB();
|
|
71
|
+
const cfg = cdb.getItem('config').mainServer;
|
|
72
|
+
return cfg;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 获取 httpServer配置
|
|
77
|
+
*/
|
|
78
|
+
exports.getHttpServerConfig = function() {
|
|
79
|
+
const cdb = this.getCoreDB();
|
|
80
|
+
const cfg = cdb.getItem('config').httpServer;
|
|
81
|
+
return cfg;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 获取 socketServer配置
|
|
86
|
+
*/
|
|
87
|
+
exports.getSocketServerConfig = function() {
|
|
88
|
+
const cdb = this.getCoreDB();
|
|
89
|
+
const cfg = cdb.getItem('config').socketServer;
|
|
90
|
+
return cfg;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 获取 socketio port
|
|
95
|
+
*/
|
|
96
|
+
exports.getSocketPort = function() {
|
|
97
|
+
const cdb = this.getCoreDB();
|
|
98
|
+
const port = cdb.getItem('config').socketServer.port;
|
|
99
|
+
return parseInt(port);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 获取 socket channel
|
|
104
|
+
*/
|
|
105
|
+
exports.getSocketChannel = function() {
|
|
106
|
+
return Constants.socketIo.channel;
|
|
107
|
+
}
|
|
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;
|
|
247
129
|
}
|
package/lib/logger.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const debug = require('debug')('ee-core:logger');
|
|
4
|
-
const Loggers = require('egg-logger').EggLoggers;
|
|
5
|
-
const assert = require('assert');
|
|
6
|
-
|
|
7
|
-
class Logger {
|
|
8
|
-
constructor (config) {
|
|
9
|
-
debug('Loaded logger');
|
|
10
|
-
assert(Object.keys(config).length != 0, `logger config is null`);
|
|
11
|
-
this.eggLogger = this.init(config);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 单例
|
|
16
|
-
*/
|
|
17
|
-
static getInstance (config = {}) {
|
|
18
|
-
if (typeof this.instance === 'object') {
|
|
19
|
-
return this.instance.eggLogger;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
this.instance = new Logger(config);
|
|
23
|
-
|
|
24
|
-
// 返回egg-logger实例
|
|
25
|
-
return this.instance.eggLogger;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 初始化模块
|
|
30
|
-
*/
|
|
31
|
-
init(config) {
|
|
32
|
-
const loggerConfig = config.logger;
|
|
33
|
-
loggerConfig.type = 'application'; // application、agent
|
|
34
|
-
|
|
35
|
-
if (config.env === 'prod' && loggerConfig.level === 'DEBUG' && !loggerConfig.allowDebugAtProd) {
|
|
36
|
-
loggerConfig.level = 'INFO';
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const loggers = new Loggers(config);
|
|
40
|
-
|
|
41
|
-
loggers.coreLogger.info('[ee-core:logger] init all loggers with options: %j', loggerConfig);
|
|
42
|
-
|
|
43
|
-
return loggers;
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
module.exports = Logger;
|
package/lib/socket/start.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const socketServer = require('./socketServer');
|
|
4
|
-
const ipcServer = require('./ipcServer');
|
|
5
|
-
const httpServer = require('./httpServer');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* server
|
|
9
|
-
*/
|
|
10
|
-
module.exports = (app) => {
|
|
11
|
-
|
|
12
|
-
// 启动 socket server
|
|
13
|
-
new socketServer(app);
|
|
14
|
-
|
|
15
|
-
// 启动 http server
|
|
16
|
-
new httpServer(app);
|
|
17
|
-
|
|
18
|
-
// 启动 electron ipc server
|
|
19
|
-
new ipcServer(app);
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const stringify = require('./_stringify')
|
|
2
|
-
|
|
3
|
-
class Base {
|
|
4
|
-
constructor(
|
|
5
|
-
source,
|
|
6
|
-
{ defaultValue = {}, serialize = stringify, deserialize = JSON.parse } = {}
|
|
7
|
-
) {
|
|
8
|
-
this.source = source
|
|
9
|
-
this.defaultValue = defaultValue
|
|
10
|
-
this.serialize = serialize
|
|
11
|
-
this.deserialize = deserialize
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = Base
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// Not using async/await on purpose to avoid adding regenerator-runtime
|
|
2
|
-
// to lowdb dependencies
|
|
3
|
-
const fs = require('graceful-fs')
|
|
4
|
-
const pify = require('pify')
|
|
5
|
-
const steno = require('steno')
|
|
6
|
-
const Base = require('./Base')
|
|
7
|
-
|
|
8
|
-
const readFile = pify(fs.readFile)
|
|
9
|
-
const writeFile = pify(steno.writeFile)
|
|
10
|
-
|
|
11
|
-
class FileAsync extends Base {
|
|
12
|
-
read() {
|
|
13
|
-
// fs.exists is deprecated but not fs.existsSync
|
|
14
|
-
if (fs.existsSync(this.source)) {
|
|
15
|
-
// Read database
|
|
16
|
-
return readFile(this.source, 'utf-8')
|
|
17
|
-
.then(data => {
|
|
18
|
-
// Handle blank file
|
|
19
|
-
const trimmed = data.trim()
|
|
20
|
-
return trimmed ? this.deserialize(trimmed) : this.defaultValue
|
|
21
|
-
})
|
|
22
|
-
.catch(e => {
|
|
23
|
-
if (e instanceof SyntaxError) {
|
|
24
|
-
e.message = `Malformed JSON in file: ${this.source}\n${e.message}`
|
|
25
|
-
}
|
|
26
|
-
throw e
|
|
27
|
-
})
|
|
28
|
-
} else {
|
|
29
|
-
// Initialize
|
|
30
|
-
return writeFile(this.source, this.serialize(this.defaultValue)).then(
|
|
31
|
-
() => this.defaultValue
|
|
32
|
-
)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
write(data) {
|
|
37
|
-
return writeFile(this.source, this.serialize(data))
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
module.exports = FileAsync
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
const fs = require('graceful-fs')
|
|
2
|
-
const Base = require('./Base')
|
|
3
|
-
const fileSystem = require('fs')
|
|
4
|
-
|
|
5
|
-
//const readFile = fs.readFileSync
|
|
6
|
-
const writeFile = fs.writeFileSync
|
|
7
|
-
|
|
8
|
-
// Same code as in FileAsync, minus `await`
|
|
9
|
-
class FileSync extends Base {
|
|
10
|
-
read() {
|
|
11
|
-
// fs.exists is deprecated but not fs.existsSync
|
|
12
|
-
if (fs.existsSync(this.source)) {
|
|
13
|
-
// Read database
|
|
14
|
-
try {
|
|
15
|
-
// 使用 fileSystem的readFileSync
|
|
16
|
-
//const data = readFile(this.source, 'utf-8').trim()
|
|
17
|
-
const data = fileSystem.readFileSync(this.source, {encoding: 'utf-8'})
|
|
18
|
-
|
|
19
|
-
// Handle blank file
|
|
20
|
-
return data ? this.deserialize(data) : this.defaultValue
|
|
21
|
-
} catch (e) {
|
|
22
|
-
if (e instanceof SyntaxError) {
|
|
23
|
-
e.message = `Malformed JSON in file: ${this.source}\n${e.message}`
|
|
24
|
-
}
|
|
25
|
-
throw e
|
|
26
|
-
}
|
|
27
|
-
} else {
|
|
28
|
-
// Initialize
|
|
29
|
-
writeFile(this.source, this.serialize(this.defaultValue))
|
|
30
|
-
return this.defaultValue
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
write(data) {
|
|
35
|
-
return writeFile(this.source, this.serialize(data))
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
module.exports = FileSync
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/* global localStorage */
|
|
2
|
-
const Base = require('./Base')
|
|
3
|
-
|
|
4
|
-
class LocalStorage extends Base {
|
|
5
|
-
read() {
|
|
6
|
-
const data = localStorage.getItem(this.source)
|
|
7
|
-
if (data) {
|
|
8
|
-
return this.deserialize(data)
|
|
9
|
-
} else {
|
|
10
|
-
localStorage.setItem(this.source, this.serialize(this.defaultValue))
|
|
11
|
-
return this.defaultValue
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
write(data) {
|
|
16
|
-
localStorage.setItem(this.source, this.serialize(data))
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
module.exports = LocalStorage
|