ee-core 2.9.2-beta.1 → 2.10.0

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 (103) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +65 -65
  3. package/addon/index.js +34 -34
  4. package/addon/window/index.js +98 -98
  5. package/bin/tools.js +8 -8
  6. package/config/cache.js +41 -38
  7. package/config/config.default.js +331 -330
  8. package/config/index.js +75 -73
  9. package/const/channel.js +17 -17
  10. package/const/index.js +8 -8
  11. package/controller/baseContextClass.js +34 -34
  12. package/controller/index.js +34 -34
  13. package/core/index.js +10 -10
  14. package/core/lib/ee.js +216 -216
  15. package/core/lib/loader/context_loader.js +106 -106
  16. package/core/lib/loader/ee_loader.js +435 -435
  17. package/core/lib/loader/file_loader.js +326 -326
  18. package/core/lib/loader/mixin/addon.js +32 -32
  19. package/core/lib/loader/mixin/config.js +130 -130
  20. package/core/lib/loader/mixin/controller.js +125 -125
  21. package/core/lib/loader/mixin/service.js +28 -28
  22. package/core/lib/utils/base_context_class.js +34 -34
  23. package/core/lib/utils/function.js +30 -30
  24. package/core/lib/utils/index.js +133 -133
  25. package/core/lib/utils/sequencify.js +59 -59
  26. package/core/lib/utils/timing.js +77 -77
  27. package/cross/index.js +183 -183
  28. package/cross/spawnProcess.js +183 -183
  29. package/ee/appLoader.js +48 -48
  30. package/ee/application.js +99 -99
  31. package/ee/baseApp.js +103 -102
  32. package/ee/eeApp.js +408 -408
  33. package/ee/index.js +57 -57
  34. package/electron/app/index.js +64 -58
  35. package/electron/index.js +19 -19
  36. package/electron/window/index.js +73 -73
  37. package/electron/window/winState.js +186 -186
  38. package/exception/index.js +112 -112
  39. package/html/boot.html +98 -98
  40. package/html/cross-failure.html +28 -28
  41. package/html/failure.html +28 -28
  42. package/html/index.js +13 -13
  43. package/httpclient/index.js +161 -161
  44. package/index.js +54 -54
  45. package/jobs/baseJobClass.js +16 -16
  46. package/jobs/child/app.js +65 -65
  47. package/jobs/child/forkProcess.js +145 -145
  48. package/jobs/child/index.js +82 -82
  49. package/jobs/child-pool/index.js +213 -213
  50. package/jobs/index.js +8 -8
  51. package/jobs/load-balancer/algorithm/index.js +11 -11
  52. package/jobs/load-balancer/algorithm/minimumConnection.js +18 -18
  53. package/jobs/load-balancer/algorithm/polling.js +11 -11
  54. package/jobs/load-balancer/algorithm/random.js +9 -9
  55. package/jobs/load-balancer/algorithm/specify.js +14 -14
  56. package/jobs/load-balancer/algorithm/weights.js +21 -21
  57. package/jobs/load-balancer/algorithm/weightsMinimumConnection.js +29 -29
  58. package/jobs/load-balancer/algorithm/weightsPolling.js +22 -22
  59. package/jobs/load-balancer/algorithm/weightsRandom.js +16 -16
  60. package/jobs/load-balancer/consts.js +9 -9
  61. package/jobs/load-balancer/index.js +201 -201
  62. package/jobs/load-balancer/scheduler.js +31 -31
  63. package/jobs/renderer/index.js +141 -141
  64. package/jobs/renderer/loadView.js +40 -40
  65. package/jobs/unification.js +63 -63
  66. package/loader/index.js +172 -172
  67. package/log/index.js +68 -68
  68. package/log/logger.js +86 -80
  69. package/main/index.js +56 -56
  70. package/message/childMessage.js +54 -54
  71. package/message/index.js +18 -18
  72. package/old-utils/index.js +91 -91
  73. package/package.json +38 -38
  74. package/ps/index.js +371 -371
  75. package/services/baseContextClass.js +34 -34
  76. package/services/index.js +40 -40
  77. package/socket/httpServer.js +147 -147
  78. package/socket/index.js +81 -81
  79. package/socket/io.js +27 -27
  80. package/socket/ipcServer.js +112 -112
  81. package/socket/socketServer.js +69 -65
  82. package/storage/index.js +38 -38
  83. package/storage/jsondb/adapters/Base.js +23 -23
  84. package/storage/jsondb/adapters/FileSync.js +64 -52
  85. package/storage/jsondb/main.js +55 -42
  86. package/storage/jsondbStorage.js +195 -195
  87. package/storage/sqliteStorage.js +123 -123
  88. package/utils/co.js +237 -237
  89. package/utils/copyto.js +160 -160
  90. package/utils/depd/index.js +538 -538
  91. package/utils/depd/lib/browser/index.js +77 -77
  92. package/utils/extend.js +73 -73
  93. package/utils/get-port/index.d.ts +64 -64
  94. package/utils/get-port/index.js +148 -148
  95. package/utils/helper.js +220 -220
  96. package/utils/index.js +160 -160
  97. package/utils/ip.js +261 -261
  98. package/utils/is.js +145 -145
  99. package/utils/json.js +72 -72
  100. package/utils/pargv.js +263 -263
  101. package/utils/time/index.js +19 -19
  102. package/utils/time/ms.js +162 -162
  103. package/utils/wrap.js +35 -35
@@ -1,141 +1,141 @@
1
- const { BrowserWindow } = require('electron');
2
- const fs = require('fs');
3
- const LoadView = require('./loadView');
4
- const Loader = require('../../loader');
5
-
6
- class RendererJob {
7
-
8
- /**
9
- * constructor
10
- * @param {String} name - job name
11
- * @param {String} filepath - filepath to file
12
- * @param {Object} options - options to create BrowserWindow
13
- */
14
- constructor(name, filepath, opt = {}) {
15
- // TODO Object.assign 只能单层对象结构,多层的对象会直接覆盖
16
- let options = Object.assign({
17
- show: false,
18
- webPreferences: {
19
- webSecurity: true,
20
- nodeIntegration: true,
21
- contextIsolation: false,
22
- //enableRemoteModule: true
23
- }
24
- }, opt);
25
-
26
- this.subWin = new BrowserWindow(options);
27
-
28
- this.jobReady = false;
29
- this.exec = Loader.getFullpath(filepath);;
30
- this.name = name;
31
- this.listeners = [];
32
- this.callbacks = [];
33
- this.fails = [];
34
- this.id = this.subWin.id;
35
- this.webSecurity = options.webPreferences.webSecurity;
36
-
37
- // this.callbacks.push(() => {
38
- // MessageChannel.registry(name, this.id, this.subWin.webContents.getOSProcessId());
39
- // });
40
-
41
- // job state listener
42
- this.subWin.webContents.on('did-finish-load', this._didFinishLoad);
43
- this.subWin.webContents.on('did-fail-load', this._didFailLoad);
44
-
45
- // load job
46
- this._loadJob(this.exec);
47
- }
48
-
49
- /**
50
- * 显示开发者工具栏
51
- */
52
- openDevTools() {
53
- this.subWin.webContents.openDevTools({
54
- mode: 'undocked'
55
- });
56
- }
57
-
58
- /**
59
- * 窗口加载完成,即业务代码执行完毕
60
- */
61
- _didFinishLoad = () => {
62
- this.jobReady = true;
63
- this.callbacks.forEach(callback => {
64
- callback(this.id);
65
- });
66
- }
67
-
68
- /**
69
- * 窗口加载失败,即业务运行失败
70
- */
71
- _didFailLoad = (error) => {
72
- this.jobReady = false;
73
- this.fails.forEach(handle => {
74
- handle(error.toString());
75
- });
76
- }
77
-
78
-
79
- /**
80
- * 加载任务
81
- */
82
- _loadJob(filepath) {
83
- if (!this.webSecurity) {
84
- this._loadURLUnsafe(filepath);
85
- } else {
86
- this._loadURLSafe(filepath);
87
- }
88
- }
89
-
90
- /**
91
- * 安全的脚本注入
92
- */
93
- _loadURLSafe(filepath) {
94
- return new Promise((resolve, reject) => {
95
- fs.readFile(filepath, { encoding: 'utf-8' }, (err, buffer) => {
96
- if (err) {
97
- reject(err);
98
- this._didFailLoad(err);
99
- return console.error(err);
100
- }
101
-
102
- let param = {
103
- webSecurity: true,
104
- script: buffer.toString(),
105
- title: `${this.name} job`,
106
- base: filepath
107
- }
108
- const viewData = LoadView(param);
109
-
110
- this.subWin.loadURL(viewData)
111
- .then(resolve)
112
- .catch(err => {
113
- reject(err);
114
- this._didFailLoad(err);
115
- console.error(err);
116
- });
117
- })
118
- })
119
- }
120
-
121
- /**
122
- * 不安全的脚本注入
123
- */
124
- _loadURLUnsafe(filepath) {
125
- let param = {
126
- webSecurity: false,
127
- src: this.exec,
128
- title: `${this.name} job`,
129
- base: filepath
130
- }
131
- const viewData = LoadView(param);
132
-
133
- this.subWin.loadURL(viewData)
134
- .catch(err => {
135
- this._didFailLoad(err);
136
- console.error(err);
137
- });
138
- }
139
- }
140
-
141
- module.exports = RendererJob;
1
+ const { BrowserWindow } = require('electron');
2
+ const fs = require('fs');
3
+ const LoadView = require('./loadView');
4
+ const Loader = require('../../loader');
5
+
6
+ class RendererJob {
7
+
8
+ /**
9
+ * constructor
10
+ * @param {String} name - job name
11
+ * @param {String} filepath - filepath to file
12
+ * @param {Object} options - options to create BrowserWindow
13
+ */
14
+ constructor(name, filepath, opt = {}) {
15
+ // TODO Object.assign 只能单层对象结构,多层的对象会直接覆盖
16
+ let options = Object.assign({
17
+ show: false,
18
+ webPreferences: {
19
+ webSecurity: true,
20
+ nodeIntegration: true,
21
+ contextIsolation: false,
22
+ //enableRemoteModule: true
23
+ }
24
+ }, opt);
25
+
26
+ this.subWin = new BrowserWindow(options);
27
+
28
+ this.jobReady = false;
29
+ this.exec = Loader.getFullpath(filepath);;
30
+ this.name = name;
31
+ this.listeners = [];
32
+ this.callbacks = [];
33
+ this.fails = [];
34
+ this.id = this.subWin.id;
35
+ this.webSecurity = options.webPreferences.webSecurity;
36
+
37
+ // this.callbacks.push(() => {
38
+ // MessageChannel.registry(name, this.id, this.subWin.webContents.getOSProcessId());
39
+ // });
40
+
41
+ // job state listener
42
+ this.subWin.webContents.on('did-finish-load', this._didFinishLoad);
43
+ this.subWin.webContents.on('did-fail-load', this._didFailLoad);
44
+
45
+ // load job
46
+ this._loadJob(this.exec);
47
+ }
48
+
49
+ /**
50
+ * 显示开发者工具栏
51
+ */
52
+ openDevTools() {
53
+ this.subWin.webContents.openDevTools({
54
+ mode: 'undocked'
55
+ });
56
+ }
57
+
58
+ /**
59
+ * 窗口加载完成,即业务代码执行完毕
60
+ */
61
+ _didFinishLoad = () => {
62
+ this.jobReady = true;
63
+ this.callbacks.forEach(callback => {
64
+ callback(this.id);
65
+ });
66
+ }
67
+
68
+ /**
69
+ * 窗口加载失败,即业务运行失败
70
+ */
71
+ _didFailLoad = (error) => {
72
+ this.jobReady = false;
73
+ this.fails.forEach(handle => {
74
+ handle(error.toString());
75
+ });
76
+ }
77
+
78
+
79
+ /**
80
+ * 加载任务
81
+ */
82
+ _loadJob(filepath) {
83
+ if (!this.webSecurity) {
84
+ this._loadURLUnsafe(filepath);
85
+ } else {
86
+ this._loadURLSafe(filepath);
87
+ }
88
+ }
89
+
90
+ /**
91
+ * 安全的脚本注入
92
+ */
93
+ _loadURLSafe(filepath) {
94
+ return new Promise((resolve, reject) => {
95
+ fs.readFile(filepath, { encoding: 'utf-8' }, (err, buffer) => {
96
+ if (err) {
97
+ reject(err);
98
+ this._didFailLoad(err);
99
+ return console.error(err);
100
+ }
101
+
102
+ let param = {
103
+ webSecurity: true,
104
+ script: buffer.toString(),
105
+ title: `${this.name} job`,
106
+ base: filepath
107
+ }
108
+ const viewData = LoadView(param);
109
+
110
+ this.subWin.loadURL(viewData)
111
+ .then(resolve)
112
+ .catch(err => {
113
+ reject(err);
114
+ this._didFailLoad(err);
115
+ console.error(err);
116
+ });
117
+ })
118
+ })
119
+ }
120
+
121
+ /**
122
+ * 不安全的脚本注入
123
+ */
124
+ _loadURLUnsafe(filepath) {
125
+ let param = {
126
+ webSecurity: false,
127
+ src: this.exec,
128
+ title: `${this.name} job`,
129
+ base: filepath
130
+ }
131
+ const viewData = LoadView(param);
132
+
133
+ this.subWin.loadURL(viewData)
134
+ .catch(err => {
135
+ this._didFailLoad(err);
136
+ console.error(err);
137
+ });
138
+ }
139
+ }
140
+
141
+ module.exports = RendererJob;
@@ -1,41 +1,41 @@
1
- //require('bytenode');
2
- const Ps = require('../../ps');
3
-
4
- /**
5
- * loadView 生成BrowserWindow的html content
6
- */
7
- const loadView = function (opt = {}) {
8
- const webSecurity = opt.webSecurity;
9
- const src = opt.src;
10
- const title = opt.title;
11
- const script = opt.script;
12
-
13
- //const scriptUrl = new URL('eefile://' + src);
14
- const scriptUrl = 'eefile://' + src;
15
- console.log('[ee-core:job] scriptUrl: ', scriptUrl);
16
-
17
- // 脚本内容
18
- //const scriptBytenode = Ps.isDev() ? '' : `<script> require('bytenode') </script>`;
19
- const scriptContent = webSecurity ? `<script> ${ script } </script>` : `<script src='${scriptUrl}'></script>`;
20
-
21
- // html内容
22
- const htmlContent = (`
23
- <!DOCTYPE html>
24
- <html>
25
- <head>
26
- <title>${title}</title>
27
- <meta charset="UTF-8">
28
- </head>
29
- <body>
30
- ${scriptContent}
31
- </body>
32
- </html>
33
- `);
34
-
35
- const DataURI = 'data:text/html;charset=UTF-8,';
36
- const data = DataURI + encodeURIComponent(htmlContent);
37
-
38
- return data;
39
- };
40
-
1
+ //require('bytenode');
2
+ const Ps = require('../../ps');
3
+
4
+ /**
5
+ * loadView 生成BrowserWindow的html content
6
+ */
7
+ const loadView = function (opt = {}) {
8
+ const webSecurity = opt.webSecurity;
9
+ const src = opt.src;
10
+ const title = opt.title;
11
+ const script = opt.script;
12
+
13
+ //const scriptUrl = new URL('eefile://' + src);
14
+ const scriptUrl = 'eefile://' + src;
15
+ console.log('[ee-core:job] scriptUrl: ', scriptUrl);
16
+
17
+ // 脚本内容
18
+ //const scriptBytenode = Ps.isDev() ? '' : `<script> require('bytenode') </script>`;
19
+ const scriptContent = webSecurity ? `<script> ${ script } </script>` : `<script src='${scriptUrl}'></script>`;
20
+
21
+ // html内容
22
+ const htmlContent = (`
23
+ <!DOCTYPE html>
24
+ <html>
25
+ <head>
26
+ <title>${title}</title>
27
+ <meta charset="UTF-8">
28
+ </head>
29
+ <body>
30
+ ${scriptContent}
31
+ </body>
32
+ </html>
33
+ `);
34
+
35
+ const DataURI = 'data:text/html;charset=UTF-8,';
36
+ const data = DataURI + encodeURIComponent(htmlContent);
37
+
38
+ return data;
39
+ };
40
+
41
41
  module.exports = loadView;
@@ -1,64 +1,64 @@
1
- const path = require('path');
2
- const fs = require('fs');
3
- const RendererJob = require('./renderer');
4
- const ChildJob = require('./child/pool');
5
- const Ps = require('../ps');
6
- const Loader = require('../loader');
7
-
8
- class Jobs {
9
- constructor() {
10
- this.type;
11
- this.dev;
12
- this.path;
13
- this.instance;
14
- this.child;
15
- this.childOptions;
16
- this.renderer;
17
- this.winOptions;
18
- }
19
-
20
- /**
21
- * 创建 job
22
- */
23
- create (name, opt = {}) {
24
- this.type = opt.type || 'child';
25
- this.dev = opt.dev || false;
26
- this.winOptions = opt.winOptions || {};
27
- this.childOptions = opt.childOptions || {};
28
- this.path = opt.path || null;
29
-
30
- const isAbsolute = path.isAbsolute(this.path);
31
- if (!isAbsolute) {
32
- this.path = path.join(Ps.getBaseDir(), this.path);
33
- }
34
- const filepath = Loader.resolveModule(this.path);
35
-
36
- if (!fs.existsSync(filepath)) {
37
- throw new Error(`[ee-core] [jobs-create] file ${this.path} not exists`);
38
- }
39
-
40
- this.path = filepath;
41
- if (this.type == 'child') {
42
- this.instance = new ChildJob(name, filepath, this.childOptions);
43
- this.child = this.instance;
44
- } else if (this.type == 'renderer') {
45
- this.instance = new RendererJob(name, filepath, this.winOptions);
46
- this.renderer = this.instance;
47
-
48
- if (this.dev) {
49
- this.openDevTools();
50
- }
51
- }
52
-
53
- return;
54
- }
55
-
56
- /**
57
- * 显示开发者工具栏(仅支持 RendererJob)
58
- */
59
- openDevTools () {
60
- this.instance.openDevTools();
61
- }
62
- }
63
-
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+ const RendererJob = require('./renderer');
4
+ const ChildJob = require('./child/pool');
5
+ const Ps = require('../ps');
6
+ const Loader = require('../loader');
7
+
8
+ class Jobs {
9
+ constructor() {
10
+ this.type;
11
+ this.dev;
12
+ this.path;
13
+ this.instance;
14
+ this.child;
15
+ this.childOptions;
16
+ this.renderer;
17
+ this.winOptions;
18
+ }
19
+
20
+ /**
21
+ * 创建 job
22
+ */
23
+ create (name, opt = {}) {
24
+ this.type = opt.type || 'child';
25
+ this.dev = opt.dev || false;
26
+ this.winOptions = opt.winOptions || {};
27
+ this.childOptions = opt.childOptions || {};
28
+ this.path = opt.path || null;
29
+
30
+ const isAbsolute = path.isAbsolute(this.path);
31
+ if (!isAbsolute) {
32
+ this.path = path.join(Ps.getBaseDir(), this.path);
33
+ }
34
+ const filepath = Loader.resolveModule(this.path);
35
+
36
+ if (!fs.existsSync(filepath)) {
37
+ throw new Error(`[ee-core] [jobs-create] file ${this.path} not exists`);
38
+ }
39
+
40
+ this.path = filepath;
41
+ if (this.type == 'child') {
42
+ this.instance = new ChildJob(name, filepath, this.childOptions);
43
+ this.child = this.instance;
44
+ } else if (this.type == 'renderer') {
45
+ this.instance = new RendererJob(name, filepath, this.winOptions);
46
+ this.renderer = this.instance;
47
+
48
+ if (this.dev) {
49
+ this.openDevTools();
50
+ }
51
+ }
52
+
53
+ return;
54
+ }
55
+
56
+ /**
57
+ * 显示开发者工具栏(仅支持 RendererJob)
58
+ */
59
+ openDevTools () {
60
+ this.instance.openDevTools();
61
+ }
62
+ }
63
+
64
64
  module.exports = Jobs;