ee-core 2.2.0-beta.1 → 2.2.0-beta.3

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.
package/addon/index.js CHANGED
@@ -7,6 +7,10 @@ const Addon = {
7
7
  */
8
8
  all() {
9
9
  const { CoreApp } = EE;
10
+ if (!CoreApp) {
11
+ throw new Error('An unknown error or Addons cannot be used by the jobs!');
12
+ }
13
+
10
14
  const instances = CoreApp.addon || null;
11
15
  if (!instances) {
12
16
  throw new Error('Addons not exists or do not call directly at the top!');
package/ee/application.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const Exception = require('../exception');
2
- const {app} = require('electron');
2
+ const { app } = require('electron');
3
3
  const path = require('path');
4
4
  const debug = require('debug')('ee-core:Appliaction');
5
5
  const EeApp = require('./eeApp');
@@ -53,7 +53,7 @@ class Appliaction extends EeApp {
53
53
  }
54
54
 
55
55
  // normalize env
56
- env.NODE_ENV = options.env;
56
+ //env.NODE_ENV = options.env;
57
57
  env.EE_HOME = options.homeDir;
58
58
  env.EE_BASE_DIR = options.baseDir;
59
59
  env.EE_SERVER_ENV = options.env;
@@ -88,6 +88,8 @@ class Appliaction extends EeApp {
88
88
  await this.ready();
89
89
 
90
90
  await this.createElectronApp();
91
+
92
+ await this.InitModuleMode();
91
93
  }
92
94
  }
93
95
 
package/ee/eeApp.js CHANGED
@@ -28,9 +28,11 @@ class EeApp extends BaseApp {
28
28
  * 生成端口
29
29
  */
30
30
  async createPorts() {
31
- const mainPort = await GetPort({port: this.config.mainServer.port});
32
- process.env.EE_MAIN_PORT = mainPort;
33
- this.config.mainServer.port = mainPort;
31
+ if (Ps.isFrameworkMode()) {
32
+ const mainPort = await GetPort({port: this.config.mainServer.port});
33
+ process.env.EE_MAIN_PORT = mainPort;
34
+ this.config.mainServer.port = mainPort;
35
+ }
34
36
 
35
37
  if (this.config.socketServer.enable) {
36
38
  const socketPort = await GetPort({port: this.config.socketServer.port});
@@ -59,6 +61,7 @@ class EeApp extends BaseApp {
59
61
  * 创建electron应用
60
62
  */
61
63
  async createElectronApp() {
64
+ if (!Ps.isFrameworkMode()) return;
62
65
  const newApp = CoreElectronApp.create();
63
66
  if (!newApp) {
64
67
  return
@@ -172,9 +175,13 @@ class EeApp extends BaseApp {
172
175
  */
173
176
  loadMainUrl(type, url) {
174
177
  const mainServer = this.config.mainServer;
175
- Log.coreLogger.info('[ee-core] [main] Env: %s, Type: %s', this.config.env, type);
176
- Log.coreLogger.info('[ee-core] [main] App running at: %s', url);
177
- this.mainWindow.loadURL(url, mainServer.options);
178
+ Log.coreLogger.info('[ee-core] Env: %s, Type: %s', this.config.env, type);
179
+ Log.coreLogger.info('[ee-core] App running at: %s', url);
180
+ this.mainWindow.loadURL(url, mainServer.options)
181
+ .then()
182
+ .catch((err)=>{
183
+ Log.coreLogger.error(`[ee-core] Please check the ${url} are running OR modify config file !`);
184
+ });
178
185
  }
179
186
 
180
187
  /**
@@ -193,7 +200,7 @@ class EeApp extends BaseApp {
193
200
 
194
201
  // 注册主窗口Contents id
195
202
  const addonsCfg = this.config.addons;
196
- if (addonsCfg.window.enable) {
203
+ if (addonsCfg.window.enable && Ps.isFrameworkMode()) {
197
204
  const win = this.mainWindow;
198
205
  const addonWindow = this.addon.window;
199
206
  addonWindow.registerWCid('main', win.webContents.id);
@@ -214,6 +221,17 @@ class EeApp extends BaseApp {
214
221
  }
215
222
  }
216
223
 
224
+ /**
225
+ * module模式初始化
226
+ */
227
+ async InitModuleMode() {
228
+ if (!Ps.isModuleMode()) return;
229
+
230
+ await this._loderAddons();
231
+
232
+ await this._loderPreload();
233
+ }
234
+
217
235
  /**
218
236
  * electron app已经准备好,主窗口还未创建
219
237
  */
package/index.js CHANGED
@@ -2,6 +2,12 @@
2
2
  * @namespace EeCore
3
3
  */
4
4
 
5
+ /**
6
+ * @member {ElectronEgg} EeCore#Index
7
+ * @since 1.0.0
8
+ */
9
+ const ElectronEgg = require('./main');
10
+
5
11
  /**
6
12
  * @member {app} EeCore#app
7
13
  * @since 1.0.0
@@ -39,6 +45,7 @@ const Utils = require('./old-utils');
39
45
  const Socket = require('./socket');
40
46
 
41
47
  module.exports = {
48
+ ElectronEgg,
42
49
  Application: EE.Application,
43
50
  Controller,
44
51
  Service,
package/main/index.js ADDED
@@ -0,0 +1,49 @@
1
+ const { app } = require('electron');
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+ const Utils = require('../utils');
5
+ const Ps = require('../ps');
6
+ const EE = require('../ee');
7
+ const UtilsCore = require('../core/lib/utils');
8
+ const Loader = require('../loader');
9
+
10
+ class ElectronEgg {
11
+
12
+ constructor(mode) {
13
+ this.mode = mode || 'framework';
14
+ this._create();
15
+ }
16
+
17
+ /**
18
+ * create ElectronEgg app
19
+ */
20
+ _create() {
21
+ if (!Ps.verifyMode(this.mode)) {
22
+ throw new Error(`The mode supports only (framework | module) !`);
23
+ }
24
+ process.env.EE_MODE = this.mode;
25
+
26
+ // module mode
27
+ if (Ps.isModuleMode()) {
28
+ const { Application } = EE;
29
+ new Application();
30
+ return;
31
+ }
32
+
33
+ let baseDir = path.join(app.getAppPath(), 'electron');
34
+ if (Utils.isEncrypt(app.getAppPath())) {
35
+ baseDir = Ps.getEncryptDir(app.getAppPath());
36
+ }
37
+
38
+ let indexFile = path.join(baseDir, 'index');
39
+ indexFile = Loader.resolveModule(indexFile);
40
+ if (!fs.existsSync(indexFile)) {
41
+ throw new Error(`The ${indexFile} file does not exist`);
42
+ }
43
+
44
+ const EEApp = UtilsCore.loadFile(indexFile);
45
+ EE.app = new EEApp(this.env);
46
+ }
47
+ }
48
+
49
+ module.exports = ElectronEgg;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ee-core",
3
- "version": "2.2.0-beta.1",
3
+ "version": "2.2.0-beta.3",
4
4
  "description": "ee core",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/ps/index.js CHANGED
@@ -1,6 +1,37 @@
1
1
  const path = require('path');
2
2
  const eis = require('../utils/is');
3
3
 
4
+ /**
5
+ * 当前模式 - framework | module
6
+ */
7
+ exports.mode = function() {
8
+ return process.env.EE_MODE;
9
+ }
10
+
11
+ /**
12
+ * 校验模式
13
+ */
14
+ exports.verifyMode = function(mode) {
15
+ if (['framework', 'module'].includes(mode)) {
16
+ return true;
17
+ }
18
+ return false;
19
+ }
20
+
21
+ /**
22
+ * 是否为框架模式
23
+ */
24
+ exports.isFrameworkMode = function() {
25
+ return (process.env.EE_MODE === 'framework');
26
+ }
27
+
28
+ /**
29
+ * 是否为模块模式
30
+ */
31
+ exports.isModuleMode = function() {
32
+ return (process.env.EE_MODE === 'module');
33
+ }
34
+
4
35
  /**
5
36
  * 当前进程的所有env
6
37
  */
package/services/index.js CHANGED
@@ -7,6 +7,10 @@ const Services = {
7
7
  */
8
8
  all() {
9
9
  const { CoreApp } = EE;
10
+ if (!CoreApp) {
11
+ throw new Error('An unknown error or Services cannot be used by the jobs!');
12
+ }
13
+
10
14
  const instances = CoreApp.service || null;
11
15
  if (!instances) {
12
16
  throw new Error('Services not exists or do not call directly at the top!');