ee-core 1.5.1 → 1.5.2-beta.2

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 (52) 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 +18 -18
  5. package/config/config.default.js +280 -280
  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 -359
  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/lowdb/adapters/Base.js +15 -0
  35. package/lib/storage/lowdb/adapters/FileAsync.js +41 -0
  36. package/lib/storage/lowdb/adapters/FileSync.js +39 -0
  37. package/lib/storage/lowdb/adapters/LocalStorage.js +20 -0
  38. package/lib/storage/lowdb/adapters/Memory.js +8 -0
  39. package/lib/storage/lowdb/adapters/_stringify.js +4 -0
  40. package/lib/storage/lowdb/common.js +33 -0
  41. package/lib/storage/lowdb/fp.js +23 -0
  42. package/lib/storage/lowdb/isPromise.js +6 -0
  43. package/lib/storage/lowdb/main.js +46 -0
  44. package/lib/storage/lowdb/nano.js +5 -0
  45. package/lib/storage/lowdbStorage.js +98 -98
  46. package/lib/storage/sqliteStorage.js +127 -127
  47. package/package.json +48 -45
  48. package/tools/encrypt.js +274 -274
  49. package/tools/replaceDist.js +61 -61
  50. package/utils/common.js +90 -90
  51. package/utils/index.js +246 -246
  52. package/utils/wrap.js +37 -37
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
  }
package/utils/wrap.js CHANGED
@@ -1,38 +1,38 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
- const is = require('is-type-of');
5
-
6
- exports.getProperties = (filepath, { caseStyle }) => {
7
- // if caseStyle is function, return the result of function
8
- if (is.function(caseStyle)) {
9
- const result = caseStyle(filepath);
10
- assert(is.array(result), `caseStyle expect an array, but got ${result}`);
11
- return result;
12
- }
13
- // use default camelize
14
- return this.defaultCamelize(filepath, caseStyle);
15
- }
16
-
17
- exports.defaultCamelize = (filepath, caseStyle) => {
18
- const properties = filepath.substring(0, filepath.lastIndexOf('.')).split('/');
19
- return properties.map(property => {
20
- if (!/^[a-z][a-z0-9_-]*$/i.test(property)) {
21
- throw new Error(`${property} is not match 'a-z0-9_-' in ${filepath}`);
22
- }
23
-
24
- property = property.replace(/[_-][a-z]/ig, s => s.substring(1).toUpperCase());
25
- let first = property[0];
26
- switch (caseStyle) {
27
- case 'lower':
28
- first = first.toLowerCase();
29
- break;
30
- case 'upper':
31
- first = first.toUpperCase();
32
- break;
33
- case 'camel':
34
- default:
35
- }
36
- return first + property.substring(1);
37
- });
1
+ 'use strict';
2
+
3
+ const assert = require('assert');
4
+ const is = require('is-type-of');
5
+
6
+ exports.getProperties = (filepath, { caseStyle }) => {
7
+ // if caseStyle is function, return the result of function
8
+ if (is.function(caseStyle)) {
9
+ const result = caseStyle(filepath);
10
+ assert(is.array(result), `caseStyle expect an array, but got ${result}`);
11
+ return result;
12
+ }
13
+ // use default camelize
14
+ return this.defaultCamelize(filepath, caseStyle);
15
+ }
16
+
17
+ exports.defaultCamelize = (filepath, caseStyle) => {
18
+ const properties = filepath.substring(0, filepath.lastIndexOf('.')).split('/');
19
+ return properties.map(property => {
20
+ if (!/^[a-z][a-z0-9_-]*$/i.test(property)) {
21
+ throw new Error(`${property} is not match 'a-z0-9_-' in ${filepath}`);
22
+ }
23
+
24
+ property = property.replace(/[_-][a-z]/ig, s => s.substring(1).toUpperCase());
25
+ let first = property[0];
26
+ switch (caseStyle) {
27
+ case 'lower':
28
+ first = first.toLowerCase();
29
+ break;
30
+ case 'upper':
31
+ first = first.toUpperCase();
32
+ break;
33
+ case 'camel':
34
+ default:
35
+ }
36
+ return first + property.substring(1);
37
+ });
38
38
  }