ee-core 1.5.2-beta.1 → 2.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 (72) 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 +18 -18
  5. package/config/config.default.js +287 -280
  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 +461 -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 +125 -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/function.js +30 -0
  17. package/core/lib/utils/index.js +127 -127
  18. package/core/lib/utils/sequencify.js +59 -59
  19. package/core/lib/utils/timing.js +77 -77
  20. package/index.js +49 -49
  21. package/lib/appLoader.js +48 -53
  22. package/lib/application.js +85 -84
  23. package/lib/baseApp.js +114 -131
  24. package/lib/eeApp.js +325 -359
  25. package/{lib/constant.js → module/const/index.js} +12 -9
  26. package/{lib/httpclient.js → module/httpclient/index.js} +170 -136
  27. package/module/jobs/child/forkProcess.js +99 -0
  28. package/module/jobs/child/index.js +33 -0
  29. package/module/jobs/index.js +55 -0
  30. package/module/jobs/renderer/index.js +140 -0
  31. package/module/jobs/renderer/loadView.js +40 -0
  32. package/module/loader/index.js +78 -0
  33. package/module/log/index.js +53 -0
  34. package/module/log/logger.js +61 -0
  35. package/module/message/index.js +13 -0
  36. package/module/message/ipcMain.js +160 -0
  37. package/module/message/ipcRender.js +0 -0
  38. package/{lib → module}/socket/httpServer.js +142 -142
  39. package/{lib → module}/socket/io.js +23 -23
  40. package/{lib → module}/socket/ipcServer.js +106 -108
  41. package/{lib → module}/socket/socketClient.js +51 -50
  42. package/{lib → module}/socket/socketServer.js +77 -76
  43. package/module/socket/start.js +22 -0
  44. package/{lib → module}/storage/index.js +35 -34
  45. package/module/storage/jsondb/adapters/Base.js +14 -0
  46. package/module/storage/jsondb/adapters/FileSync.js +32 -0
  47. package/{lib/storage/lowdb → module/storage/jsondb}/main.js +42 -46
  48. package/{lib/storage/lowdbStorage.js → module/storage/jsondbStorage.js} +98 -99
  49. package/{lib → module}/storage/sqliteStorage.js +123 -127
  50. package/module/utils/copyto.js +161 -0
  51. package/module/utils/helper.js +117 -0
  52. package/module/utils/index.js +120 -0
  53. package/module/utils/json.js +72 -0
  54. package/module/utils/ps.js +175 -0
  55. package/{utils → module/utils}/wrap.js +35 -37
  56. package/package.json +44 -48
  57. package/tools/encrypt.js +274 -274
  58. package/tools/replaceDist.js +61 -61
  59. package/utils/index.js +128 -246
  60. package/lib/logger.js +0 -47
  61. package/lib/socket/start.js +0 -22
  62. package/lib/storage/lowdb/adapters/Base.js +0 -15
  63. package/lib/storage/lowdb/adapters/FileAsync.js +0 -41
  64. package/lib/storage/lowdb/adapters/FileSync.js +0 -39
  65. package/lib/storage/lowdb/adapters/LocalStorage.js +0 -20
  66. package/lib/storage/lowdb/adapters/Memory.js +0 -8
  67. package/lib/storage/lowdb/adapters/_stringify.js +0 -4
  68. package/lib/storage/lowdb/common.js +0 -33
  69. package/lib/storage/lowdb/fp.js +0 -23
  70. package/lib/storage/lowdb/is-promise.js +0 -6
  71. package/lib/storage/lowdb/nano.js +0 -5
  72. package/utils/common.js +0 -91
package/core/lib/ee.js CHANGED
@@ -1,218 +1,218 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
- const fs = require('fs');
5
- const KoaApplication = require('koa');
6
- const is = require('is-type-of');
7
- const co = require('co');
8
- const BaseContextClass = require('./utils/base_context_class');
9
- const utils = require('./utils');
10
- const Timing = require('./utils/timing');
11
- const EggConsoleLogger = require('egg-logger').EggConsoleLogger;
12
- const debug = require('debug')('ee-core:EeCore');
13
- const EE_LOADER = Symbol.for('ee#loader');
14
-
15
- class EeCore extends KoaApplication {
16
-
17
- /**
18
- * @class
19
- * @param {Object} options - options
20
- * @since 1.0.0
21
- */
22
- constructor(options = {}) {
23
- options.type = options.type || 'application';
24
-
25
- assert(typeof options.baseDir === 'string', 'options.baseDir required, and must be a string');
26
- assert(fs.existsSync(options.baseDir), `Directory ${options.baseDir} not exists`);
27
- assert(fs.statSync(options.baseDir).isDirectory(), `Directory ${options.baseDir} is not a directory`);
28
-
29
- super();
30
-
31
- // todo
32
- //this.context = null;
33
-
34
- this.timing = new Timing();
35
-
36
- this.console = new EggConsoleLogger();
37
-
38
- /**
39
- * @member {Object} EeCore#options
40
- * @private
41
- * @since 1.0.0
42
- */
43
- this._options = this.options = options;
44
-
45
- /**
46
- * @member {BaseContextClass} EeCore#BaseContextClass
47
- * @since 1.0.0
48
- */
49
- this.BaseContextClass = BaseContextClass;
50
-
51
- /**
52
- * Base controller to be extended by controller in `app.controller`
53
- * @class Controller
54
- * @extends BaseContextClass
55
- * @example
56
- * class UserController extends app.Controller {}
57
- */
58
- const Controller = this.BaseContextClass;
59
-
60
- /**
61
- * Retrieve base controller
62
- * @member {Controller} EeCore#Controller
63
- * @since 1.0.0
64
- */
65
- this.Controller = Controller;
66
-
67
- /**
68
- * Base service to be extended by services in `app.service`
69
- * @class Service
70
- * @extends BaseContextClass
71
- * @example
72
- * class UserService extends app.Service {}
73
- */
74
- const Service = this.BaseContextClass;
75
-
76
- /**
77
- * Retrieve base service
78
- * @member {Service} EeCore#Service
79
- * @since 1.0.0
80
- */
81
- this.Service = Service;
82
-
83
- /**
84
- * The loader instance, the default class is {@link EeLoader}.
85
- * If you want define
86
- * @member {EeLoader} EeCore#loader
87
- * @since 1.0.0
88
- */
89
- const Loader = this[EE_LOADER];
90
- assert(Loader, 'Symbol.for(\'ee#loader\') is required');
91
- let loaderOptions = Object.assign({
92
- logger: this.console,
93
- app:this
94
- }, options);
95
- this.loader = new Loader(loaderOptions);
96
- }
97
-
98
- /**
99
- * override koa's app.use, support generator function
100
- * @param {Function} fn - middleware
101
- * @return {Application} app
102
- * @since 1.0.0
103
- */
104
- use(fn) {
105
- assert(is.function(fn), 'app.use() requires a function');
106
- debug('use %s', fn._name || fn.name || '-');
107
- this.middleware.push(utils.middleware(fn));
108
- return this;
109
- }
110
-
111
- /**
112
- * The home directory of application
113
- * @member {String}
114
- * @see {@link AppInfo#homeDir}
115
- * @since 1.0.0
116
- */
117
- get homeDir() {
118
- return this.options.homeDir;
119
- }
120
-
121
- /**
122
- * The electron current directory of application
123
- * @member {String}
124
- * @see {@link AppInfo#baseDir}
125
- * @since 1.0.0
126
- */
127
- get baseDir() {
128
- return this.options.baseDir;
129
- }
130
-
131
- /**
132
- * The ee-core directory of framework
133
- * @member {String}
134
- * @see {@link AppInfo#EeCoreDir}
135
- * @since 1.0.0
136
- */
137
- get eeCoreDir() {
138
- return this.options.framework;
139
- }
140
-
141
- /**
142
- * The name of application
143
- * @member {String}
144
- * @see {@link AppInfo#name}
145
- * @since 1.0.0
146
- */
147
- get name() {
148
- return this.loader ? this.loader.pkg.name : '';
149
- }
150
-
151
- /**
152
- * The configuration of application
153
- * @member {Config}
154
- * @since 1.0.0
155
- */
156
- get config() {
157
- return this.loader ? this.loader.config : {};
158
- }
159
-
160
- /**
161
- * The addon of application
162
- * @member {Addon}
163
- * @since 1.0.0
164
- */
165
- get addon() {
166
- return this.loader ? this.loader.addon : {};
167
- }
168
-
169
- get [EE_LOADER]() {
170
- return require('./loader/ee_loader');
171
- }
172
-
173
- /**
174
- * Convert a generator function to a promisable one.
175
- *
176
- * Notice: for other kinds of functions, it directly returns you what it is.
177
- *
178
- * @param {Function} fn The inputted function.
179
- * @return {AsyncFunction} An async promise-based function.
180
- * @example
181
- ```javascript
182
- const fn = function* (arg) {
183
- return arg;
184
- };
185
- const wrapped = app.toAsyncFunction(fn);
186
- wrapped(true).then((value) => console.log(value));
187
- ```
188
- */
189
- toAsyncFunction(fn) {
190
- if (!is.generatorFunction(fn)) return fn;
191
- fn = co.wrap(fn);
192
- return async function(...args) {
193
- return fn.apply(this, args);
194
- };
195
- }
196
-
197
- /**
198
- * Convert an object with generator functions to a Promisable one.
199
- * @param {Mixed} obj The inputted object.
200
- * @return {Promise} A Promisable result.
201
- * @example
202
- ```javascript
203
- const fn = function* (arg) {
204
- return arg;
205
- };
206
- const arr = [ fn(1), fn(2) ];
207
- const promise = app.toPromise(arr);
208
- promise.then(res => console.log(res));
209
- ```
210
- */
211
- toPromise(obj) {
212
- return co(function* () {
213
- return yield obj;
214
- });
215
- }
216
- }
217
-
218
- module.exports = EeCore;
1
+ 'use strict';
2
+
3
+ const assert = require('assert');
4
+ const fs = require('fs');
5
+ const KoaApplication = require('koa');
6
+ const is = require('is-type-of');
7
+ const co = require('co');
8
+ const BaseContextClass = require('./utils/base_context_class');
9
+ const utils = require('./utils');
10
+ const Timing = require('./utils/timing');
11
+ const EggConsoleLogger = require('egg-logger').EggConsoleLogger;
12
+ const debug = require('debug')('ee-core:EeCore');
13
+ const EE_LOADER = Symbol.for('ee#loader');
14
+
15
+ class EeCore extends KoaApplication {
16
+
17
+ /**
18
+ * @class
19
+ * @param {Object} options - options
20
+ * @since 1.0.0
21
+ */
22
+ constructor(options = {}) {
23
+ options.type = options.type || 'application';
24
+
25
+ assert(typeof options.baseDir === 'string', 'options.baseDir required, and must be a string');
26
+ assert(fs.existsSync(options.baseDir), `Directory ${options.baseDir} not exists`);
27
+ assert(fs.statSync(options.baseDir).isDirectory(), `Directory ${options.baseDir} is not a directory`);
28
+
29
+ super();
30
+
31
+ // todo
32
+ //this.context = null;
33
+
34
+ this.timing = new Timing();
35
+
36
+ this.console = new EggConsoleLogger({level: 'INFO'});
37
+
38
+ /**
39
+ * @member {Object} EeCore#options
40
+ * @private
41
+ * @since 1.0.0
42
+ */
43
+ this._options = this.options = options;
44
+
45
+ /**
46
+ * @member {BaseContextClass} EeCore#BaseContextClass
47
+ * @since 1.0.0
48
+ */
49
+ this.BaseContextClass = BaseContextClass;
50
+
51
+ /**
52
+ * Base controller to be extended by controller in `app.controller`
53
+ * @class Controller
54
+ * @extends BaseContextClass
55
+ * @example
56
+ * class UserController extends app.Controller {}
57
+ */
58
+ const Controller = this.BaseContextClass;
59
+
60
+ /**
61
+ * Retrieve base controller
62
+ * @member {Controller} EeCore#Controller
63
+ * @since 1.0.0
64
+ */
65
+ this.Controller = Controller;
66
+
67
+ /**
68
+ * Base service to be extended by services in `app.service`
69
+ * @class Service
70
+ * @extends BaseContextClass
71
+ * @example
72
+ * class UserService extends app.Service {}
73
+ */
74
+ const Service = this.BaseContextClass;
75
+
76
+ /**
77
+ * Retrieve base service
78
+ * @member {Service} EeCore#Service
79
+ * @since 1.0.0
80
+ */
81
+ this.Service = Service;
82
+
83
+ /**
84
+ * The loader instance, the default class is {@link EeLoader}.
85
+ * If you want define
86
+ * @member {EeLoader} EeCore#loader
87
+ * @since 1.0.0
88
+ */
89
+ const Loader = this[EE_LOADER];
90
+ assert(Loader, 'Symbol.for(\'ee#loader\') is required');
91
+ let loaderOptions = Object.assign({
92
+ logger: this.console,
93
+ app:this
94
+ }, options);
95
+ this.loader = new Loader(loaderOptions);
96
+ }
97
+
98
+ /**
99
+ * override koa's app.use, support generator function
100
+ * @param {Function} fn - middleware
101
+ * @return {Application} app
102
+ * @since 1.0.0
103
+ */
104
+ use(fn) {
105
+ assert(is.function(fn), 'app.use() requires a function');
106
+ debug('use %s', fn._name || fn.name || '-');
107
+ this.middleware.push(utils.middleware(fn));
108
+ return this;
109
+ }
110
+
111
+ /**
112
+ * The home directory of application
113
+ * @member {String}
114
+ * @see {@link AppInfo#homeDir}
115
+ * @since 1.0.0
116
+ */
117
+ get homeDir() {
118
+ return this.options.homeDir;
119
+ }
120
+
121
+ /**
122
+ * The electron current directory of application
123
+ * @member {String}
124
+ * @see {@link AppInfo#baseDir}
125
+ * @since 1.0.0
126
+ */
127
+ get baseDir() {
128
+ return this.options.baseDir;
129
+ }
130
+
131
+ /**
132
+ * The ee-core directory of framework
133
+ * @member {String}
134
+ * @see {@link AppInfo#EeCoreDir}
135
+ * @since 1.0.0
136
+ */
137
+ get eeCoreDir() {
138
+ return this.options.framework;
139
+ }
140
+
141
+ /**
142
+ * The name of application
143
+ * @member {String}
144
+ * @see {@link AppInfo#name}
145
+ * @since 1.0.0
146
+ */
147
+ get name() {
148
+ return this.loader ? this.loader.pkg.name : '';
149
+ }
150
+
151
+ /**
152
+ * The configuration of application
153
+ * @member {Config}
154
+ * @since 1.0.0
155
+ */
156
+ get config() {
157
+ return this.loader ? this.loader.config : {};
158
+ }
159
+
160
+ /**
161
+ * The addon of application
162
+ * @member {Addon}
163
+ * @since 1.0.0
164
+ */
165
+ get addon() {
166
+ return this.loader ? this.loader.addon : {};
167
+ }
168
+
169
+ get [EE_LOADER]() {
170
+ return require('./loader/ee_loader');
171
+ }
172
+
173
+ /**
174
+ * Convert a generator function to a promisable one.
175
+ *
176
+ * Notice: for other kinds of functions, it directly returns you what it is.
177
+ *
178
+ * @param {Function} fn The inputted function.
179
+ * @return {AsyncFunction} An async promise-based function.
180
+ * @example
181
+ ```javascript
182
+ const fn = function* (arg) {
183
+ return arg;
184
+ };
185
+ const wrapped = app.toAsyncFunction(fn);
186
+ wrapped(true).then((value) => console.log(value));
187
+ ```
188
+ */
189
+ toAsyncFunction(fn) {
190
+ if (!is.generatorFunction(fn)) return fn;
191
+ fn = co.wrap(fn);
192
+ return async function(...args) {
193
+ return fn.apply(this, args);
194
+ };
195
+ }
196
+
197
+ /**
198
+ * Convert an object with generator functions to a Promisable one.
199
+ * @param {Mixed} obj The inputted object.
200
+ * @return {Promise} A Promisable result.
201
+ * @example
202
+ ```javascript
203
+ const fn = function* (arg) {
204
+ return arg;
205
+ };
206
+ const arr = [ fn(1), fn(2) ];
207
+ const promise = app.toPromise(arr);
208
+ promise.then(res => console.log(res));
209
+ ```
210
+ */
211
+ toPromise(obj) {
212
+ return co(function* () {
213
+ return yield obj;
214
+ });
215
+ }
216
+ }
217
+
218
+ module.exports = EeCore;
@@ -1,106 +1,106 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
- const is = require('is-type-of');
5
- const FileLoader = require('./file_loader');
6
- const CLASSLOADER = Symbol('classLoader');
7
- const EXPORTS = FileLoader.EXPORTS;
8
- const utils = require('../utils');
9
-
10
- class ClassLoader {
11
-
12
- constructor(options) {
13
- assert(options.ctx, 'options.ctx is required');
14
- const properties = options.properties;
15
- this._cache = new Map();
16
- this._ctx = options.ctx;
17
-
18
- for (const property in properties) {
19
- this.defineProperty(property, properties[property]);
20
- }
21
- }
22
-
23
- defineProperty(property, values) {
24
- Object.defineProperty(this, property, {
25
- get() {
26
- let instance = this._cache.get(property);
27
- if (!instance) {
28
- instance = getInstance(values, this._ctx);
29
- this._cache.set(property, instance);
30
- }
31
- return instance;
32
- },
33
- });
34
- }
35
- }
36
-
37
- /**
38
- * Same as {@link FileLoader}, but it will attach file to `inject[fieldClass]`. The exports will be lazy loaded, such as `ctx.group.repository`.
39
- * @extends FileLoader
40
- * @since 1.0.0
41
- */
42
- class ContextLoader extends FileLoader {
43
-
44
- /**
45
- * @class
46
- * @param {Object} options - options same as {@link FileLoader}
47
- * @param {String} options.fieldClass - determine the field name of inject object.
48
- */
49
- constructor(options) {
50
- assert(options.property, 'options.property is required');
51
- assert(options.inject, 'options.inject is required');
52
- const target = options.target = {};
53
- if (options.fieldClass) {
54
- options.inject[options.fieldClass] = target;
55
- }
56
- super(options);
57
-
58
- const app = this.options.inject;
59
- const property = options.property;
60
-
61
- // define ctx.service
62
- Object.defineProperty(app, property, {
63
- get() {
64
- // distinguish property cache,
65
- // cache's lifecycle is the same with this context instance
66
- // e.x. ctx.service1 and ctx.service2 have different cache
67
- if (!this[CLASSLOADER]) {
68
- this[CLASSLOADER] = new Map();
69
- }
70
- const classLoader = this[CLASSLOADER];
71
-
72
- let instance = classLoader.get(property);
73
- if (!instance) {
74
- instance = getInstance(target, this);
75
- classLoader.set(property, instance);
76
- }
77
- return instance;
78
- },
79
- });
80
- }
81
- }
82
-
83
- module.exports = ContextLoader;
84
-
85
-
86
- function getInstance(values, ctx) {
87
- // it's a directory when it has no exports
88
- // then use ClassLoader
89
- const Class = values[EXPORTS] ? values : null;
90
- let instance;
91
- if (Class) {
92
- if (is.class(Class) || utils.isBytecodeClass(Class)) {
93
- instance = new Class(ctx);
94
- } else {
95
- // it's just an object
96
- instance = Class;
97
- }
98
- // Can't set property to primitive, so check again
99
- // e.x. module.exports = 1;
100
- } else if (is.primitive(values)) {
101
- instance = values;
102
- } else {
103
- instance = new ClassLoader({ ctx, properties: values });
104
- }
105
- return instance;
106
- }
1
+ 'use strict';
2
+
3
+ const assert = require('assert');
4
+ const is = require('is-type-of');
5
+ const FileLoader = require('./file_loader');
6
+ const CLASSLOADER = Symbol('classLoader');
7
+ const EXPORTS = FileLoader.EXPORTS;
8
+ const utils = require('../utils');
9
+
10
+ class ClassLoader {
11
+
12
+ constructor(options) {
13
+ assert(options.ctx, 'options.ctx is required');
14
+ const properties = options.properties;
15
+ this._cache = new Map();
16
+ this._ctx = options.ctx;
17
+
18
+ for (const property in properties) {
19
+ this.defineProperty(property, properties[property]);
20
+ }
21
+ }
22
+
23
+ defineProperty(property, values) {
24
+ Object.defineProperty(this, property, {
25
+ get() {
26
+ let instance = this._cache.get(property);
27
+ if (!instance) {
28
+ instance = getInstance(values, this._ctx);
29
+ this._cache.set(property, instance);
30
+ }
31
+ return instance;
32
+ },
33
+ });
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Same as {@link FileLoader}, but it will attach file to `inject[fieldClass]`. The exports will be lazy loaded, such as `ctx.group.repository`.
39
+ * @extends FileLoader
40
+ * @since 1.0.0
41
+ */
42
+ class ContextLoader extends FileLoader {
43
+
44
+ /**
45
+ * @class
46
+ * @param {Object} options - options same as {@link FileLoader}
47
+ * @param {String} options.fieldClass - determine the field name of inject object.
48
+ */
49
+ constructor(options) {
50
+ assert(options.property, 'options.property is required');
51
+ assert(options.inject, 'options.inject is required');
52
+ const target = options.target = {};
53
+ if (options.fieldClass) {
54
+ options.inject[options.fieldClass] = target;
55
+ }
56
+ super(options);
57
+
58
+ const app = this.options.inject;
59
+ const property = options.property;
60
+
61
+ // define ctx.service
62
+ Object.defineProperty(app, property, {
63
+ get() {
64
+ // distinguish property cache,
65
+ // cache's lifecycle is the same with this context instance
66
+ // e.x. ctx.service1 and ctx.service2 have different cache
67
+ if (!this[CLASSLOADER]) {
68
+ this[CLASSLOADER] = new Map();
69
+ }
70
+ const classLoader = this[CLASSLOADER];
71
+
72
+ let instance = classLoader.get(property);
73
+ if (!instance) {
74
+ instance = getInstance(target, this);
75
+ classLoader.set(property, instance);
76
+ }
77
+ return instance;
78
+ },
79
+ });
80
+ }
81
+ }
82
+
83
+ module.exports = ContextLoader;
84
+
85
+
86
+ function getInstance(values, ctx) {
87
+ // it's a directory when it has no exports
88
+ // then use ClassLoader
89
+ const Class = values[EXPORTS] ? values : null;
90
+ let instance;
91
+ if (Class) {
92
+ if (is.class(Class) || utils.isBytecodeClass(Class)) {
93
+ instance = new Class(ctx);
94
+ } else {
95
+ // it's just an object
96
+ instance = Class;
97
+ }
98
+ // Can't set property to primitive, so check again
99
+ // e.x. module.exports = 1;
100
+ } else if (is.primitive(values)) {
101
+ instance = values;
102
+ } else {
103
+ instance = new ClassLoader({ ctx, properties: values });
104
+ }
105
+ return instance;
106
+ }