ee-core 2.12.0 → 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 +19 -23
  7. package/config/default_config.js +110 -0
  8. package/config/index.js +20 -37
  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 +10 -10
  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 -143
  32. package/log/index.js +74 -57
  33. package/log/logger.js +75 -80
  34. package/message/childMessage.js +13 -13
  35. package/message/index.js +7 -16
  36. package/package.json +2 -2
  37. package/ps/index.js +136 -229
  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 -62
  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 -101
  72. package/ee/baseApp.js +0 -99
  73. package/ee/eeApp.js +0 -406
  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,25 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * BaseContextClass is a base class that can be extended,
5
- * it's instantiated in context level,
6
- */
7
- class BaseContextClass {
8
-
9
- /**
10
- * @class
11
- * @param {Context} ctx - context instance
12
- * @since 1.1.0
13
- */
14
- constructor(ctx) {
15
-
16
- // todo 兼容旧版本,后续废弃ctx
17
- if (typeof ctx === 'object') {
18
- this.app = ctx;
19
- this.config = ctx.config;
20
- this.service = ctx.service;
21
- }
22
- }
23
- }
24
-
25
- module.exports = BaseContextClass;
package/core/lib/ee.js DELETED
@@ -1,216 +0,0 @@
1
- const assert = require('assert');
2
- const fs = require('fs');
3
- const KoaApplication = require('koa');
4
- const is = require('is-type-of');
5
- const co = require('../../utils/co');
6
- const BaseContextClass = require('./utils/base_context_class');
7
- const utils = require('./utils');
8
- const Timing = require('./utils/timing');
9
- const EggConsoleLogger = require('egg-logger').EggConsoleLogger;
10
- const debug = require('debug')('ee-core:EeCore');
11
- const EE_LOADER = Symbol.for('ee#loader');
12
-
13
- class EeCore extends KoaApplication {
14
-
15
- /**
16
- * @class
17
- * @param {Object} options - options
18
- * @since 1.0.0
19
- */
20
- constructor(options = {}) {
21
- options.type = options.type || 'application';
22
-
23
- assert(typeof options.baseDir === 'string', 'options.baseDir required, and must be a string');
24
- // assert(fs.existsSync(options.baseDir), `Directory ${options.baseDir} not exists`);
25
- // assert(fs.statSync(options.baseDir).isDirectory(), `Directory ${options.baseDir} is not a directory`);
26
-
27
- super();
28
-
29
- // todo
30
- //this.context = null;
31
-
32
- this.timing = new Timing();
33
-
34
- this.console = new EggConsoleLogger({level: 'INFO'});
35
-
36
- /**
37
- * @member {Object} EeCore#options
38
- * @private
39
- * @since 1.0.0
40
- */
41
- this._options = this.options = options;
42
-
43
- /**
44
- * @member {BaseContextClass} EeCore#BaseContextClass
45
- * @since 1.0.0
46
- */
47
- this.BaseContextClass = BaseContextClass;
48
-
49
- /**
50
- * Base controller to be extended by controller in `app.controller`
51
- * @class Controller
52
- * @extends BaseContextClass
53
- * @example
54
- * class UserController extends app.Controller {}
55
- */
56
- const Controller = this.BaseContextClass;
57
-
58
- /**
59
- * Retrieve base controller
60
- * @member {Controller} EeCore#Controller
61
- * @since 1.0.0
62
- */
63
- this.Controller = Controller;
64
-
65
- /**
66
- * Base service to be extended by services in `app.service`
67
- * @class Service
68
- * @extends BaseContextClass
69
- * @example
70
- * class UserService extends app.Service {}
71
- */
72
- const Service = this.BaseContextClass;
73
-
74
- /**
75
- * Retrieve base service
76
- * @member {Service} EeCore#Service
77
- * @since 1.0.0
78
- */
79
- this.Service = Service;
80
-
81
- /**
82
- * The loader instance, the default class is {@link EeLoader}.
83
- * If you want define
84
- * @member {EeLoader} EeCore#loader
85
- * @since 1.0.0
86
- */
87
- const Loader = this[EE_LOADER];
88
- assert(Loader, 'Symbol.for(\'ee#loader\') is required');
89
- let loaderOptions = Object.assign({
90
- logger: this.console,
91
- app:this
92
- }, options);
93
- this.loader = new Loader(loaderOptions);
94
- }
95
-
96
- /**
97
- * override koa's app.use, support generator function
98
- * @param {Function} fn - middleware
99
- * @return {Application} app
100
- * @since 1.0.0
101
- */
102
- use(fn) {
103
- assert(is.function(fn), 'app.use() requires a function');
104
- debug('use %s', fn._name || fn.name || '-');
105
- this.middleware.push(utils.middleware(fn));
106
- return this;
107
- }
108
-
109
- /**
110
- * The home directory of application
111
- * @member {String}
112
- * @see {@link AppInfo#homeDir}
113
- * @since 1.0.0
114
- */
115
- get homeDir() {
116
- return this.options.homeDir;
117
- }
118
-
119
- /**
120
- * The electron current directory of application
121
- * @member {String}
122
- * @see {@link AppInfo#baseDir}
123
- * @since 1.0.0
124
- */
125
- get baseDir() {
126
- return this.options.baseDir;
127
- }
128
-
129
- /**
130
- * The ee-core directory of framework
131
- * @member {String}
132
- * @see {@link AppInfo#EeCoreDir}
133
- * @since 1.0.0
134
- */
135
- get eeCoreDir() {
136
- return this.options.framework;
137
- }
138
-
139
- /**
140
- * The name of application
141
- * @member {String}
142
- * @see {@link AppInfo#name}
143
- * @since 1.0.0
144
- */
145
- get name() {
146
- return this.loader ? this.loader.pkg.name : '';
147
- }
148
-
149
- /**
150
- * The configuration of application
151
- * @member {Config}
152
- * @since 1.0.0
153
- */
154
- get config() {
155
- return this.loader ? this.loader.config : {};
156
- }
157
-
158
- /**
159
- * The addon of application
160
- * @member {Addon}
161
- * @since 1.0.0
162
- */
163
- get addon() {
164
- return this.loader ? this.loader.addon : {};
165
- }
166
-
167
- get [EE_LOADER]() {
168
- return require('./loader/ee_loader');
169
- }
170
-
171
- /**
172
- * Convert a generator function to a promisable one.
173
- *
174
- * Notice: for other kinds of functions, it directly returns you what it is.
175
- *
176
- * @param {Function} fn The inputted function.
177
- * @return {AsyncFunction} An async promise-based function.
178
- * @example
179
- ```javascript
180
- const fn = function* (arg) {
181
- return arg;
182
- };
183
- const wrapped = app.toAsyncFunction(fn);
184
- wrapped(true).then((value) => console.log(value));
185
- ```
186
- */
187
- toAsyncFunction(fn) {
188
- if (!is.generatorFunction(fn)) return fn;
189
- fn = co.wrap(fn);
190
- return async function(...args) {
191
- return fn.apply(this, args);
192
- };
193
- }
194
-
195
- /**
196
- * Convert an object with generator functions to a Promisable one.
197
- * @param {Mixed} obj The inputted object.
198
- * @return {Promise} A Promisable result.
199
- * @example
200
- ```javascript
201
- const fn = function* (arg) {
202
- return arg;
203
- };
204
- const arr = [ fn(1), fn(2) ];
205
- const promise = app.toPromise(arr);
206
- promise.then(res => console.log(res));
207
- ```
208
- */
209
- toPromise(obj) {
210
- return co(function* () {
211
- return yield obj;
212
- });
213
- }
214
- }
215
-
216
- module.exports = EeCore;
@@ -1,106 +0,0 @@
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
- }