ee-core 1.5.0 → 1.5.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 (41) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +2 -2
  3. package/addon/window/index.js +91 -91
  4. package/bin/tools.js +17 -17
  5. package/config/config.default.js +280 -276
  6. package/core/index.js +12 -12
  7. package/core/lib/ee.js +218 -218
  8. package/core/lib/loader/context_loader.js +106 -106
  9. package/core/lib/loader/ee_loader.js +457 -457
  10. package/core/lib/loader/file_loader.js +325 -325
  11. package/core/lib/loader/mixin/addon.js +32 -32
  12. package/core/lib/loader/mixin/config.js +135 -135
  13. package/core/lib/loader/mixin/controller.js +124 -124
  14. package/core/lib/loader/mixin/service.js +28 -28
  15. package/core/lib/utils/base_context_class.js +34 -34
  16. package/core/lib/utils/index.js +127 -127
  17. package/core/lib/utils/sequencify.js +59 -59
  18. package/core/lib/utils/timing.js +77 -77
  19. package/index.js +49 -49
  20. package/lib/appLoader.js +53 -53
  21. package/lib/application.js +84 -84
  22. package/lib/baseApp.js +131 -131
  23. package/lib/constant.js +9 -9
  24. package/lib/eeApp.js +359 -335
  25. package/lib/httpclient.js +136 -136
  26. package/lib/logger.js +46 -46
  27. package/lib/socket/httpServer.js +142 -142
  28. package/lib/socket/io.js +23 -23
  29. package/lib/socket/ipcServer.js +108 -108
  30. package/lib/socket/socketClient.js +50 -50
  31. package/lib/socket/socketServer.js +76 -76
  32. package/lib/socket/start.js +22 -22
  33. package/lib/storage/index.js +33 -33
  34. package/lib/storage/lowdbStorage.js +98 -98
  35. package/lib/storage/sqliteStorage.js +127 -127
  36. package/package.json +45 -45
  37. package/tools/encrypt.js +274 -274
  38. package/tools/replaceDist.js +61 -61
  39. package/utils/common.js +90 -90
  40. package/utils/index.js +246 -246
  41. package/utils/wrap.js +37 -37
package/index.js CHANGED
@@ -1,50 +1,50 @@
1
- 'use strict';
2
-
3
- /**
4
- * @namespace EeCore
5
- */
6
-
7
- /**
8
- * @member {Appliaction} EeCore#Appliaction
9
- * @since 1.0.0
10
- */
11
- const Appliaction = require('./lib/application');
12
-
13
- /**
14
- * @member {Controller} EeCore#Controller
15
- * @since 1.0.0
16
- */
17
- const Controller = require('./core/lib/utils/base_context_class');
18
-
19
- /**
20
- * @member {Service} EeCore#Service
21
- * @since 1.0.0
22
- */
23
- const Service = require('./core/lib/utils/base_context_class');
24
-
25
- /**
26
- * @member {Storage}
27
- * @since 1.0.0
28
- */
29
- const Storage = require('./lib/storage/index');
30
-
31
- /**
32
- * @member {Utils}
33
- * @since 1.0.0
34
- */
35
- const Utils = require('./utils/index');
36
-
37
- /**
38
- * @member {Socket}
39
- * @since 1.0.0
40
- */
41
- const Socket = require('./lib/socket/io');
42
-
43
- module.exports = {
44
- Appliaction,
45
- Controller,
46
- Service,
47
- Storage,
48
- Socket,
49
- Utils
1
+ 'use strict';
2
+
3
+ /**
4
+ * @namespace EeCore
5
+ */
6
+
7
+ /**
8
+ * @member {Appliaction} EeCore#Appliaction
9
+ * @since 1.0.0
10
+ */
11
+ const Appliaction = require('./lib/application');
12
+
13
+ /**
14
+ * @member {Controller} EeCore#Controller
15
+ * @since 1.0.0
16
+ */
17
+ const Controller = require('./core/lib/utils/base_context_class');
18
+
19
+ /**
20
+ * @member {Service} EeCore#Service
21
+ * @since 1.0.0
22
+ */
23
+ const Service = require('./core/lib/utils/base_context_class');
24
+
25
+ /**
26
+ * @member {Storage}
27
+ * @since 1.0.0
28
+ */
29
+ const Storage = require('./lib/storage/index');
30
+
31
+ /**
32
+ * @member {Utils}
33
+ * @since 1.0.0
34
+ */
35
+ const Utils = require('./utils/index');
36
+
37
+ /**
38
+ * @member {Socket}
39
+ * @since 1.0.0
40
+ */
41
+ const Socket = require('./lib/socket/io');
42
+
43
+ module.exports = {
44
+ Appliaction,
45
+ Controller,
46
+ Service,
47
+ Storage,
48
+ Socket,
49
+ Utils
50
50
  };
package/lib/appLoader.js CHANGED
@@ -1,53 +1,53 @@
1
- 'use strict';
2
-
3
- const EeLoader = require('../core/index').EeLoader;
4
-
5
- /**
6
- * App Loader
7
- * @see
8
- */
9
- class AppLoader extends EeLoader {
10
-
11
- /**
12
- * loadPlugin first, then loadConfig
13
- * @since 1.0.0
14
- */
15
- loadConfig() {
16
- super.loadConfig();
17
- }
18
-
19
- /**
20
- * Load all directories in convention
21
- * @since 1.0.0
22
- */
23
- load() {
24
-
25
- // app > plugin
26
- this.loadService();
27
-
28
- // app
29
- this.loadController();
30
-
31
- }
32
-
33
- /**
34
- * load addons
35
- * @since 1.0.0
36
- */
37
- loadAddons() {
38
- this.loadAddon();
39
- }
40
-
41
- /**
42
- * load electron modules
43
- * @since 1.0.0
44
- */
45
- loadElectron() {
46
-
47
- // 预加载功能模块
48
- //this.loadPreload();
49
-
50
- }
51
- }
52
-
53
- module.exports = AppLoader;
1
+ 'use strict';
2
+
3
+ const EeLoader = require('../core/index').EeLoader;
4
+
5
+ /**
6
+ * App Loader
7
+ * @see
8
+ */
9
+ class AppLoader extends EeLoader {
10
+
11
+ /**
12
+ * loadPlugin first, then loadConfig
13
+ * @since 1.0.0
14
+ */
15
+ loadConfig() {
16
+ super.loadConfig();
17
+ }
18
+
19
+ /**
20
+ * Load all directories in convention
21
+ * @since 1.0.0
22
+ */
23
+ load() {
24
+
25
+ // app > plugin
26
+ this.loadService();
27
+
28
+ // app
29
+ this.loadController();
30
+
31
+ }
32
+
33
+ /**
34
+ * load addons
35
+ * @since 1.0.0
36
+ */
37
+ loadAddons() {
38
+ this.loadAddon();
39
+ }
40
+
41
+ /**
42
+ * load electron modules
43
+ * @since 1.0.0
44
+ */
45
+ loadElectron() {
46
+
47
+ // 预加载功能模块
48
+ //this.loadPreload();
49
+
50
+ }
51
+ }
52
+
53
+ module.exports = AppLoader;
@@ -1,85 +1,85 @@
1
- const {app} = require('electron');
2
- const path = require('path');
3
- const EeApp = require('./eeApp');
4
- const debug = require('debug')('ee-core:Appliaction');
5
- const fs = require('fs');
6
-
7
- class Appliaction extends EeApp {
8
- constructor() {
9
- const { env } = process;
10
- let options = {
11
- env: 'prod',
12
- serverScope: '',
13
- type: 'application',
14
- baseDir: path.join(app.getAppPath(), 'electron'),
15
- homeDir: app.getAppPath(),
16
- framework: path.join(app.getAppPath(), 'node_modules', 'ee-core'),
17
- appName: app.getName(),
18
- userHome: app.getPath('home'),
19
- appData: app.getPath('appData'),
20
- appUserData: app.getPath('userData'),
21
- //logsDir: app.getPath('logs'),
22
- appVersion: app.getVersion(),
23
- isPackaged: app.isPackaged,
24
- execDir: app.getAppPath()
25
- }
26
-
27
- // argv
28
- let hotReload = false;
29
- for (let i = 0; i < process.argv.length; i++) {
30
- const tmpArgv = process.argv[i]
31
- if (tmpArgv.indexOf('--env=') !== -1) {
32
- options.env = tmpArgv.substring(6);
33
- }
34
- if (tmpArgv.indexOf('--hot-reload=') !== -1) {
35
- hotReload = tmpArgv.substring(13) == 1 ? true : false;
36
- }
37
- }
38
-
39
- // exec directory (exe dmg dep) for prod
40
- if (options.env == 'prod' && app.isPackaged) {
41
- options.execDir = path.dirname(app.getPath('exe'));
42
- }
43
-
44
- // Use encryption, base directory is public/electron
45
- const encryptDir = path.join(app.getAppPath(), 'public', 'electron');
46
- let isEncrypted = fs.existsSync(encryptDir);
47
- if (options.env == 'prod' && isEncrypted) {
48
- options.baseDir = encryptDir;
49
- }
50
-
51
- // normalize env
52
- env.NODE_ENV = 'production';
53
- env.EE_HOME = options.homeDir;
54
- env.EE_SERVER_ENV = options.env;
55
- env.EE_SERVER_SCOPE = options.serverScope;
56
- env.EE_USER_HOME = options.userHome;
57
- env.EE_APP_DATA = options.appData;
58
- env.EE_APP_USER_DATA = options.appUserData;
59
- env.EE_MAIN_PORT = null;
60
- env.EE_SOCKET_PORT = null;
61
- env.EE_HTTP_PORT = null;
62
- env.HOT_RELOAD = hotReload;
63
- env.EE_EXEC_DIR = options.execDir;
64
- env.EE_DATABASE_DIR = null;
65
- debug('options:%j', options)
66
-
67
- super(options);
68
- this.initialize();
69
- }
70
-
71
- async initialize () {
72
-
73
- await this.createPorts();
74
-
75
- await this.startSocket();
76
-
77
- await this.ready();
78
-
79
- await this.createElectronApp();
80
-
81
- await this.catchLog();
82
- }
83
- }
84
-
1
+ const {app} = require('electron');
2
+ const path = require('path');
3
+ const EeApp = require('./eeApp');
4
+ const debug = require('debug')('ee-core:Appliaction');
5
+ const fs = require('fs');
6
+
7
+ class Appliaction extends EeApp {
8
+ constructor() {
9
+ const { env } = process;
10
+ let options = {
11
+ env: 'prod',
12
+ serverScope: '',
13
+ type: 'application',
14
+ baseDir: path.join(app.getAppPath(), 'electron'),
15
+ homeDir: app.getAppPath(),
16
+ framework: path.join(app.getAppPath(), 'node_modules', 'ee-core'),
17
+ appName: app.getName(),
18
+ userHome: app.getPath('home'),
19
+ appData: app.getPath('appData'),
20
+ appUserData: app.getPath('userData'),
21
+ //logsDir: app.getPath('logs'),
22
+ appVersion: app.getVersion(),
23
+ isPackaged: app.isPackaged,
24
+ execDir: app.getAppPath()
25
+ }
26
+
27
+ // argv
28
+ let hotReload = false;
29
+ for (let i = 0; i < process.argv.length; i++) {
30
+ const tmpArgv = process.argv[i]
31
+ if (tmpArgv.indexOf('--env=') !== -1) {
32
+ options.env = tmpArgv.substring(6);
33
+ }
34
+ if (tmpArgv.indexOf('--hot-reload=') !== -1) {
35
+ hotReload = tmpArgv.substring(13) == 1 ? true : false;
36
+ }
37
+ }
38
+
39
+ // exec directory (exe dmg dep) for prod
40
+ if (options.env == 'prod' && app.isPackaged) {
41
+ options.execDir = path.dirname(app.getPath('exe'));
42
+ }
43
+
44
+ // Use encryption, base directory is public/electron
45
+ const encryptDir = path.join(app.getAppPath(), 'public', 'electron');
46
+ let isEncrypted = fs.existsSync(encryptDir);
47
+ if (options.env == 'prod' && isEncrypted) {
48
+ options.baseDir = encryptDir;
49
+ }
50
+
51
+ // normalize env
52
+ env.NODE_ENV = 'production';
53
+ env.EE_HOME = options.homeDir;
54
+ env.EE_SERVER_ENV = options.env;
55
+ env.EE_SERVER_SCOPE = options.serverScope;
56
+ env.EE_USER_HOME = options.userHome;
57
+ env.EE_APP_DATA = options.appData;
58
+ env.EE_APP_USER_DATA = options.appUserData;
59
+ env.EE_MAIN_PORT = null;
60
+ env.EE_SOCKET_PORT = null;
61
+ env.EE_HTTP_PORT = null;
62
+ env.HOT_RELOAD = hotReload;
63
+ env.EE_EXEC_DIR = options.execDir;
64
+ env.EE_DATABASE_DIR = null;
65
+ debug('options:%j', options)
66
+
67
+ super(options);
68
+ this.initialize();
69
+ }
70
+
71
+ async initialize () {
72
+
73
+ await this.createPorts();
74
+
75
+ await this.startSocket();
76
+
77
+ await this.ready();
78
+
79
+ await this.createElectronApp();
80
+
81
+ await this.catchLog();
82
+ }
83
+ }
84
+
85
85
  module.exports = Appliaction;
package/lib/baseApp.js CHANGED
@@ -1,132 +1,132 @@
1
- 'use strict';
2
-
3
- const EeAppCore = require('../core/index').EeCore;
4
- const EE_PATH = Symbol.for('ee#eePath');
5
- const path = require('path');
6
- const EE_LOADER = Symbol.for('ee#loader');
7
- const AppLoader = require('./appLoader');
8
- const LOGGERS = Symbol('EeApplication#loggers');
9
- const ELoggers = require('./logger');
10
- const HttpClient = require('./httpclient');
11
- const HTTPCLIENT = Symbol('EeApplication#httpclient');
12
-
13
- class BaseApp extends EeAppCore {
14
- constructor (options = {}) {
15
-
16
- super(options);
17
-
18
- this.HttpClient = HttpClient;
19
-
20
- this.loader.loadConfig();
21
-
22
- // todo
23
- //this.setDatabaseDir();
24
-
25
- // 缓存配置
26
- this.getCoreDB().setItem('config', this.config);
27
-
28
- this.loader.load();
29
-
30
- // TODO 这个不行,要么每次new对象,要么所有地方都用同一个实例,否则会出现数据无法刷新的情况
31
- //this.coreDB = this.getCoreDB();
32
-
33
- }
34
-
35
- get [EE_PATH]() {
36
- return path.join(__dirname, '..');
37
- }
38
-
39
- get [EE_LOADER]() {
40
- return AppLoader;
41
- }
42
-
43
- /**
44
- * loggers
45
- * @member {Object}
46
- * @since 1.0.0
47
- */
48
- get loggers() {
49
- if (!this[LOGGERS]) {
50
- this[LOGGERS] = ELoggers.getInstance(this.config);
51
- }
52
- return this[LOGGERS];
53
- }
54
-
55
- /**
56
- * Get logger by name, it's equal to app.loggers['name'],
57
- * but you can extend it with your own logical.
58
- * @param {String} name - logger name
59
- * @return {Logger} logger
60
- */
61
- getLogger(name) {
62
- return this.loggers[name] || null;
63
- }
64
-
65
- /**
66
- * application logger, log file is `$HOME/logs/ee.log`
67
- * @member {Logger}
68
- * @since 1.0.0
69
- */
70
- get logger() {
71
- return this.getLogger('logger');
72
- }
73
-
74
- /**
75
- * core logger for framework and plugins, log file is `$HOME/logs/ee-core.log`
76
- * @member {Logger}
77
- * @since 1.0.0
78
- */
79
- get coreLogger() {
80
- return this.getLogger('coreLogger');
81
- }
82
-
83
- /**
84
- * @class core存储模块
85
- * @since 1.0.0
86
- */
87
- getCoreDB () {
88
- const db = require('./storage/index').JsonDB.connection('system');
89
- return db;
90
- }
91
-
92
- /**
93
- * @class curl
94
- * @since 1.0.0
95
- */
96
- curl(url, opts) {
97
- return this.httpclient.request(url, opts);
98
- }
99
-
100
- /**
101
- * HttpClient instance
102
- * @see https://github.com/node-modules/urllib
103
- * @member {HttpClient}
104
- */
105
- get httpclient() {
106
- if (!this[HTTPCLIENT]) {
107
- this[HTTPCLIENT] = new this.HttpClient(this);
108
- }
109
- return this[HTTPCLIENT];
110
- }
111
-
112
- /**
113
- * todo 设置db存储目录
114
- */
115
- setDatabaseDir (dirPath) {
116
- if (dirPath) {
117
- assert(typeof dirPath === 'string', ` ${dirPath} dirPath required, and must be a string`);
118
- process.env.EE_DATABASE_DIR = dirPath;
119
- } else {
120
- process.env.EE_DATABASE_DIR = this.config.database.dir;
121
- }
122
- }
123
-
124
- /**
125
- * core app have been loaded
126
- */
127
- async ready () {
128
- // do some things
129
- }
130
- }
131
-
1
+ 'use strict';
2
+
3
+ const EeAppCore = require('../core/index').EeCore;
4
+ const EE_PATH = Symbol.for('ee#eePath');
5
+ const path = require('path');
6
+ const EE_LOADER = Symbol.for('ee#loader');
7
+ const AppLoader = require('./appLoader');
8
+ const LOGGERS = Symbol('EeApplication#loggers');
9
+ const ELoggers = require('./logger');
10
+ const HttpClient = require('./httpclient');
11
+ const HTTPCLIENT = Symbol('EeApplication#httpclient');
12
+
13
+ class BaseApp extends EeAppCore {
14
+ constructor (options = {}) {
15
+
16
+ super(options);
17
+
18
+ this.HttpClient = HttpClient;
19
+
20
+ this.loader.loadConfig();
21
+
22
+ // todo
23
+ //this.setDatabaseDir();
24
+
25
+ // 缓存配置
26
+ this.getCoreDB().setItem('config', this.config);
27
+
28
+ this.loader.load();
29
+
30
+ // TODO 这个不行,要么每次new对象,要么所有地方都用同一个实例,否则会出现数据无法刷新的情况
31
+ //this.coreDB = this.getCoreDB();
32
+
33
+ }
34
+
35
+ get [EE_PATH]() {
36
+ return path.join(__dirname, '..');
37
+ }
38
+
39
+ get [EE_LOADER]() {
40
+ return AppLoader;
41
+ }
42
+
43
+ /**
44
+ * loggers
45
+ * @member {Object}
46
+ * @since 1.0.0
47
+ */
48
+ get loggers() {
49
+ if (!this[LOGGERS]) {
50
+ this[LOGGERS] = ELoggers.getInstance(this.config);
51
+ }
52
+ return this[LOGGERS];
53
+ }
54
+
55
+ /**
56
+ * Get logger by name, it's equal to app.loggers['name'],
57
+ * but you can extend it with your own logical.
58
+ * @param {String} name - logger name
59
+ * @return {Logger} logger
60
+ */
61
+ getLogger(name) {
62
+ return this.loggers[name] || null;
63
+ }
64
+
65
+ /**
66
+ * application logger, log file is `$HOME/logs/ee.log`
67
+ * @member {Logger}
68
+ * @since 1.0.0
69
+ */
70
+ get logger() {
71
+ return this.getLogger('logger');
72
+ }
73
+
74
+ /**
75
+ * core logger for framework and plugins, log file is `$HOME/logs/ee-core.log`
76
+ * @member {Logger}
77
+ * @since 1.0.0
78
+ */
79
+ get coreLogger() {
80
+ return this.getLogger('coreLogger');
81
+ }
82
+
83
+ /**
84
+ * @class core存储模块
85
+ * @since 1.0.0
86
+ */
87
+ getCoreDB () {
88
+ const db = require('./storage/index').JsonDB.connection('system');
89
+ return db;
90
+ }
91
+
92
+ /**
93
+ * @class curl
94
+ * @since 1.0.0
95
+ */
96
+ curl(url, opts) {
97
+ return this.httpclient.request(url, opts);
98
+ }
99
+
100
+ /**
101
+ * HttpClient instance
102
+ * @see https://github.com/node-modules/urllib
103
+ * @member {HttpClient}
104
+ */
105
+ get httpclient() {
106
+ if (!this[HTTPCLIENT]) {
107
+ this[HTTPCLIENT] = new this.HttpClient(this);
108
+ }
109
+ return this[HTTPCLIENT];
110
+ }
111
+
112
+ /**
113
+ * todo 设置db存储目录
114
+ */
115
+ setDatabaseDir (dirPath) {
116
+ if (dirPath) {
117
+ assert(typeof dirPath === 'string', ` ${dirPath} dirPath required, and must be a string`);
118
+ process.env.EE_DATABASE_DIR = dirPath;
119
+ } else {
120
+ process.env.EE_DATABASE_DIR = this.config.database.dir;
121
+ }
122
+ }
123
+
124
+ /**
125
+ * core app have been loaded
126
+ */
127
+ async ready () {
128
+ // do some things
129
+ }
130
+ }
131
+
132
132
  module.exports = BaseApp;
package/lib/constant.js CHANGED
@@ -1,10 +1,10 @@
1
- module.exports = {
2
- storageKey: {
3
- cache: 'cache',
4
- },
5
- socketIo: {
6
- channel: {
7
- partySoftware: 'c1',
8
- }
9
- }
1
+ module.exports = {
2
+ storageKey: {
3
+ cache: 'cache',
4
+ },
5
+ socketIo: {
6
+ channel: {
7
+ partySoftware: 'c1',
8
+ }
9
+ }
10
10
  };