ee-core 1.2.7 → 1.2.8-beta.4

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 (43) 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 +250 -247
  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 +451 -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 +80 -80
  20. package/lib/baseApp.js +118 -118
  21. package/lib/constant.js +28 -28
  22. package/lib/eeApp.js +326 -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 +102 -104
  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 -21
  33. package/lib/storage/lowdbStorage.js +98 -143
  34. package/lib/storage/sqliteStorage.js +59 -0
  35. package/package.json +45 -45
  36. package/resource/loading.html +21 -21
  37. package/resource/view_example.html +21 -21
  38. package/tools/codeCompress.js +204 -204
  39. package/tools/replaceDist.js +76 -76
  40. package/utils/common.js +91 -30
  41. package/utils/index.js +207 -207
  42. package/utils/wrap.js +37 -37
  43. package/lib/storage/appStorage.js +0 -14
@@ -1,22 +1,22 @@
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>
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
22
  </html>
@@ -1,22 +1,22 @@
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>
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
22
  </html>
@@ -1,204 +1,204 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const fs = require('fs');
5
- const fsPro = require('fs-extra');
6
- const UglifyJS = require('uglify-js');
7
-
8
- class CodeCompress {
9
- constructor() {
10
- const directory = [
11
- 'app',
12
- 'electron',
13
- 'config'
14
- ];
15
- this.dirs = [];
16
-
17
- this.basePath = process.cwd();
18
- this.backupCodeDir = path.join(this.basePath, 'run', 'backup_code');
19
-
20
- // 检查存在的目录
21
- for (let i = 0; i < directory.length; i++) {
22
- let codeDirPath = path.join(this.basePath, directory[i]);
23
- if (fs.existsSync(codeDirPath)) {
24
- this.dirs.push(directory[i]);
25
- }
26
- }
27
- console.log('dirs:', this.dirs);
28
- }
29
-
30
- /**
31
- * 备份 app、electron目录代码
32
- */
33
- backup () {
34
- console.log('[ee-core] [code_compress] [backup] start');
35
- this.rmBackup();
36
-
37
- for (let i = 0; i < this.dirs.length; i++) {
38
- // check code dir
39
- let codeDirPath = path.join(this.basePath, this.dirs[i]);
40
- if (!fs.existsSync(codeDirPath)) {
41
- console.log('[ee-core] [code_compress] [backup] ERROR: %s is not exist', codeDirPath);
42
- return
43
- }
44
-
45
- // copy
46
- let targetDir = path.join(this.backupCodeDir, this.dirs[i]);
47
- console.log('[ee-core] [code_compress] [backup] targetDir:', targetDir);
48
- if (!fs.existsSync(targetDir)) {
49
- this.mkdir(targetDir);
50
- this.chmodPath(targetDir, '777');
51
- }
52
-
53
- fsPro.copySync(codeDirPath, targetDir);
54
- }
55
- console.log('[ee-core] [code_compress] [backup] success');
56
- }
57
-
58
- /**
59
- * 还原代码
60
- */
61
- restore () {
62
- console.log('[ee-core] [code_compress] [restore] start');
63
- for (let i = 0; i < this.dirs.length; i++) {
64
- let codeDirPath = path.join(this.backupCodeDir, this.dirs[i]);
65
- let targetDir = path.join(this.basePath, this.dirs[i]);
66
- fsPro.copySync(codeDirPath, targetDir);
67
- }
68
- console.log('[ee-core] [code_compress] [restore] success');
69
- };
70
-
71
- /**
72
- * 压缩代码
73
- */
74
- compress () {
75
- console.log('[ee-core] [code_compress] [compress] start');
76
- for (let i = 0; i < this.dirs.length; i++) {
77
- let codeDirPath = path.join(this.basePath, this.dirs[i]);
78
- this.compressLoop(codeDirPath);
79
- }
80
- console.log('[ee-core] [code_compress] [compress] success');
81
- };
82
-
83
- compressLoop (dirPath) {
84
- let files = [];
85
- if (fs.existsSync(dirPath)) {
86
- files = fs.readdirSync(dirPath);
87
- files.forEach((file, index) => {
88
- let curPath = dirPath + '/' + file;
89
- if (fs.statSync(curPath).isDirectory()) {
90
- this.compressLoop(curPath);
91
- } else {
92
- if (path.extname(curPath) === '.js') {
93
- this.miniFile(curPath);
94
- }
95
- }
96
- });
97
- }
98
- }
99
-
100
- miniFile (file) {
101
- let code = fs.readFileSync(file, "utf8");
102
- const options = {
103
- mangle: {
104
- toplevel: false,
105
- },
106
- };
107
-
108
- let result = UglifyJS.minify(code, options);
109
- fs.writeFileSync(file, result.code, "utf8");
110
- }
111
-
112
- /**
113
- * 格式化参数
114
- */
115
- formatArgvs () {
116
- // argv
117
- let argvs = [];
118
- for (let i = 0; i < process.argv.length; i++) {
119
- const tmpArgv = process.argv[i]
120
- if (tmpArgv.indexOf('--') !== -1) {
121
- argvs.push(tmpArgv.substring(2))
122
- }
123
- }
124
- return argvs;
125
- }
126
-
127
- /**
128
- * 移除备份
129
- */
130
- rmBackup () {
131
- if (fs.existsSync(this.backupCodeDir)) {
132
- fs.rmSync(this.backupCodeDir, {recursive: true, force: true});
133
- }
134
- return;
135
- }
136
-
137
- /**
138
- * 检查文件是否存在
139
- */
140
- fileExist (filePath) {
141
- try {
142
- return fs.statSync(filePath).isFile();
143
- } catch (err) {
144
- return false;
145
- }
146
- };
147
-
148
- mkdir (dirpath, dirname) {
149
- // 判断是否是第一次调用
150
- if (typeof dirname === 'undefined') {
151
- if (fs.existsSync(dirpath)) {
152
- return;
153
- }
154
- this.mkdir(dirpath, path.dirname(dirpath));
155
- } else {
156
- // 判断第二个参数是否正常,避免调用时传入错误参数
157
- if (dirname !== path.dirname(dirpath)) {
158
- this.mkdir(dirpath);
159
- return;
160
- }
161
- if (fs.existsSync(dirname)) {
162
- fs.mkdirSync(dirpath);
163
- } else {
164
- this.mkdir(dirname, path.dirname(dirname));
165
- fs.mkdirSync(dirpath);
166
- }
167
- }
168
- };
169
-
170
- chmodPath (path, mode) {
171
- let files = [];
172
- if (fs.existsSync(path)) {
173
- files = fs.readdirSync(path);
174
- files.forEach((file, index) => {
175
- const curPath = path + '/' + file;
176
- if (fs.statSync(curPath).isDirectory()) {
177
- this.chmodPath(curPath, mode); // 递归删除文件夹
178
- } else {
179
- fs.chmodSync(curPath, mode);
180
- }
181
- });
182
- fs.chmodSync(path, mode);
183
- }
184
- };
185
- }
186
-
187
- const compress = () => {
188
- const cc = new CodeCompress();
189
- cc.backup();
190
- cc.compress();
191
- }
192
-
193
- const restore = () => {
194
- const cc = new CodeCompress();
195
- cc.restore();
196
- }
197
-
198
- module.exports = {
199
- compress,
200
- restore
201
- };
202
-
203
-
204
-
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+ const fsPro = require('fs-extra');
6
+ const UglifyJS = require('uglify-js');
7
+
8
+ class CodeCompress {
9
+ constructor() {
10
+ const directory = [
11
+ 'app',
12
+ 'electron',
13
+ 'config'
14
+ ];
15
+ this.dirs = [];
16
+
17
+ this.basePath = process.cwd();
18
+ this.backupCodeDir = path.join(this.basePath, 'run', 'backup_code');
19
+
20
+ // 检查存在的目录
21
+ for (let i = 0; i < directory.length; i++) {
22
+ let codeDirPath = path.join(this.basePath, directory[i]);
23
+ if (fs.existsSync(codeDirPath)) {
24
+ this.dirs.push(directory[i]);
25
+ }
26
+ }
27
+ console.log('dirs:', this.dirs);
28
+ }
29
+
30
+ /**
31
+ * 备份 app、electron目录代码
32
+ */
33
+ backup () {
34
+ console.log('[ee-core] [code_compress] [backup] start');
35
+ this.rmBackup();
36
+
37
+ for (let i = 0; i < this.dirs.length; i++) {
38
+ // check code dir
39
+ let codeDirPath = path.join(this.basePath, this.dirs[i]);
40
+ if (!fs.existsSync(codeDirPath)) {
41
+ console.log('[ee-core] [code_compress] [backup] ERROR: %s is not exist', codeDirPath);
42
+ return
43
+ }
44
+
45
+ // copy
46
+ let targetDir = path.join(this.backupCodeDir, this.dirs[i]);
47
+ console.log('[ee-core] [code_compress] [backup] targetDir:', targetDir);
48
+ if (!fs.existsSync(targetDir)) {
49
+ this.mkdir(targetDir);
50
+ this.chmodPath(targetDir, '777');
51
+ }
52
+
53
+ fsPro.copySync(codeDirPath, targetDir);
54
+ }
55
+ console.log('[ee-core] [code_compress] [backup] success');
56
+ }
57
+
58
+ /**
59
+ * 还原代码
60
+ */
61
+ restore () {
62
+ console.log('[ee-core] [code_compress] [restore] start');
63
+ for (let i = 0; i < this.dirs.length; i++) {
64
+ let codeDirPath = path.join(this.backupCodeDir, this.dirs[i]);
65
+ let targetDir = path.join(this.basePath, this.dirs[i]);
66
+ fsPro.copySync(codeDirPath, targetDir);
67
+ }
68
+ console.log('[ee-core] [code_compress] [restore] success');
69
+ };
70
+
71
+ /**
72
+ * 压缩代码
73
+ */
74
+ compress () {
75
+ console.log('[ee-core] [code_compress] [compress] start');
76
+ for (let i = 0; i < this.dirs.length; i++) {
77
+ let codeDirPath = path.join(this.basePath, this.dirs[i]);
78
+ this.compressLoop(codeDirPath);
79
+ }
80
+ console.log('[ee-core] [code_compress] [compress] success');
81
+ };
82
+
83
+ compressLoop (dirPath) {
84
+ let files = [];
85
+ if (fs.existsSync(dirPath)) {
86
+ files = fs.readdirSync(dirPath);
87
+ files.forEach((file, index) => {
88
+ let curPath = dirPath + '/' + file;
89
+ if (fs.statSync(curPath).isDirectory()) {
90
+ this.compressLoop(curPath);
91
+ } else {
92
+ if (path.extname(curPath) === '.js') {
93
+ this.miniFile(curPath);
94
+ }
95
+ }
96
+ });
97
+ }
98
+ }
99
+
100
+ miniFile (file) {
101
+ let code = fs.readFileSync(file, "utf8");
102
+ const options = {
103
+ mangle: {
104
+ toplevel: false,
105
+ },
106
+ };
107
+
108
+ let result = UglifyJS.minify(code, options);
109
+ fs.writeFileSync(file, result.code, "utf8");
110
+ }
111
+
112
+ /**
113
+ * 格式化参数
114
+ */
115
+ formatArgvs () {
116
+ // argv
117
+ let argvs = [];
118
+ for (let i = 0; i < process.argv.length; i++) {
119
+ const tmpArgv = process.argv[i]
120
+ if (tmpArgv.indexOf('--') !== -1) {
121
+ argvs.push(tmpArgv.substring(2))
122
+ }
123
+ }
124
+ return argvs;
125
+ }
126
+
127
+ /**
128
+ * 移除备份
129
+ */
130
+ rmBackup () {
131
+ if (fs.existsSync(this.backupCodeDir)) {
132
+ fs.rmSync(this.backupCodeDir, {recursive: true, force: true});
133
+ }
134
+ return;
135
+ }
136
+
137
+ /**
138
+ * 检查文件是否存在
139
+ */
140
+ fileExist (filePath) {
141
+ try {
142
+ return fs.statSync(filePath).isFile();
143
+ } catch (err) {
144
+ return false;
145
+ }
146
+ };
147
+
148
+ mkdir (dirpath, dirname) {
149
+ // 判断是否是第一次调用
150
+ if (typeof dirname === 'undefined') {
151
+ if (fs.existsSync(dirpath)) {
152
+ return;
153
+ }
154
+ this.mkdir(dirpath, path.dirname(dirpath));
155
+ } else {
156
+ // 判断第二个参数是否正常,避免调用时传入错误参数
157
+ if (dirname !== path.dirname(dirpath)) {
158
+ this.mkdir(dirpath);
159
+ return;
160
+ }
161
+ if (fs.existsSync(dirname)) {
162
+ fs.mkdirSync(dirpath);
163
+ } else {
164
+ this.mkdir(dirname, path.dirname(dirname));
165
+ fs.mkdirSync(dirpath);
166
+ }
167
+ }
168
+ };
169
+
170
+ chmodPath (path, mode) {
171
+ let files = [];
172
+ if (fs.existsSync(path)) {
173
+ files = fs.readdirSync(path);
174
+ files.forEach((file, index) => {
175
+ const curPath = path + '/' + file;
176
+ if (fs.statSync(curPath).isDirectory()) {
177
+ this.chmodPath(curPath, mode); // 递归删除文件夹
178
+ } else {
179
+ fs.chmodSync(curPath, mode);
180
+ }
181
+ });
182
+ fs.chmodSync(path, mode);
183
+ }
184
+ };
185
+ }
186
+
187
+ const compress = () => {
188
+ const cc = new CodeCompress();
189
+ cc.backup();
190
+ cc.compress();
191
+ }
192
+
193
+ const restore = () => {
194
+ const cc = new CodeCompress();
195
+ cc.restore();
196
+ }
197
+
198
+ module.exports = {
199
+ compress,
200
+ restore
201
+ };
202
+
203
+
204
+
@@ -1,76 +1,76 @@
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 targetDir = path.join(homeDir, 'app', 'public');
40
- const sourceIndexFile = path.join(sourceDir, 'index.html');
41
- const targetIndexFile = path.join(homeDir, 'app', 'view', 'index.ejs');
42
-
43
- if (!fileExist(sourceIndexFile)) {
44
- console.error('[ee-core] [replace_dist] ERROR 前端资源不存在,请构建!!!');
45
- return
46
- }
47
-
48
- // 复制到ee资源目录
49
- const eeResourceDir = path.join(homeDir, 'public', 'dist');
50
-
51
- // 清空历史资源
52
- fs.rmdirSync(eeResourceDir, {recursive: true});
53
- console.log('[ee-core] [replace_dist] 清空历史资源:', eeResourceDir);
54
-
55
- fsPro.copySync(sourceDir, eeResourceDir);
56
- console.log('[ee-core] [replace_dist] 复制资源到:', eeResourceDir);
57
-
58
- // 复制到egg资源目录
59
- if (fs.existsSync(targetDir)) {
60
- console.log('[ee-core] [replace_dist] 重置egg资源:', targetDir);
61
- fs.rmdirSync(targetDir, {recursive: true});
62
-
63
- console.log('[ee-core] [replace_dist] 复制资源到egg:', sourceDir);
64
- fsPro.copySync(sourceDir, targetDir);
65
-
66
- // replace ejs
67
- fsPro.copySync(sourceIndexFile, targetIndexFile);
68
- console.log('[ee-core] [replace_dist] 替换 egg index.ejs');
69
- }
70
-
71
- console.log('[ee-core] [replace_dist] 结束');
72
- }
73
- }
74
-
75
-
76
-
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 targetDir = path.join(homeDir, 'app', 'public');
40
+ const sourceIndexFile = path.join(sourceDir, 'index.html');
41
+ const targetIndexFile = path.join(homeDir, 'app', 'view', 'index.ejs');
42
+
43
+ if (!fileExist(sourceIndexFile)) {
44
+ console.error('[ee-core] [replace_dist] ERROR 前端资源不存在,请构建!!!');
45
+ return
46
+ }
47
+
48
+ // 复制到ee资源目录
49
+ const eeResourceDir = path.join(homeDir, 'public', 'dist');
50
+
51
+ // 清空历史资源
52
+ fs.rmdirSync(eeResourceDir, {recursive: true});
53
+ console.log('[ee-core] [replace_dist] 清空历史资源:', eeResourceDir);
54
+
55
+ fsPro.copySync(sourceDir, eeResourceDir);
56
+ console.log('[ee-core] [replace_dist] 复制资源到:', eeResourceDir);
57
+
58
+ // 复制到egg资源目录
59
+ if (fs.existsSync(targetDir)) {
60
+ console.log('[ee-core] [replace_dist] 重置egg资源:', targetDir);
61
+ fs.rmdirSync(targetDir, {recursive: true});
62
+
63
+ console.log('[ee-core] [replace_dist] 复制资源到egg:', sourceDir);
64
+ fsPro.copySync(sourceDir, targetDir);
65
+
66
+ // replace ejs
67
+ fsPro.copySync(sourceIndexFile, targetIndexFile);
68
+ console.log('[ee-core] [replace_dist] 替换 egg index.ejs');
69
+ }
70
+
71
+ console.log('[ee-core] [replace_dist] 结束');
72
+ }
73
+ }
74
+
75
+
76
+