ee-core 1.5.0 → 1.5.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.
Files changed (41) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +2 -2
  3. package/addon/window/index.js +91 -91
  4. package/bin/tools.js +17 -17
  5. package/config/config.default.js +280 -276
  6. package/core/index.js +12 -12
  7. package/core/lib/ee.js +218 -218
  8. package/core/lib/loader/context_loader.js +106 -106
  9. package/core/lib/loader/ee_loader.js +457 -457
  10. package/core/lib/loader/file_loader.js +325 -325
  11. package/core/lib/loader/mixin/addon.js +32 -32
  12. package/core/lib/loader/mixin/config.js +135 -135
  13. package/core/lib/loader/mixin/controller.js +124 -124
  14. package/core/lib/loader/mixin/service.js +28 -28
  15. package/core/lib/utils/base_context_class.js +34 -34
  16. package/core/lib/utils/index.js +127 -127
  17. package/core/lib/utils/sequencify.js +59 -59
  18. package/core/lib/utils/timing.js +77 -77
  19. package/index.js +49 -49
  20. package/lib/appLoader.js +53 -53
  21. package/lib/application.js +84 -84
  22. package/lib/baseApp.js +131 -131
  23. package/lib/constant.js +9 -9
  24. package/lib/eeApp.js +359 -335
  25. package/lib/httpclient.js +136 -136
  26. package/lib/logger.js +46 -46
  27. package/lib/socket/httpServer.js +142 -142
  28. package/lib/socket/io.js +23 -23
  29. package/lib/socket/ipcServer.js +108 -108
  30. package/lib/socket/socketClient.js +50 -50
  31. package/lib/socket/socketServer.js +76 -76
  32. package/lib/socket/start.js +22 -22
  33. package/lib/storage/index.js +33 -33
  34. package/lib/storage/lowdbStorage.js +98 -98
  35. package/lib/storage/sqliteStorage.js +127 -127
  36. package/package.json +45 -45
  37. package/tools/encrypt.js +274 -274
  38. package/tools/replaceDist.js +61 -61
  39. package/utils/common.js +90 -90
  40. package/utils/index.js +246 -246
  41. package/utils/wrap.js +37 -37
package/utils/common.js CHANGED
@@ -1,91 +1,91 @@
1
- 'use strict';
2
-
3
- /**
4
- * ee-core使用
5
- */
6
-
7
- const fs = require('fs');
8
- const path = require('path');
9
-
10
- /**
11
- * 版本号比较
12
- */
13
- exports.compareVersion = function (v1, v2) {
14
- v1 = v1.split('.')
15
- v2 = v2.split('.')
16
- const len = Math.max(v1.length, v2.length)
17
-
18
- while (v1.length < len) {
19
- v1.push('0')
20
- }
21
- while (v2.length < len) {
22
- v2.push('0')
23
- }
24
-
25
- for (let i = 0; i < len; i++) {
26
- const num1 = parseInt(v1[i])
27
- const num2 = parseInt(v2[i])
28
-
29
- if (num1 > num2) {
30
- return 1
31
- } else if (num1 < num2) {
32
- return -1
33
- }
34
- }
35
-
36
- return 0
37
- }
38
-
39
- /**
40
- * 创建文件夹
41
- */
42
- exports.mkdir = function(dirpath, dirname) {
43
- // 判断是否是第一次调用
44
- if (typeof dirname === 'undefined') {
45
- if (fs.existsSync(dirpath)) {
46
- return;
47
- }
48
- this.mkdir(dirpath, path.dirname(dirpath));
49
- } else {
50
- // 判断第二个参数是否正常,避免调用时传入错误参数
51
- if (dirname !== path.dirname(dirpath)) {
52
- this.mkdir(dirpath);
53
- return;
54
- }
55
- if (fs.existsSync(dirname)) {
56
- fs.mkdirSync(dirpath);
57
- } else {
58
- this.mkdir(dirname, path.dirname(dirname));
59
- fs.mkdirSync(dirpath);
60
- }
61
- }
62
- };
63
-
64
- /**
65
- * 修改文件权限
66
- */
67
- exports.chmodPath = function(path, mode) {
68
- let files = [];
69
- if (fs.existsSync(path)) {
70
- files = fs.readdirSync(path);
71
- files.forEach((file, index) => {
72
- const curPath = path + '/' + file;
73
- if (fs.statSync(curPath).isDirectory()) {
74
- this.chmodPath(curPath, mode); // 递归删除文件夹
75
- } else {
76
- fs.chmodSync(curPath, mode);
77
- }
78
- });
79
- fs.chmodSync(path, mode);
80
- }
81
- };
82
-
83
- /**
84
- * 获取数据存储路径
85
- */
86
- exports.getStorageDir = function () {
87
- let env = process.env.EE_SERVER_ENV;
88
- const appDir = env === 'local' || env === 'unittest' ? process.env.EE_HOME : process.env.EE_APP_USER_DATA;
89
- const storageDir = path.join(appDir, 'data');
90
- return storageDir;
1
+ 'use strict';
2
+
3
+ /**
4
+ * ee-core使用
5
+ */
6
+
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+
10
+ /**
11
+ * 版本号比较
12
+ */
13
+ exports.compareVersion = function (v1, v2) {
14
+ v1 = v1.split('.')
15
+ v2 = v2.split('.')
16
+ const len = Math.max(v1.length, v2.length)
17
+
18
+ while (v1.length < len) {
19
+ v1.push('0')
20
+ }
21
+ while (v2.length < len) {
22
+ v2.push('0')
23
+ }
24
+
25
+ for (let i = 0; i < len; i++) {
26
+ const num1 = parseInt(v1[i])
27
+ const num2 = parseInt(v2[i])
28
+
29
+ if (num1 > num2) {
30
+ return 1
31
+ } else if (num1 < num2) {
32
+ return -1
33
+ }
34
+ }
35
+
36
+ return 0
37
+ }
38
+
39
+ /**
40
+ * 创建文件夹
41
+ */
42
+ exports.mkdir = function(dirpath, dirname) {
43
+ // 判断是否是第一次调用
44
+ if (typeof dirname === 'undefined') {
45
+ if (fs.existsSync(dirpath)) {
46
+ return;
47
+ }
48
+ this.mkdir(dirpath, path.dirname(dirpath));
49
+ } else {
50
+ // 判断第二个参数是否正常,避免调用时传入错误参数
51
+ if (dirname !== path.dirname(dirpath)) {
52
+ this.mkdir(dirpath);
53
+ return;
54
+ }
55
+ if (fs.existsSync(dirname)) {
56
+ fs.mkdirSync(dirpath);
57
+ } else {
58
+ this.mkdir(dirname, path.dirname(dirname));
59
+ fs.mkdirSync(dirpath);
60
+ }
61
+ }
62
+ };
63
+
64
+ /**
65
+ * 修改文件权限
66
+ */
67
+ exports.chmodPath = function(path, mode) {
68
+ let files = [];
69
+ if (fs.existsSync(path)) {
70
+ files = fs.readdirSync(path);
71
+ files.forEach((file, index) => {
72
+ const curPath = path + '/' + file;
73
+ if (fs.statSync(curPath).isDirectory()) {
74
+ this.chmodPath(curPath, mode); // 递归删除文件夹
75
+ } else {
76
+ fs.chmodSync(curPath, mode);
77
+ }
78
+ });
79
+ fs.chmodSync(path, mode);
80
+ }
81
+ };
82
+
83
+ /**
84
+ * 获取数据存储路径
85
+ */
86
+ exports.getStorageDir = function () {
87
+ let env = process.env.EE_SERVER_ENV;
88
+ const appDir = env === 'local' || env === 'unittest' ? process.env.EE_HOME : process.env.EE_APP_USER_DATA;
89
+ const storageDir = path.join(appDir, 'data');
90
+ return storageDir;
91
91
  }
package/utils/index.js CHANGED
@@ -1,247 +1,247 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const constant = require('../lib/constant');
5
- const convert = require('koa-convert');
6
- const is = require('is-type-of');
7
- const co = require('co');
8
- const utility = require('utility');
9
- const eis = require('electron-is');
10
- const utilsCommon = require('./common');
11
-
12
- /**
13
- * 创建文件夹
14
- */
15
- exports.mkdir = function (dirpath, dirname) {
16
- return utilsCommon.mkdir(dirpath, dirname);
17
- }
18
-
19
- /**
20
- * 修改文件权限
21
- */
22
- exports.chmodPath = function (path, mode) {
23
- return utilsCommon.chmodPath(path, mode);
24
- }
25
-
26
- /**
27
- * 获取项目根目录package.json
28
- */
29
- exports.getPackage = function() {
30
- const cdb = this.getCoreDB();
31
- const config = cdb.getItem('config');
32
- const json = utility.readJSONSync(path.join(config.homeDir, 'package.json'));
33
-
34
- return json;
35
- };
36
-
37
- /**
38
- * 获取 coredb
39
- */
40
- exports.getCoreDB = function() {
41
- const coreDB = require('../lib/storage/index').JsonDB.connection('system');
42
- return coreDB;
43
- }
44
-
45
- /**
46
- * 获取 当前环境
47
- */
48
- exports.getEnv = function() {
49
- const cdb = this.getCoreDB();
50
- const env = cdb.getItem('config').env;
51
-
52
- return env;
53
- }
54
-
55
- /**
56
- * 获取 ee配置
57
- */
58
- exports.getEeConfig = function() {
59
- const cdb = this.getCoreDB();
60
- const config = cdb.getItem('config');
61
-
62
- return config;
63
- }
64
-
65
- /**
66
- * 获取 数据库存储路径
67
- */
68
- exports.getStorageDir = function() {
69
- const cdb = this.getCoreDB();
70
- const env = cdb.getItem('config').env;
71
-
72
- const appDir = env === 'local' || env === 'unittest' ? this.getHomeDir() : this.getAppUserDataDir();
73
- const storageDir = path.join(appDir, 'data');
74
-
75
- return storageDir;
76
- }
77
-
78
- /**
79
- * 获取 应用程序数据目录 (开发环境时,为项目根目录)
80
- */
81
- exports.getAppUserDataDir = function() {
82
- const cdb = this.getCoreDB();
83
- const config = cdb.getItem('config');
84
- const env = config.env;
85
- const dir = env === 'local' || env === 'unittest' ? config.homeDir : config.appUserDataDir;
86
- return dir;
87
- }
88
-
89
- /**
90
- * 获取 日志目录
91
- */
92
- exports.getLogDir = function() {
93
- const cdb = this.getCoreDB();
94
- const logPath = cdb.getItem('config').logger.dir;
95
- return logPath;
96
- }
97
-
98
- /**
99
- * 获取 home目录
100
- */
101
- exports.getHomeDir = function() {
102
- const cdb = this.getCoreDB();
103
- const homePath = cdb.getItem('config').homeDir;
104
- return homePath;
105
- }
106
-
107
- /**
108
- * 获取 base目录
109
- */
110
- exports.getBaseDir = function() {
111
- const cdb = this.getCoreDB();
112
- const basePath = cdb.getItem('config').baseDir;
113
- return basePath;
114
- }
115
-
116
- /**
117
- * 获取 root目录
118
- */
119
- exports.getRootDir = function() {
120
- const cdb = this.getCoreDB();
121
- const rootPath = cdb.getItem('config').root;
122
- return rootPath;
123
- }
124
-
125
- /**
126
- * 获取 appUserData目录
127
- */
128
- exports.getAppUserDataDir = function() {
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
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const constant = require('../lib/constant');
5
+ const convert = require('koa-convert');
6
+ const is = require('is-type-of');
7
+ const co = require('co');
8
+ const utility = require('utility');
9
+ const eis = require('electron-is');
10
+ const utilsCommon = require('./common');
11
+
12
+ /**
13
+ * 创建文件夹
14
+ */
15
+ exports.mkdir = function (dirpath, dirname) {
16
+ return utilsCommon.mkdir(dirpath, dirname);
17
+ }
18
+
19
+ /**
20
+ * 修改文件权限
21
+ */
22
+ exports.chmodPath = function (path, mode) {
23
+ return utilsCommon.chmodPath(path, mode);
24
+ }
25
+
26
+ /**
27
+ * 获取项目根目录package.json
28
+ */
29
+ exports.getPackage = function() {
30
+ const cdb = this.getCoreDB();
31
+ const config = cdb.getItem('config');
32
+ const json = utility.readJSONSync(path.join(config.homeDir, 'package.json'));
33
+
34
+ return json;
35
+ };
36
+
37
+ /**
38
+ * 获取 coredb
39
+ */
40
+ exports.getCoreDB = function() {
41
+ const coreDB = require('../lib/storage/index').JsonDB.connection('system');
42
+ return coreDB;
43
+ }
44
+
45
+ /**
46
+ * 获取 当前环境
47
+ */
48
+ exports.getEnv = function() {
49
+ const cdb = this.getCoreDB();
50
+ const env = cdb.getItem('config').env;
51
+
52
+ return env;
53
+ }
54
+
55
+ /**
56
+ * 获取 ee配置
57
+ */
58
+ exports.getEeConfig = function() {
59
+ const cdb = this.getCoreDB();
60
+ const config = cdb.getItem('config');
61
+
62
+ return config;
63
+ }
64
+
65
+ /**
66
+ * 获取 数据库存储路径
67
+ */
68
+ exports.getStorageDir = function() {
69
+ const cdb = this.getCoreDB();
70
+ const env = cdb.getItem('config').env;
71
+
72
+ const appDir = env === 'local' || env === 'unittest' ? this.getHomeDir() : this.getAppUserDataDir();
73
+ const storageDir = path.join(appDir, 'data');
74
+
75
+ return storageDir;
76
+ }
77
+
78
+ /**
79
+ * 获取 应用程序数据目录 (开发环境时,为项目根目录)
80
+ */
81
+ exports.getAppUserDataDir = function() {
82
+ const cdb = this.getCoreDB();
83
+ const config = cdb.getItem('config');
84
+ const env = config.env;
85
+ const dir = env === 'local' || env === 'unittest' ? config.homeDir : config.appUserDataDir;
86
+ return dir;
87
+ }
88
+
89
+ /**
90
+ * 获取 日志目录
91
+ */
92
+ exports.getLogDir = function() {
93
+ const cdb = this.getCoreDB();
94
+ const logPath = cdb.getItem('config').logger.dir;
95
+ return logPath;
96
+ }
97
+
98
+ /**
99
+ * 获取 home目录
100
+ */
101
+ exports.getHomeDir = function() {
102
+ const cdb = this.getCoreDB();
103
+ const homePath = cdb.getItem('config').homeDir;
104
+ return homePath;
105
+ }
106
+
107
+ /**
108
+ * 获取 base目录
109
+ */
110
+ exports.getBaseDir = function() {
111
+ const cdb = this.getCoreDB();
112
+ const basePath = cdb.getItem('config').baseDir;
113
+ return basePath;
114
+ }
115
+
116
+ /**
117
+ * 获取 root目录
118
+ */
119
+ exports.getRootDir = function() {
120
+ const cdb = this.getCoreDB();
121
+ const rootPath = cdb.getItem('config').root;
122
+ return rootPath;
123
+ }
124
+
125
+ /**
126
+ * 获取 appUserData目录
127
+ */
128
+ exports.getAppUserDataDir = function() {
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);
247
247
  }