ee-core 1.2.8 → 1.2.9

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 (44) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +2 -2
  3. package/bin/tools.js +22 -22
  4. package/config/config.default.js +262 -250
  5. package/core/index.js +12 -12
  6. package/core/lib/ee.js +209 -209
  7. package/core/lib/loader/context_loader.js +105 -105
  8. package/core/lib/loader/ee_loader.js +447 -451
  9. package/core/lib/loader/file_loader.js +262 -262
  10. package/core/lib/loader/mixin/config.js +138 -138
  11. package/core/lib/loader/mixin/controller.js +123 -123
  12. package/core/lib/loader/mixin/service.js +29 -29
  13. package/core/lib/utils/base_context_class.js +34 -34
  14. package/core/lib/utils/index.js +100 -100
  15. package/core/lib/utils/sequencify.js +59 -59
  16. package/core/lib/utils/timing.js +77 -77
  17. package/index.js +49 -49
  18. package/lib/appLoader.js +45 -45
  19. package/lib/application.js +81 -80
  20. package/lib/baseApp.js +133 -118
  21. package/lib/constant.js +28 -28
  22. package/lib/eeApp.js +321 -326
  23. package/lib/helper.js +51 -51
  24. package/lib/httpclient.js +136 -136
  25. package/lib/logger.js +46 -46
  26. package/lib/socket/httpServer.js +134 -102
  27. package/lib/socket/io.js +23 -23
  28. package/lib/socket/ipcServer.js +128 -128
  29. package/lib/socket/socketClient.js +50 -50
  30. package/lib/socket/socketServer.js +76 -76
  31. package/lib/socket/start.js +22 -22
  32. package/lib/storage/index.js +33 -33
  33. package/lib/storage/lowdbStorage.js +98 -98
  34. package/lib/storage/sqliteStorage.js +58 -58
  35. package/package.json +45 -45
  36. package/tools/codeCompress.js +204 -204
  37. package/tools/replaceDist.js +76 -76
  38. package/utils/common.js +90 -90
  39. package/utils/index.js +151 -207
  40. package/utils/wrap.js +37 -37
  41. package/resource/images/loding.gif +0 -0
  42. package/resource/images/tray_logo.png +0 -0
  43. package/resource/loading.html +0 -22
  44. package/resource/view_example.html +0 -22
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,207 +1,151 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const constant = require('../lib/constant');
6
- const convert = require('koa-convert');
7
- const is = require('is-type-of');
8
- const co = require('co');
9
- const utility = require('utility');
10
- const eis = require('electron-is');
11
-
12
- /**
13
- * 创建文件夹
14
- */
15
- exports.mkdir = function(dirpath, dirname) {
16
- // 判断是否是第一次调用
17
- if (typeof dirname === 'undefined') {
18
- if (fs.existsSync(dirpath)) {
19
- return;
20
- }
21
- this.mkdir(dirpath, path.dirname(dirpath));
22
- } else {
23
- // 判断第二个参数是否正常,避免调用时传入错误参数
24
- if (dirname !== path.dirname(dirpath)) {
25
- this.mkdir(dirpath);
26
- return;
27
- }
28
- if (fs.existsSync(dirname)) {
29
- fs.mkdirSync(dirpath);
30
- } else {
31
- this.mkdir(dirname, path.dirname(dirname));
32
- fs.mkdirSync(dirpath);
33
- }
34
- }
35
- };
36
-
37
- /**
38
- * 修改文件权限
39
- */
40
- exports.chmodPath = function(path, mode) {
41
- let files = [];
42
- if (fs.existsSync(path)) {
43
- files = fs.readdirSync(path);
44
- files.forEach((file, index) => {
45
- const curPath = path + '/' + file;
46
- if (fs.statSync(curPath).isDirectory()) {
47
- this.chmodPath(curPath, mode); // 递归删除文件夹
48
- } else {
49
- fs.chmodSync(curPath, mode);
50
- }
51
- });
52
- fs.chmodSync(path, mode);
53
- }
54
- };
55
-
56
-
57
- /**
58
- * 获取项目根目录package.json
59
- */
60
- exports.getPackage = function() {
61
- const cdb = this.getCoreDB();
62
- const config = cdb.getItem('config');
63
- const json = utility.readJSONSync(path.join(config.homeDir, 'package.json'));
64
-
65
- return json;
66
- };
67
-
68
- /**
69
- * 获取 coredb
70
- */
71
- exports.getCoreDB = function() {
72
- const coreDB = require('../lib/storage/index').JsonDB.connection('system');
73
- return coreDB;
74
- }
75
-
76
- /**
77
- * 获取 ee配置
78
- */
79
- exports.getEeConfig = function() {
80
- const cdb = this.getCoreDB();
81
- const config = cdb.getItem('config');
82
-
83
- return config;
84
- }
85
-
86
- /**
87
- * 获取 egg配置
88
- */
89
- exports.getEggConfig = function() {
90
- const cdb = this.getCoreDB();
91
- const config = cdb.getItem('config');
92
-
93
- return config.egg;
94
- }
95
-
96
- /**
97
- * 获取 数据库存储路径
98
- */
99
- exports.getStorageDir = function() {
100
- const cdb = this.getCoreDB();
101
- const dirPath = cdb.getStorageDir();
102
-
103
- return dirPath;
104
- }
105
-
106
- /**
107
- * 获取 应用程序数据目录 (开发环境时,为项目根目录)
108
- */
109
- exports.getAppUserDataDir = function() {
110
- const cdb = this.getCoreDB();
111
- const config = cdb.getItem('config');
112
- const env = config.env;
113
- const dir = env === 'local' || env === 'unittest' ? config.homeDir : config.appUserDataDir;
114
- return dir;
115
- }
116
-
117
- /**
118
- * 获取 日志目录
119
- */
120
- exports.getLogDir = function() {
121
- const logPath = path.join(this.getAppUserDataDir(), 'logs');
122
- return logPath;
123
- }
124
-
125
- /**
126
- * 获取 socketio port
127
- */
128
- exports.getSocketPort = function() {
129
- const cdb = this.getCoreDB();
130
- const port = cdb.getItem('config').socketServer.port;
131
- return parseInt(port);
132
- }
133
-
134
- /**
135
- * 获取 socket channel
136
- */
137
- exports.getSocketChannel = function() {
138
- return constant.socketIo.channel;
139
- }
140
-
141
- /**
142
- * 获取 额外资源目录
143
- */
144
- exports.getExtraResourcesDir = function() {
145
- const cdb = this.getCoreDB();
146
- const config = cdb.getItem('config');
147
- const execDir = config.execDir;
148
-
149
- // 资源路径不同
150
- let dir = '';
151
- if (config.isPackaged) {
152
- // 打包后 execDir为 应用程序 exe\dmg\dep软件所在目录;打包前该值是项目根目录
153
- // windows和MacOs不一样
154
- dir = path.join(execDir, "resources", "extraResources");
155
- if (eis.macOS()) {
156
- dir = path.join(execDir, "..", "Resources", "extraResources");
157
- }
158
- } else {
159
- // 打包前
160
- dir = path.join(execDir, "build", "extraResources");
161
- }
162
- return dir;
163
- }
164
-
165
- /**
166
- * 执行一个函数
167
- */
168
- exports.callFn = async function (fn, args, ctx) {
169
- args = args || [];
170
- if (!is.function(fn)) return;
171
- if (is.generatorFunction(fn)) fn = co.wrap(fn);
172
- return ctx ? fn.call(ctx, ...args) : fn(...args);
173
- }
174
-
175
- exports.middleware = function (fn) {
176
- return is.generatorFunction(fn) ? convert(fn) : fn;
177
- }
178
-
179
- /**
180
- * 版本号比较
181
- */
182
- exports.compareVersion = function (v1, v2) {
183
- v1 = v1.split('.')
184
- v2 = v2.split('.')
185
- const len = Math.max(v1.length, v2.length)
186
-
187
- while (v1.length < len) {
188
- v1.push('0')
189
- }
190
- while (v2.length < len) {
191
- v2.push('0')
192
- }
193
-
194
- for (let i = 0; i < len; i++) {
195
- const num1 = parseInt(v1[i])
196
- const num2 = parseInt(v2[i])
197
-
198
- if (num1 > num2) {
199
- return 1
200
- } else if (num1 < num2) {
201
- return -1
202
- }
203
- }
204
-
205
- return 0
206
- }
207
-
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
+ * 获取 ee配置
47
+ */
48
+ exports.getEeConfig = function() {
49
+ const cdb = this.getCoreDB();
50
+ const config = cdb.getItem('config');
51
+
52
+ return config;
53
+ }
54
+
55
+ /**
56
+ * 获取 egg配置
57
+ */
58
+ exports.getEggConfig = function() {
59
+ const cdb = this.getCoreDB();
60
+ const config = cdb.getItem('config');
61
+
62
+ return config.egg;
63
+ }
64
+
65
+ /**
66
+ * 获取 数据库存储路径
67
+ */
68
+ exports.getStorageDir = function() {
69
+ return utilsCommon.getStorageDir();
70
+ }
71
+
72
+ /**
73
+ * 获取 应用程序数据目录 (开发环境时,为项目根目录)
74
+ */
75
+ exports.getAppUserDataDir = function() {
76
+ const cdb = this.getCoreDB();
77
+ const config = cdb.getItem('config');
78
+ const env = config.env;
79
+ const dir = env === 'local' || env === 'unittest' ? config.homeDir : config.appUserDataDir;
80
+ return dir;
81
+ }
82
+
83
+ /**
84
+ * 获取 日志目录
85
+ */
86
+ exports.getLogDir = function() {
87
+ const cdb = this.getCoreDB();
88
+ const logPath = cdb.getItem('config').logger.dir;
89
+ return logPath;
90
+ }
91
+
92
+ /**
93
+ * 获取 socketio port
94
+ */
95
+ exports.getSocketPort = function() {
96
+ const cdb = this.getCoreDB();
97
+ const port = cdb.getItem('config').socketServer.port;
98
+ return parseInt(port);
99
+ }
100
+
101
+ /**
102
+ * 获取 socket channel
103
+ */
104
+ exports.getSocketChannel = function() {
105
+ return constant.socketIo.channel;
106
+ }
107
+
108
+ /**
109
+ * 获取 额外资源目录
110
+ */
111
+ exports.getExtraResourcesDir = function() {
112
+ const cdb = this.getCoreDB();
113
+ const config = cdb.getItem('config');
114
+ const execDir = config.execDir;
115
+
116
+ // 资源路径不同
117
+ let dir = '';
118
+ if (config.isPackaged) {
119
+ // 打包后 execDir为 应用程序 exe\dmg\dep软件所在目录;打包前该值是项目根目录
120
+ // windows和MacOs不一样
121
+ dir = path.join(execDir, "resources", "extraResources");
122
+ if (eis.macOS()) {
123
+ dir = path.join(execDir, "..", "Resources", "extraResources");
124
+ }
125
+ } else {
126
+ // 打包前
127
+ dir = path.join(execDir, "build", "extraResources");
128
+ }
129
+ return dir;
130
+ }
131
+
132
+ /**
133
+ * 执行一个函数
134
+ */
135
+ exports.callFn = async function (fn, args, ctx) {
136
+ args = args || [];
137
+ if (!is.function(fn)) return;
138
+ if (is.generatorFunction(fn)) fn = co.wrap(fn);
139
+ return ctx ? fn.call(ctx, ...args) : fn(...args);
140
+ }
141
+
142
+ exports.middleware = function (fn) {
143
+ return is.generatorFunction(fn) ? convert(fn) : fn;
144
+ }
145
+
146
+ /**
147
+ * 版本号比较
148
+ */
149
+ exports.compareVersion = function (v1, v2) {
150
+ return utilsCommon.compareVersion(v1, v2);
151
+ }
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
  }
Binary file
Binary file
@@ -1,22 +0,0 @@
1
- <html>
2
- <head>
3
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4
- <style type="text/css">
5
- body{
6
- margin:0px auto;
7
- }
8
- #picture1 {
9
- position: absolute;
10
- left: 50%;
11
- top: 35%;
12
- transform: translate(-50%, -50%);
13
- }
14
- </style>
15
- <title></title>
16
- </head>
17
- <body>
18
- <div id="picture1">
19
- <img src="./images/loding.gif" />
20
- </div>
21
- </body>
22
- </html>
@@ -1,22 +0,0 @@
1
- <html>
2
- <head>
3
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4
- <style type="text/css">
5
- body{
6
- margin:0px auto;
7
- }
8
- #content {
9
- position: absolute;
10
- left: 50%;
11
- top: 35%;
12
- transform: translate(-50%, -50%);
13
- }
14
- </style>
15
- <title></title>
16
- </head>
17
- <body>
18
- <div id="content">
19
- 这是一个html页面
20
- </div>
21
- </body>
22
- </html>