ee-core 2.11.1 → 4.0.0-beta.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 (96) hide show
  1. package/app/application.js +31 -0
  2. package/app/boot.js +81 -0
  3. package/app/dir.js +27 -0
  4. package/app/events.js +56 -0
  5. package/app/index.js +7 -0
  6. package/config/config_loader.js +66 -0
  7. package/config/default_config.js +110 -0
  8. package/config/index.js +21 -83
  9. package/const/channel.js +26 -16
  10. package/const/index.js +0 -4
  11. package/controller/controller_loader.js +78 -0
  12. package/controller/index.js +18 -19
  13. package/core/index.js +6 -5
  14. package/core/{lib/loader → loader}/file_loader.js +39 -156
  15. package/core/utils/index.js +83 -0
  16. package/core/{lib/utils → utils}/timing.js +3 -2
  17. package/cross/cross.js +152 -0
  18. package/cross/index.js +6 -181
  19. package/cross/spawnProcess.js +34 -51
  20. package/electron/app/index.js +38 -54
  21. package/electron/index.js +13 -17
  22. package/electron/window/index.js +260 -65
  23. package/exception/index.js +34 -32
  24. package/html/index.js +7 -10
  25. package/index.js +4 -52
  26. package/jobs/child/app.js +9 -9
  27. package/jobs/child/forkProcess.js +29 -45
  28. package/jobs/child/index.js +13 -10
  29. package/jobs/child-pool/index.js +13 -11
  30. package/jobs/index.js +2 -4
  31. package/loader/index.js +91 -144
  32. package/log/index.js +74 -57
  33. package/log/logger.js +76 -84
  34. package/message/childMessage.js +12 -13
  35. package/message/index.js +7 -16
  36. package/package.json +2 -2
  37. package/ps/index.js +137 -223
  38. package/socket/httpServer.js +46 -43
  39. package/socket/index.js +52 -69
  40. package/socket/ipcServer.js +80 -94
  41. package/socket/socketServer.js +31 -24
  42. package/storage/index.js +5 -37
  43. package/storage/sqliteStorage.js +18 -18
  44. package/utils/extend.js +10 -5
  45. package/utils/helper.js +38 -42
  46. package/utils/index.js +40 -23
  47. package/utils/ip.js +5 -45
  48. package/utils/is.js +107 -141
  49. package/utils/json.js +15 -7
  50. package/utils/pargv.js +5 -1
  51. package/utils/{get-port → port}/index.js +4 -26
  52. package/utils/wrap.js +8 -3
  53. package/addon/index.js +0 -35
  54. package/addon/window/index.js +0 -99
  55. package/bin/tools.js +0 -8
  56. package/config/cache.js +0 -42
  57. package/config/config.default.js +0 -331
  58. package/controller/baseContextClass.js +0 -25
  59. package/core/lib/ee.js +0 -216
  60. package/core/lib/loader/context_loader.js +0 -106
  61. package/core/lib/loader/ee_loader.js +0 -435
  62. package/core/lib/loader/mixin/addon.js +0 -32
  63. package/core/lib/loader/mixin/config.js +0 -130
  64. package/core/lib/loader/mixin/controller.js +0 -125
  65. package/core/lib/loader/mixin/service.js +0 -28
  66. package/core/lib/utils/base_context_class.js +0 -34
  67. package/core/lib/utils/function.js +0 -30
  68. package/core/lib/utils/index.js +0 -133
  69. package/core/lib/utils/sequencify.js +0 -59
  70. package/ee/appLoader.js +0 -48
  71. package/ee/application.js +0 -100
  72. package/ee/baseApp.js +0 -104
  73. package/ee/eeApp.js +0 -409
  74. package/ee/index.js +0 -58
  75. package/electron/window/winState.js +0 -186
  76. package/httpclient/index.js +0 -161
  77. package/jobs/baseJobClass.js +0 -16
  78. package/jobs/renderer/index.js +0 -141
  79. package/jobs/renderer/loadView.js +0 -41
  80. package/jobs/unification.js +0 -64
  81. package/main/index.js +0 -57
  82. package/old-utils/index.js +0 -91
  83. package/services/baseContextClass.js +0 -24
  84. package/services/index.js +0 -41
  85. package/socket/io.js +0 -28
  86. package/storage/jsondb/adapters/Base.js +0 -23
  87. package/storage/jsondb/adapters/FileSync.js +0 -64
  88. package/storage/jsondb/main.js +0 -55
  89. package/storage/jsondbStorage.js +0 -196
  90. package/utils/co.js +0 -237
  91. package/utils/copyto.js +0 -161
  92. package/utils/depd/index.js +0 -538
  93. package/utils/depd/lib/browser/index.js +0 -77
  94. package/utils/get-port/index.d.ts +0 -64
  95. package/utils/time/index.js +0 -20
  96. package/utils/time/ms.js +0 -162
@@ -1,29 +1,29 @@
1
1
  const path = require('path');
2
2
  const EventEmitter = require('events');
3
- const { fork } = require('child_process');
4
3
  const serialize = require('serialize-javascript');
5
- const Log = require('../../log');
6
- const Ps = require('../../ps');
7
- const Channel = require('../../const/channel');
8
- const Helper = require('../../utils/helper');
9
- const Loader = require('../../loader');
4
+ const { fork } = require('child_process');
5
+ const { coreLogger } = require('../../log');
6
+ const { getBaseDir, isPackaged, allEnv } = require('../../ps');
7
+ const { Processes, Events, Receiver } = require('../../const/channel');
8
+ const { getRandomString } = require('../../utils/helper');
9
+ const { getFullpath } = require('../../loader');
10
+ const { extend } = require('../../utils/extend');
10
11
 
11
12
  class ForkProcess {
12
13
  constructor(host, opt = {}) {
13
14
 
14
- let cwd = Ps.getHomeDir();
15
- let appPath = path.join(__dirname, 'app.js');
16
- if (Ps.isPackaged()) {
15
+ const cwd = getBaseDir();
16
+ const appPath = path.join(__dirname, 'app.js');
17
+ if (isPackaged()) {
17
18
  // todo fork的cwd目录为什么要在app.asar外 ?
18
- cwd = path.join(Ps.getHomeDir(), '..');
19
+ cwd = path.join(getBaseDir(), '..');
19
20
  }
20
21
 
21
- // TODO Object.assign 只能单层对象结构,多层的对象会直接覆盖
22
- let options = Object.assign({
22
+ const options = extend(true, {
23
23
  processArgs: {},
24
24
  processOptions: {
25
25
  cwd: cwd,
26
- env: Ps.allEnv(),
26
+ env: allEnv(),
27
27
  stdio: 'ignore' // pipe
28
28
  }
29
29
  }, opt);
@@ -48,15 +48,15 @@ class ForkProcess {
48
48
  const { messageLog } = this.host.config;
49
49
  this.child.on('message', (m) => {
50
50
  if (messageLog == true) {
51
- Log.coreLogger.info(`[ee-core] [jobs/child] received a message from child-process, message: ${serialize(m)}`);
51
+ coreLogger.info(`[ee-core] [jobs/child] received a message from child-process, message: ${serialize(m)}`);
52
52
  }
53
53
 
54
- if (m.channel == Channel.process.showException) {
55
- Log.coreLogger.error(`${m.data}`);
54
+ if (m.channel == Processes.showException) {
55
+ coreLogger.error(`${m.data}`);
56
56
  }
57
57
 
58
58
  // 收到子进程消息,转发到 event
59
- if (m.channel == Channel.process.sendToMain) {
59
+ if (m.channel == Processes.sendToMain) {
60
60
  this._eventEmit(m);
61
61
  }
62
62
  });
@@ -65,16 +65,16 @@ class ForkProcess {
65
65
  let data = {
66
66
  pid: this.pid
67
67
  }
68
- this.host.emit(Channel.events.childProcessExit, data);
69
- Log.coreLogger.info(`[ee-core] [jobs/child] received a exit from child-process, code:${code}, signal:${signal}, pid:${this.pid}`);
68
+ this.host.emit(Events.childProcessExit, data);
69
+ coreLogger.info(`[ee-core] [jobs/child] received a exit from child-process, code:${code}, signal:${signal}, pid:${this.pid}`);
70
70
  });
71
71
 
72
72
  this.child.on('error', (err) => {
73
73
  let data = {
74
74
  pid: this.pid
75
75
  }
76
- this.host.emit(Channel.events.childProcessError, data);
77
- Log.coreLogger.error(`[ee-core] [jobs/child] received a error from child-process, error: ${err}, pid:${this.pid}`);
76
+ this.host.emit(Events.childProcessError, data);
77
+ coreLogger.error(`[ee-core] [jobs/child] received a error from child-process, error: ${err}, pid:${this.pid}`);
78
78
  });
79
79
  }
80
80
 
@@ -83,10 +83,10 @@ class ForkProcess {
83
83
  */
84
84
  _eventEmit(m) {
85
85
  switch (m.eventReceiver) {
86
- case Channel.receiver.forkProcess:
86
+ case Receiver.forkProcess:
87
87
  this.emitter.emit(m.event, m.data);
88
88
  break;
89
- case Channel.receiver.childJob:
89
+ case Receiver.childJob:
90
90
  this.host.emit(m.event, m.data);
91
91
  break;
92
92
  default:
@@ -101,7 +101,7 @@ class ForkProcess {
101
101
  */
102
102
  dispatch(cmd, jobPath = '', ...params) {
103
103
  // 消息对象
104
- const mid = Helper.getRandomString();
104
+ const mid = getRandomString();
105
105
  let msg = {
106
106
  mid,
107
107
  cmd,
@@ -118,10 +118,10 @@ class ForkProcess {
118
118
  * 调用job的方法
119
119
  */
120
120
  callFunc(jobPath = '', funcName = '', ...params) {
121
- jobPath = Loader.getFullpath(jobPath);
121
+ jobPath = getFullpath(jobPath);
122
122
 
123
123
  // 消息对象
124
- const mid = Helper.getRandomString();
124
+ const mid = getRandomString();
125
125
  let msg = {
126
126
  mid,
127
127
  cmd:'run',
@@ -142,24 +142,8 @@ class ForkProcess {
142
142
  this.child.kill('SIGKILL');
143
143
  }, timeout)
144
144
  }
145
-
146
- /**
147
- * sleep (仅Unix平台)
148
- */
149
- sleep() {
150
- if (this.sleeping) return;
151
- process.kill(this.pid, 'SIGSTOP');
152
- this.sleeping = true;
153
- }
154
-
155
- /**
156
- * wakeup (仅Unix平台)
157
- */
158
- wakeup() {
159
- if (!this.sleeping) return;
160
- process.kill(this.pid, 'SIGCONT');
161
- this.sleeping = false;
162
- }
163
145
  }
164
146
 
165
- module.exports = ForkProcess;
147
+ module.exports = {
148
+ ForkProcess
149
+ };
@@ -1,8 +1,9 @@
1
1
  const EventEmitter = require('events');
2
- const ForkProcess = require('./forkProcess');
3
- const Loader = require('../../loader');
4
- const Channel = require('../../const/channel');
5
- const Conf = require('../../config/cache');
2
+ const { ForkProcess } = require('./forkProcess');
3
+ const { getFullpath } = require('../../loader');
4
+ const { Events } = require('../../const/channel');
5
+ const { getConfig } = require('../../config');
6
+ const { extend } = require('../../utils/extend');
6
7
 
7
8
  class ChildJob extends EventEmitter {
8
9
 
@@ -11,7 +12,7 @@ class ChildJob extends EventEmitter {
11
12
  this.jobs = {};
12
13
  this.config = {};
13
14
 
14
- const cfg = Conf.getValue('jobs');
15
+ const cfg = getConfig().jobs;
15
16
  if (cfg) {
16
17
  this.config = cfg;
17
18
  }
@@ -23,10 +24,10 @@ class ChildJob extends EventEmitter {
23
24
  * 初始化监听
24
25
  */
25
26
  _initEvents() {
26
- this.on(Channel.events.childProcessExit, (data) => {
27
+ this.on(Events.childProcessExit, (data) => {
27
28
  delete this.jobs[data.pid];
28
29
  });
29
- this.on(Channel.events.childProcessError, (data) => {
30
+ this.on(Events.childProcessError, (data) => {
30
31
  delete this.jobs[data.pid];
31
32
  });
32
33
  }
@@ -35,7 +36,7 @@ class ChildJob extends EventEmitter {
35
36
  * 执行一个job文件
36
37
  */
37
38
  exec(filepath, params = {}, opt = {}) {
38
- const jobPath = Loader.getFullpath(filepath);
39
+ const jobPath = getFullpath(filepath);
39
40
  const proc = this.createProcess(opt);
40
41
  const cmd = 'run';
41
42
  proc.dispatch(cmd, jobPath, params);
@@ -47,7 +48,7 @@ class ChildJob extends EventEmitter {
47
48
  * 创建子进程
48
49
  */
49
50
  createProcess(opt = {}) {
50
- let options = Object.assign({
51
+ const options = extend(true, {
51
52
  processArgs: {
52
53
  type: 'childJob'
53
54
  }
@@ -79,4 +80,6 @@ class ChildJob extends EventEmitter {
79
80
 
80
81
  }
81
82
 
82
- module.exports = ChildJob;
83
+ module.exports = {
84
+ ChildJob
85
+ };
@@ -1,10 +1,10 @@
1
1
  const EventEmitter = require('events');
2
2
  const LoadBalancer = require('../load-balancer');
3
- const Loader = require('../../loader');
4
- const ForkProcess = require('../child/forkProcess');
5
- const Channel = require('../../const/channel');
6
- const Helper = require('../../utils/helper');
7
- const Conf = require('../../config/cache');
3
+ const { getFullpath } = require('../../loader');
4
+ const { ForkProcess } = require('../child/forkProcess');
5
+ const { Events } = require('../../const/channel');
6
+ const { validValue } = require('../../utils/helper');
7
+ const { getConfig } = require('../../config');
8
8
 
9
9
  class ChildPoolJob extends EventEmitter {
10
10
 
@@ -21,7 +21,7 @@ class ChildPoolJob extends EventEmitter {
21
21
  this.max = 6;
22
22
  this.strategy = 'polling';
23
23
  this.weights = new Array(this.max).fill().map((v, i) => {
24
- let w = Helper.validValue(options.weights[i]) ? options.weights[i] : 1
24
+ let w = validValue(options.weights[i]) ? options.weights[i] : 1
25
25
  return w;
26
26
  });
27
27
 
@@ -31,7 +31,7 @@ class ChildPoolJob extends EventEmitter {
31
31
  }
32
32
  this.LB = new LoadBalancer(lbOpt);
33
33
 
34
- const cfg = Conf.getValue('jobs');
34
+ const cfg = getConfig().jobs;
35
35
  if (cfg) {
36
36
  this.config = cfg;
37
37
  }
@@ -43,10 +43,10 @@ class ChildPoolJob extends EventEmitter {
43
43
  * 初始化监听
44
44
  */
45
45
  _initEvents() {
46
- this.on(Channel.events.childProcessExit, (data) => {
46
+ this.on(Events.childProcessExit, (data) => {
47
47
  this._removeChild(data.pid);
48
48
  });
49
- this.on(Channel.events.childProcessError, (data) => {
49
+ this.on(Events.childProcessError, (data) => {
50
50
  this._removeChild(data.pid);
51
51
  });
52
52
  }
@@ -115,7 +115,7 @@ class ChildPoolJob extends EventEmitter {
115
115
  * 执行一个job文件
116
116
  */
117
117
  run(filepath, params = {}) {
118
- const jobPath = Loader.getFullpath(filepath);
118
+ const jobPath = getFullpath(filepath);
119
119
  const childProcess = this.getChild();
120
120
  childProcess.dispatch('run', jobPath, params);
121
121
 
@@ -210,4 +210,6 @@ class ChildPoolJob extends EventEmitter {
210
210
  }
211
211
  }
212
212
 
213
- module.exports = ChildPoolJob;
213
+ module.exports = {
214
+ ChildPoolJob
215
+ };
package/jobs/index.js CHANGED
@@ -1,9 +1,7 @@
1
- const ChildJob = require('./child');
2
- const RendererJob = require('./renderer');
3
- const ChildPoolJob = require('./child-pool');
1
+ const { ChildJob } = require('./child');
2
+ const { ChildPoolJob } = require('./child-pool');
4
3
 
5
4
  module.exports = {
6
5
  ChildJob,
7
- RendererJob,
8
6
  ChildPoolJob
9
7
  };
package/loader/index.js CHANGED
@@ -1,163 +1,110 @@
1
1
  const is = require('is-type-of');
2
2
  const fs = require('fs');
3
3
  const path = require('path');
4
- const UtilsCore = require('../core/lib/utils');
5
- const Ps = require('../ps');
6
- const Log = require('../log');
7
-
8
- module.exports = {
4
+ const CoreUtils = require('../core/utils');
5
+ const { getElectronDir } = require('../ps');
6
+
7
+ /**
8
+ * 加载单个文件(如果是函数,将被执行)
9
+ *
10
+ * @param {String} filepath - fullpath
11
+ * @param {Array} inject - pass rest arguments into the function when invoke
12
+ * @return {Object} exports
13
+ */
14
+ function loadFile(filepath, ...inject) {
15
+ const isAbsolute = path.isAbsolute(filepath);
16
+ if (!isAbsolute) {
17
+ filepath = path.join(getElectronDir(), filepath);
18
+ }
9
19
 
10
- /**
11
- * 加载单个文件(如果是函数,将被执行)
12
- *
13
- * @param {String} filepath - fullpath
14
- * @param {Array} inject - pass rest arguments into the function when invoke
15
- * @return {Object} exports
16
- * @since 1.0.0
17
- */
18
- loadOneFile (filepath, ...inject) {
19
- const isAbsolute = path.isAbsolute(filepath);
20
- if (!isAbsolute) {
21
- filepath = path.join(Ps.getBaseDir(), filepath);
22
- }
20
+ filepath = filepath && resolveModule(filepath);
21
+ if (!fs.existsSync(filepath)) {
22
+ let errorMsg = `[ee-core] [loader/index] loadFile ${filepath} does not exist`;
23
+ throw new Error(errorMsg);
24
+ }
23
25
 
24
- filepath = filepath && this.resolveModule(filepath);
25
- if (!fs.existsSync(filepath)) {
26
- let errorMsg = `[ee-core] [loader/index] loadOneFile ${filepath} does not exist`;
27
- throw new Error(errorMsg);
28
- }
26
+ let ret = CoreUtils.loadFile(filepath);
27
+ if (is.function(ret) && !is.class(ret) && !CoreUtils.isBytecodeClass(ret)) {
28
+ ret = ret(...inject);
29
+ }
30
+ return ret;
31
+ }
29
32
 
30
- const ret = UtilsCore.loadFile(filepath);
31
- if (is.function(ret) && !is.class(ret) && !UtilsCore.isBytecodeClass(ret)) {
32
- ret = ret(...inject);
33
- }
34
- return ret;
35
- },
36
-
37
- /**
38
- * 加载js文件
39
- *
40
- * @param {String} filepath - fullpath
41
- * @return {Any} exports
42
- * @since 1.0.0
43
- */
44
- loadJsFile (filepath) {
45
- if (!fs.existsSync(filepath)) {
46
- let errMsg = `[ee-core] [loader] loadJobFile ${filepath} does not exist`;
47
- throw new Error(errMsg);
48
- }
33
+ // requireFile
34
+ function requireFile(filepath) {
35
+ return CoreUtils.loadFile(filepath);
36
+ }
49
37
 
50
- const ret = UtilsCore.loadFile(filepath);
51
- return ret;
52
- },
53
-
54
- /**
55
- * 加载并运行js文件
56
- *
57
- * @param {String} filepath - fullpath
58
- * @param {Array} inject - pass rest arguments into the function when invoke
59
- * @return {Any}
60
- * @since 1.0.0
61
- */
62
- execJsFile (filepath, ...inject) {
63
- if (!fs.existsSync(filepath)) {
64
- let errMsg = `[ee-core] [loader] loadJobFile ${filepath} does not exist`;
65
- throw new Error(errMsg);
66
- }
38
+ /**
39
+ * 加载并运行文件
40
+ *
41
+ * @param {String} filepath - fullpath
42
+ * @param {Array} inject - pass rest arguments into the function when invoke
43
+ * @return {Any}
44
+ */
45
+ function execFile(filepath, ...inject) {
46
+ let ret = CoreUtils.loadFile(filepath);
47
+ if (is.class(ret) || CoreUtils.isBytecodeClass(ret)) {
48
+ ret = new ret(inject);
49
+ } else if (is.function(ret)) {
50
+ ret = ret(inject);
51
+ }
67
52
 
68
- let ret = UtilsCore.loadFile(filepath);
69
- if (is.class(ret) || UtilsCore.isBytecodeClass(ret)) {
70
- ret = new ret(inject);
71
- } else if (is.function(ret)) {
72
- ret = ret(inject);
73
- }
53
+ return ret;
54
+ }
74
55
 
75
- return ret;
76
- },
77
-
78
- /**
79
- * 模块的绝对路径
80
- * @param {String} filepath - fullpath
81
- */
82
- resolveModule(filepath) {
83
- let fullpath;
84
- try {
85
- fullpath = require.resolve(filepath);
86
- } catch (e) {
87
-
88
- // 特殊后缀处理
89
- if (filepath && (filepath.endsWith('.defalut') || filepath.endsWith('.prod'))) {
90
- fullpath = filepath + '.jsc';
91
- } else if (filepath && filepath.endsWith('.js')) {
92
- fullpath = filepath + 'c';
93
- }
94
-
95
- if (!fs.existsSync(filepath) && !fs.existsSync(fullpath)) {
96
- let files = { filepath, fullpath }
97
- console.warn(`[ee-core] [loader] resolveModule unknow filepath: ${files}`)
98
- return undefined;
99
- }
56
+ /**
57
+ * 模块的绝对路径
58
+ * @param {String} filepath - fullpath
59
+ */
60
+ function resolveModule(filepath) {
61
+ let fullpath;
62
+ try {
63
+ fullpath = require.resolve(filepath);
64
+ } catch (e) {
65
+
66
+ // 特殊后缀处理
67
+ if (filepath && (filepath.endsWith('.defalut') || filepath.endsWith('.prod'))) {
68
+ fullpath = filepath + '.jsc';
69
+ } else if (filepath && filepath.endsWith('.js')) {
70
+ fullpath = filepath + 'c';
100
71
  }
101
72
 
102
- return fullpath;
103
- },
104
-
105
- /**
106
- * 加载模块(子进程中使用)
107
- *
108
- * @param {String} filepath - fullpath
109
- * @return {Object} exports
110
- * @since 1.0.0
111
- */
112
- requireModule (filepath, type = '') {
113
- let fullpath;
114
- const isAbsolute = path.isAbsolute(filepath);
115
- if (!isAbsolute) {
116
- filepath = path.join(Ps.getBaseDir(), type, filepath);
73
+ if (!fs.existsSync(filepath) && !fs.existsSync(fullpath)) {
74
+ let files = { filepath, fullpath }
75
+ console.warn(`[ee-core] [loader] resolveModule unknow filepath: ${files}`)
76
+ return undefined;
117
77
  }
78
+ }
118
79
 
119
- fullpath = this.resolveModule(filepath);
120
- if (!fs.existsSync(fullpath)) {
121
- let errorMsg = `[ee-core] [loader] requireModule filepath: ${filepath} does not exist`;
122
- throw new Error(errorMsg);
123
- }
124
- const ret = UtilsCore.loadFile(fullpath);
125
-
126
- return ret;
127
- },
128
-
129
- /**
130
- * 加载jobs模块(子进程中使用)
131
- *
132
- * @param {String} filepath - fullpath
133
- * @return {Object} exports
134
- * @since 1.0.0
135
- */
136
- requireJobsModule (filepath) {
137
- const ret = this.requireModule(filepath, 'jobs');
138
-
139
- return ret;
140
- },
141
-
142
- /**
143
- * 获取electron目录下文件的绝对路径
144
- * @param {String} filepath - fullpath
145
- */
146
- getFullpath(filepath) {
147
- let fullpath;
148
- const isAbsolute = path.isAbsolute(filepath);
149
- if (!isAbsolute) {
150
- filepath = path.join(Ps.getBaseDir(), filepath);
151
- }
80
+ return fullpath;
81
+ }
152
82
 
153
- fullpath = this.resolveModule(filepath);
154
- if (!fs.existsSync(fullpath)) {
155
- throw new Error(`[ee-core] [loader] getFullpath filepath ${fullpath} not exists`);
156
- }
83
+ /**
84
+ * 获取electron目录下文件的绝对路径
85
+ * @param {String} filepath - fullpath
86
+ */
87
+ function getFullpath(filepath) {
88
+ let fullpath;
89
+ const isAbsolute = path.isAbsolute(filepath);
90
+ if (!isAbsolute) {
91
+ filepath = path.join(getElectronDir(), filepath);
92
+ }
157
93
 
158
- return fullpath;
94
+ fullpath = resolveModule(filepath);
95
+ if (!fs.existsSync(fullpath)) {
96
+ throw new Error(`[ee-core] [loader] getFullpath filepath ${filepath} not exists`);
159
97
  }
160
-
98
+
99
+ return fullpath;
100
+ }
101
+
102
+ module.exports = {
103
+ loadFile,
104
+ execFile,
105
+ requireFile,
106
+ resolveModule,
107
+ getFullpath,
161
108
  }
162
109
 
163
110
 
package/log/index.js CHANGED
@@ -1,69 +1,86 @@
1
- const dayjs = require('dayjs');
2
- const Logger = require('./logger');
3
- const EELoggers = Symbol('EeApplication#EELoggers');
4
- let LogDate = 0;
1
+ 'use strict';
5
2
 
6
- const Log = {
7
- /**
8
- * 创建日志实例
9
- */
10
- create(config) {
11
- this._delCache();
12
- const eeLog = Logger.create(config);
3
+ const dayjs = require('dayjs');
4
+ const { create } = require('./logger');
13
5
 
14
- return eeLog;
15
- },
6
+ const Instance = {
7
+ eelog: null,
8
+ logger: {},
9
+ coreLogger: {},
10
+ };
11
+ let logDate = 0;
12
+ const logProperties = ['error', 'warn', 'info', 'debug'];
16
13
 
17
- /**
18
- * delete cache
19
- */
20
- _delCache() {
21
- let now = parseInt(dayjs().format('YYYYMMDD'));
22
- if (LogDate != now) {
23
- LogDate = now;
24
- this[EELoggers] = null;
25
- }
26
- },
14
+ // define logger/coreLogger properties
15
+ defineLoggerProperty();
16
+ defineCoreLoggerProperty();
27
17
 
28
- /**
29
- * logger
30
- */
31
- get logger() {
32
- this._delCache();
33
- if (!this[EELoggers]) {
34
- this[EELoggers] = Logger.create();
35
- }
18
+ // Create a log instance
19
+ function createLog(config) {
20
+ _delCache();
21
+ const eeLog = create(config);
36
22
 
37
- return this[EELoggers]['logger'] || null;
38
- },
23
+ return eeLog;
24
+ }
39
25
 
40
- /**
41
- * coreLogger
42
- */
43
- get coreLogger () {
44
- this._delCache();
45
- if (!this[EELoggers]) {
46
- this[EELoggers] = Logger.create();
47
- }
26
+ function loadLog() {
27
+ Instance.eelog = createLog();
28
+ return Instance.eelog;
29
+ }
48
30
 
49
- return this[EELoggers]['coreLogger'] || null;
50
- },
31
+ function defineLoggerProperty() {
32
+ for (const property of logProperties) {
33
+ Object.defineProperty(Instance.logger, property, {
34
+ get() {
35
+ //console.log('emit logger property: ', property);
36
+ let log = getLogger();
37
+ let val = log[property].bind(log);
38
+ return val;
39
+ },
40
+ });
41
+ }
42
+ }
51
43
 
52
- get error() {
53
- return this.logger.error.bind(this.logger);
54
- },
44
+ function defineCoreLoggerProperty() {
45
+ for (const property of logProperties) {
46
+ Object.defineProperty(Instance.coreLogger, property, {
47
+ get() {
48
+ let log = getCoreLogger();
49
+ let val = log[property].bind(log);
50
+ return val;
51
+ },
52
+ });
53
+ }
54
+ }
55
55
 
56
- get warn() {
57
- return this.logger.warn.bind(this.logger);
58
- },
56
+ function _delCache() {
57
+ const now = parseInt(dayjs().format('YYYYMMDD'));
58
+ if (logDate != now) {
59
+ logDate = now;
60
+ Instance.eelog = null;
61
+ }
62
+ }
59
63
 
60
- get info() {
61
- return this.logger.info.bind(this.logger);
62
- },
64
+ function getLogger() {
65
+ _delCache();
66
+ if (!Instance.eelog) {
67
+ loadLog();
68
+ }
69
+
70
+ return Instance.eelog["logger"];
71
+ }
63
72
 
64
- get debug() {
65
- return this.logger.debug.bind(this.logger);
66
- },
67
- };
73
+ function getCoreLogger() {
74
+ _delCache();
75
+ if (!Instance.eelog) {
76
+ loadLog();
77
+ }
78
+ return Instance.eelog["coreLogger"];
79
+ }
68
80
 
69
- module.exports = Log;
81
+ module.exports = {
82
+ createLog,
83
+ loadLog,
84
+ logger: Instance.logger,
85
+ coreLogger: Instance.coreLogger
86
+ };