ee-core 2.12.0 → 4.0.0
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/app/application.d.ts +5 -0
- package/app/application.js +31 -0
- package/app/boot.d.ts +5 -0
- package/app/boot.js +74 -0
- package/app/dir.d.ts +1 -0
- package/app/dir.js +27 -0
- package/app/events.d.ts +14 -0
- package/app/events.js +56 -0
- package/app/index.d.ts +2 -0
- package/app/index.js +7 -0
- package/config/config_loader.d.ts +13 -0
- package/config/config_loader.js +19 -23
- package/config/default_config.d.ts +95 -0
- package/config/default_config.js +111 -0
- package/config/index.d.ts +28 -0
- package/config/index.js +20 -37
- package/const/channel.d.ts +16 -0
- package/const/channel.js +26 -16
- package/controller/controller_loader.d.ts +9 -0
- package/controller/controller_loader.js +78 -0
- package/controller/index.d.ts +2 -0
- package/controller/index.js +18 -19
- package/core/index.d.ts +2 -0
- package/core/index.js +6 -5
- package/core/loader/file_loader.d.ts +66 -0
- package/core/{lib/loader → loader}/file_loader.js +39 -156
- package/core/utils/index.d.ts +12 -0
- package/core/utils/index.js +83 -0
- package/core/utils/timing.d.ts +22 -0
- package/core/{lib/utils → utils}/timing.js +3 -2
- package/cross/cross.d.ts +19 -0
- package/cross/cross.js +152 -0
- package/cross/crossProcess.d.ts +29 -0
- package/cross/{spawnProcess.js → crossProcess.js} +36 -53
- package/cross/index.d.ts +2 -0
- package/cross/index.js +6 -181
- package/electron/app/index.d.ts +5 -0
- package/electron/app/index.js +38 -54
- package/electron/index.d.ts +3 -0
- package/electron/index.js +13 -17
- package/electron/window/index.d.ts +6 -0
- package/electron/window/index.js +260 -65
- package/exception/index.d.ts +9 -0
- package/exception/index.js +42 -54
- package/html/index.d.ts +1 -0
- package/html/index.js +7 -10
- package/index.d.ts +2 -0
- package/index.js +4 -52
- package/jobs/child/app.d.ts +1 -0
- package/jobs/child/app.js +10 -10
- package/jobs/child/index.d.ts +13 -0
- package/jobs/child/index.js +14 -11
- package/jobs/child/jobProcess.d.ts +16 -0
- package/jobs/child/{forkProcess.js → jobProcess.js} +31 -62
- package/jobs/child-pool/index.d.ts +26 -0
- package/jobs/child-pool/index.js +25 -48
- package/jobs/index.d.ts +3 -0
- package/jobs/index.js +2 -4
- package/jobs/load-balancer/algorithm/index.d.ts +4 -0
- package/jobs/load-balancer/algorithm/minimumConnection.d.ts +2 -0
- package/jobs/load-balancer/algorithm/polling.d.ts +2 -0
- package/jobs/load-balancer/algorithm/random.d.ts +2 -0
- package/jobs/load-balancer/algorithm/specify.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weights.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weightsMinimumConnection.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weightsPolling.d.ts +2 -0
- package/jobs/load-balancer/algorithm/weightsRandom.d.ts +2 -0
- package/jobs/load-balancer/consts.d.ts +8 -0
- package/jobs/load-balancer/index.d.ts +96 -0
- package/jobs/load-balancer/scheduler.d.ts +16 -0
- package/loader/index.d.ts +9 -0
- package/loader/index.js +73 -143
- package/log/index.d.ts +5 -0
- package/log/index.js +74 -57
- package/log/logger.d.ts +2 -0
- package/log/logger.js +75 -80
- package/message/childMessage.d.ts +10 -0
- package/message/childMessage.js +15 -25
- package/message/index.d.ts +3 -0
- package/message/index.js +7 -16
- package/package.json +8 -2
- package/ps/index.d.ts +37 -0
- package/ps/index.js +135 -238
- package/socket/httpServer.d.ts +8 -0
- package/socket/httpServer.js +55 -45
- package/socket/index.d.ts +10 -0
- package/socket/index.js +52 -69
- package/socket/ipcServer.d.ts +9 -0
- package/socket/ipcServer.js +87 -94
- package/socket/socketServer.d.ts +10 -0
- package/socket/socketServer.js +37 -25
- package/storage/index.d.ts +5 -0
- package/storage/index.js +5 -37
- package/storage/sqliteStorage.d.ts +16 -0
- package/storage/sqliteStorage.js +20 -20
- package/tsconfig.json +14 -0
- package/utils/extend.d.ts +2 -0
- package/utils/extend.js +10 -5
- package/utils/helper.d.ts +14 -0
- package/utils/helper.js +39 -53
- package/utils/index.d.ts +10 -0
- package/utils/index.js +47 -40
- package/utils/ip.d.ts +2 -0
- package/utils/ip.js +5 -45
- package/utils/is.d.ts +14 -0
- package/utils/is.js +107 -141
- package/utils/json.d.ts +5 -0
- package/utils/json.js +15 -7
- package/utils/pargv.d.ts +3 -0
- package/utils/pargv.js +5 -1
- package/utils/port/index.d.ts +1 -0
- package/utils/{get-port → port}/index.js +4 -26
- package/utils/wrap.d.ts +4 -0
- package/utils/wrap.js +8 -3
- package/addon/index.js +0 -35
- package/addon/window/index.js +0 -99
- package/bin/tools.js +0 -8
- package/config/cache.js +0 -62
- package/config/config.default.js +0 -331
- package/const/index.js +0 -9
- package/controller/baseContextClass.js +0 -25
- package/core/lib/ee.js +0 -216
- package/core/lib/loader/context_loader.js +0 -106
- package/core/lib/loader/ee_loader.js +0 -435
- package/core/lib/loader/mixin/addon.js +0 -32
- package/core/lib/loader/mixin/config.js +0 -130
- package/core/lib/loader/mixin/controller.js +0 -125
- package/core/lib/loader/mixin/service.js +0 -28
- package/core/lib/utils/base_context_class.js +0 -34
- package/core/lib/utils/function.js +0 -30
- package/core/lib/utils/index.js +0 -133
- package/core/lib/utils/sequencify.js +0 -59
- package/ee/appLoader.js +0 -48
- package/ee/application.js +0 -101
- package/ee/baseApp.js +0 -99
- package/ee/eeApp.js +0 -406
- package/ee/index.js +0 -58
- package/electron/window/winState.js +0 -186
- package/httpclient/index.js +0 -161
- package/jobs/baseJobClass.js +0 -16
- package/jobs/renderer/index.js +0 -141
- package/jobs/renderer/loadView.js +0 -41
- package/jobs/unification.js +0 -64
- package/main/index.js +0 -57
- package/old-utils/index.js +0 -91
- package/services/baseContextClass.js +0 -24
- package/services/index.js +0 -41
- package/socket/io.js +0 -28
- package/storage/jsondb/adapters/Base.js +0 -23
- package/storage/jsondb/adapters/FileSync.js +0 -64
- package/storage/jsondb/main.js +0 -55
- package/storage/jsondbStorage.js +0 -196
- package/utils/co.js +0 -237
- package/utils/copyto.js +0 -161
- package/utils/depd/index.js +0 -538
- package/utils/depd/lib/browser/index.js +0 -77
- package/utils/get-port/index.d.ts +0 -64
- package/utils/time/index.js +0 -20
- package/utils/time/ms.js +0 -162
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const debug = require('debug')('ee-core:controller:controller_loader');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const is = require('is-type-of');
|
|
6
|
+
const { getElectronDir } = require('../ps');
|
|
7
|
+
const { Timing } = require('../core/utils/timing');
|
|
8
|
+
const { FileLoader, FULLPATH } = require('../core/loader/file_loader');
|
|
9
|
+
const { isBytecodeClass, callFn } = require('../core/utils');
|
|
10
|
+
|
|
11
|
+
class ControllerLoader {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.timing = new Timing();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Load controller/xxx.js
|
|
18
|
+
*/
|
|
19
|
+
load() {
|
|
20
|
+
this.timing.start('Load Controller');
|
|
21
|
+
|
|
22
|
+
const opt = {
|
|
23
|
+
caseStyle: 'lower',
|
|
24
|
+
directory: path.join(getElectronDir(), 'controller'),
|
|
25
|
+
initializer: (obj, opt) => {
|
|
26
|
+
if (is.class(obj) || isBytecodeClass(obj)) {
|
|
27
|
+
obj.prototype.pathName = opt.pathName;
|
|
28
|
+
obj.prototype.fullPath = opt.path;
|
|
29
|
+
return wrapClass(obj);
|
|
30
|
+
}
|
|
31
|
+
return obj;
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const target = new FileLoader(opt).load();
|
|
35
|
+
debug("[load] controllers: %o", target);
|
|
36
|
+
this.timing.end('Load Controller');
|
|
37
|
+
return target;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// wrap the class, yield a object with middlewares
|
|
42
|
+
function wrapClass(Controller) {
|
|
43
|
+
let proto = Controller.prototype;
|
|
44
|
+
const ret = {};
|
|
45
|
+
// tracing the prototype chain
|
|
46
|
+
while (proto !== Object.prototype) {
|
|
47
|
+
const keys = Object.getOwnPropertyNames(proto);
|
|
48
|
+
// debug("[wrapClass] keys:", keys);
|
|
49
|
+
for (const key of keys) {
|
|
50
|
+
// getOwnPropertyNames will return constructor
|
|
51
|
+
// that should be ignored
|
|
52
|
+
if (key === 'constructor') {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
// skip getter, setter & non-function properties
|
|
56
|
+
const d = Object.getOwnPropertyDescriptor(proto, key);
|
|
57
|
+
// prevent to override sub method
|
|
58
|
+
if (is.function(d.value) && !ret.hasOwnProperty(key)) {
|
|
59
|
+
ret[key] = methodToMiddleware(Controller, key);
|
|
60
|
+
ret[key][FULLPATH] = Controller.prototype.fullPath + '#' + Controller.name + '.' + key + '()';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
proto = Object.getPrototypeOf(proto);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return ret;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function methodToMiddleware(Controller, key) {
|
|
70
|
+
return function classControllerMiddleware(...args) {
|
|
71
|
+
const controller = new Controller();
|
|
72
|
+
return callFn(controller[key], args, controller);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = {
|
|
77
|
+
ControllerLoader
|
|
78
|
+
};
|
package/controller/index.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* BaseContextClass is a base class that can be extended,
|
|
5
|
-
* it's instantiated in context level,
|
|
6
|
-
*/
|
|
7
|
-
class BaseContextClass {
|
|
3
|
+
const { ControllerLoader } = require('./controller_loader');
|
|
8
4
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* @since 1.1.0
|
|
13
|
-
*/
|
|
14
|
-
constructor(ctx) {
|
|
5
|
+
const Instance = {
|
|
6
|
+
controller: null,
|
|
7
|
+
};
|
|
15
8
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
function loadController() {
|
|
10
|
+
const controllerLoader = new ControllerLoader();
|
|
11
|
+
Instance.controller = controllerLoader.load();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getController() {
|
|
15
|
+
if (!Instance.controller) {
|
|
16
|
+
loadController();
|
|
22
17
|
}
|
|
18
|
+
return Instance.controller;
|
|
23
19
|
}
|
|
24
20
|
|
|
25
|
-
module.exports =
|
|
21
|
+
module.exports = {
|
|
22
|
+
loadController,
|
|
23
|
+
getController
|
|
24
|
+
};
|
package/core/index.d.ts
ADDED
package/core/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const EeLoader = require('./loader/ee_loader');
|
|
4
|
+
const BaseContextClass = require('./utils/base_context_class');
|
|
5
|
+
const utils = require('./utils');
|
|
6
|
+
|
|
5
7
|
|
|
6
8
|
module.exports = {
|
|
7
|
-
EeCore,
|
|
8
9
|
EeLoader,
|
|
9
10
|
BaseContextClass,
|
|
10
11
|
utils,
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Load files from directory to target object.
|
|
3
|
+
*/
|
|
4
|
+
export declare class FileLoader {
|
|
5
|
+
/**
|
|
6
|
+
* @class
|
|
7
|
+
* @param {Object} options - options
|
|
8
|
+
* @param {String|Array} options.directory - directories to be loaded
|
|
9
|
+
* @param {Object} options.target - attach the target object from loaded files
|
|
10
|
+
* @param {String} options.match - match the files when load, support glob, default to all js files
|
|
11
|
+
* @param {Function} options.initializer - custom file exports, receive two parameters, first is the inject object(if not js file, will be content buffer), second is an `options` object that contain `path`
|
|
12
|
+
* @param {Boolean} options.call - determine whether invoke when exports is function
|
|
13
|
+
* @param {Object} options.inject - an object that be the argument when invoke the function
|
|
14
|
+
* @param {String|Function} options.caseStyle - set property's case when converting a filepath to property list.
|
|
15
|
+
*/
|
|
16
|
+
constructor(options: {
|
|
17
|
+
directory: string | any[];
|
|
18
|
+
target: any;
|
|
19
|
+
match: string;
|
|
20
|
+
initializer: Function;
|
|
21
|
+
call: boolean;
|
|
22
|
+
inject: any;
|
|
23
|
+
caseStyle: string | Function;
|
|
24
|
+
});
|
|
25
|
+
options: {
|
|
26
|
+
directory: any;
|
|
27
|
+
target: any;
|
|
28
|
+
match: any;
|
|
29
|
+
caseStyle: string;
|
|
30
|
+
initializer: any;
|
|
31
|
+
call: boolean;
|
|
32
|
+
inject: any;
|
|
33
|
+
} & {
|
|
34
|
+
directory: string | any[];
|
|
35
|
+
target: any;
|
|
36
|
+
match: string;
|
|
37
|
+
initializer: Function;
|
|
38
|
+
call: boolean;
|
|
39
|
+
inject: any;
|
|
40
|
+
caseStyle: string | Function;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* attach items to target object. Mapping the directory to properties.
|
|
44
|
+
* `xxx/group/repository.js` => `target.group.repository`
|
|
45
|
+
* @return {Object} target
|
|
46
|
+
*/
|
|
47
|
+
load(): any;
|
|
48
|
+
/**
|
|
49
|
+
* Parse files from given directories, then return an items list, each item contains properties and exports.
|
|
50
|
+
* For example, parse `controller/group/repository.js`
|
|
51
|
+
* It returns a item
|
|
52
|
+
* ```
|
|
53
|
+
* {
|
|
54
|
+
* fullpath: '',
|
|
55
|
+
* properties: [ 'group', 'repository' ],
|
|
56
|
+
* exports: { ... },
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
* `Properties` is an array that contains the directory of a filepath.
|
|
60
|
+
* `Exports` depends on type, if exports is a function, it will be called. if initializer is specified, it will be called with exports for customizing.
|
|
61
|
+
* @return {Array} items
|
|
62
|
+
*/
|
|
63
|
+
parse(): any[];
|
|
64
|
+
}
|
|
65
|
+
export declare const EXPORTS: unique symbol;
|
|
66
|
+
export declare const FULLPATH: unique symbol;
|
|
@@ -1,35 +1,27 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const debug = require('debug')('ee-core:core:loader:file_loader');
|
|
3
4
|
const assert = require('assert');
|
|
4
5
|
const fs = require('fs');
|
|
5
|
-
const debug = require('debug')('ee-core:fileLoader');
|
|
6
6
|
const path = require('path');
|
|
7
7
|
const globby = require('globby');
|
|
8
8
|
const is = require('is-type-of');
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const EXPORTS = Symbol('EE_LOADER_ITEM_EXPORTS');
|
|
13
|
-
//const Addon = require('../../../addon');
|
|
9
|
+
const { isBytecodeClass, loadFile, filePatterns } = require('../utils');
|
|
10
|
+
const FULLPATH = Symbol('LOADER_ITEM_FULLPATH');
|
|
11
|
+
const EXPORTS = Symbol('LOADER_ITEM_EXPORTS');
|
|
14
12
|
|
|
15
13
|
const defaults = {
|
|
16
14
|
directory: null,
|
|
17
15
|
target: null,
|
|
18
16
|
match: undefined,
|
|
19
|
-
ignore: undefined,
|
|
20
|
-
lowercaseFirst: false,
|
|
21
17
|
caseStyle: 'camel',
|
|
22
18
|
initializer: null,
|
|
23
19
|
call: true,
|
|
24
|
-
override: false,
|
|
25
20
|
inject: undefined,
|
|
26
|
-
filter: null,
|
|
27
|
-
loader: undefined,
|
|
28
21
|
};
|
|
29
22
|
|
|
30
23
|
/**
|
|
31
24
|
* Load files from directory to target object.
|
|
32
|
-
* @since 1.0.0
|
|
33
25
|
*/
|
|
34
26
|
class FileLoader {
|
|
35
27
|
|
|
@@ -39,46 +31,31 @@ class FileLoader {
|
|
|
39
31
|
* @param {String|Array} options.directory - directories to be loaded
|
|
40
32
|
* @param {Object} options.target - attach the target object from loaded files
|
|
41
33
|
* @param {String} options.match - match the files when load, support glob, default to all js files
|
|
42
|
-
* @param {String} options.ignore - ignore the files when load, support glob
|
|
43
34
|
* @param {Function} options.initializer - custom file exports, receive two parameters, first is the inject object(if not js file, will be content buffer), second is an `options` object that contain `path`
|
|
44
35
|
* @param {Boolean} options.call - determine whether invoke when exports is function
|
|
45
|
-
* @param {Boolean} options.override - determine whether override the property when get the same name
|
|
46
36
|
* @param {Object} options.inject - an object that be the argument when invoke the function
|
|
47
|
-
* @param {Function} options.filter - a function that filter the exports which can be loaded
|
|
48
37
|
* @param {String|Function} options.caseStyle - set property's case when converting a filepath to property list.
|
|
49
|
-
* @param {Object} options.loader - an object that be the argument when invoke the function
|
|
50
38
|
*/
|
|
51
39
|
constructor(options) {
|
|
52
40
|
assert(options.directory, 'options.directory is required');
|
|
53
|
-
assert(options.target, 'options.target is required');
|
|
54
41
|
this.options = Object.assign({}, defaults, options);
|
|
55
|
-
|
|
56
|
-
// compatible old options _lowercaseFirst_
|
|
57
|
-
if (this.options.lowercaseFirst === true) {
|
|
58
|
-
deprecate('lowercaseFirst is deprecated, use caseStyle instead');
|
|
59
|
-
this.options.caseStyle = 'lower';
|
|
60
|
-
}
|
|
42
|
+
debug("[constructor] options: %o", this.options);
|
|
61
43
|
}
|
|
62
44
|
|
|
63
45
|
/**
|
|
64
46
|
* attach items to target object. Mapping the directory to properties.
|
|
65
|
-
* `
|
|
47
|
+
* `xxx/group/repository.js` => `target.group.repository`
|
|
66
48
|
* @return {Object} target
|
|
67
|
-
* @since 1.0.0
|
|
68
49
|
*/
|
|
69
50
|
load() {
|
|
70
51
|
const items = this.parse();
|
|
71
|
-
const target =
|
|
52
|
+
const target = {};
|
|
72
53
|
for (const item of items) {
|
|
73
|
-
// item { properties: [ 'a', 'b', 'c'], exports }
|
|
74
|
-
// => target.a.b.c = exports
|
|
54
|
+
// item { fullpath, properties: [ 'a', 'b', 'c'], exports }
|
|
75
55
|
item.properties.reduce((target, property, index) => {
|
|
76
56
|
let obj;
|
|
77
|
-
|
|
57
|
+
// properties is a path slice, only the last value is the file name
|
|
78
58
|
if (index === item.properties.length - 1) {
|
|
79
|
-
if (property in target) {
|
|
80
|
-
if (!this.options.override) throw new Error(`can't overwrite property '${properties}' from ${target[property][FULLPATH]} by ${item.fullpath}`);
|
|
81
|
-
}
|
|
82
59
|
obj = item.exports;
|
|
83
60
|
if (obj && !is.primitive(obj)) {
|
|
84
61
|
obj[FULLPATH] = item.fullpath;
|
|
@@ -89,166 +66,78 @@ class FileLoader {
|
|
|
89
66
|
}
|
|
90
67
|
|
|
91
68
|
target[property] = obj;
|
|
92
|
-
|
|
69
|
+
// const properties = item.properties.slice(0, index + 1).join('.');
|
|
70
|
+
// debug('[load] properties: %s', properties);
|
|
93
71
|
return obj;
|
|
94
72
|
}, target);
|
|
95
73
|
}
|
|
96
|
-
|
|
74
|
+
//debug('[load] target: %O', target);
|
|
97
75
|
return target;
|
|
98
76
|
}
|
|
99
77
|
|
|
100
78
|
/**
|
|
101
79
|
* Parse files from given directories, then return an items list, each item contains properties and exports.
|
|
102
|
-
*
|
|
103
|
-
* For example, parse `app/controller/group/repository.js`
|
|
104
|
-
*
|
|
105
|
-
* ```
|
|
106
|
-
* module.exports = app => {
|
|
107
|
-
* return class RepositoryController extends app.Controller {};
|
|
108
|
-
* }
|
|
109
|
-
* ```
|
|
110
|
-
*
|
|
80
|
+
* For example, parse `controller/group/repository.js`
|
|
111
81
|
* It returns a item
|
|
112
|
-
*
|
|
113
82
|
* ```
|
|
114
83
|
* {
|
|
84
|
+
* fullpath: '',
|
|
115
85
|
* properties: [ 'group', 'repository' ],
|
|
116
|
-
* exports:
|
|
86
|
+
* exports: { ... },
|
|
117
87
|
* }
|
|
118
88
|
* ```
|
|
119
|
-
*
|
|
120
89
|
* `Properties` is an array that contains the directory of a filepath.
|
|
121
|
-
*
|
|
122
90
|
* `Exports` depends on type, if exports is a function, it will be called. if initializer is specified, it will be called with exports for customizing.
|
|
123
91
|
* @return {Array} items
|
|
124
|
-
* @since 1.0.0
|
|
125
92
|
*/
|
|
126
93
|
parse() {
|
|
127
94
|
let files = this.options.match;
|
|
128
95
|
if (!files) {
|
|
129
|
-
files = (
|
|
130
|
-
? [ '**/*.(js|ts)', '!**/*.d.ts' ]
|
|
131
|
-
: [ '**/*.js', '**/*.jsc'];
|
|
96
|
+
files = filePatterns();
|
|
132
97
|
} else {
|
|
133
98
|
files = Array.isArray(files) ? files : [ files ];
|
|
134
99
|
}
|
|
135
|
-
|
|
136
|
-
let ignore = this.options.ignore;
|
|
137
|
-
if (ignore) {
|
|
138
|
-
ignore = Array.isArray(ignore) ? ignore : [ ignore ];
|
|
139
|
-
ignore = ignore.filter(f => !!f).map(f => '!' + f);
|
|
140
|
-
files = files.concat(ignore);
|
|
141
|
-
}
|
|
142
100
|
|
|
143
101
|
let directories = this.options.directory;
|
|
144
102
|
if (!Array.isArray(directories)) {
|
|
145
103
|
directories = [ directories ];
|
|
146
104
|
}
|
|
147
105
|
|
|
148
|
-
const filter = is.function(this.options.filter) ? this.options.filter : null;
|
|
149
106
|
const items = [];
|
|
150
|
-
debug('
|
|
151
|
-
|
|
107
|
+
debug('[parse] directories %o', directories);
|
|
108
|
+
|
|
152
109
|
for (const directory of directories) {
|
|
153
110
|
const filepaths = globby.sync(files, { cwd: directory });
|
|
111
|
+
debug('[parse] filepaths %o', filepaths);
|
|
154
112
|
for (const filepath of filepaths) {
|
|
155
113
|
const fullpath = path.join(directory, filepath);
|
|
156
114
|
if (!fs.statSync(fullpath).isFile()) continue;
|
|
157
115
|
// get properties
|
|
158
|
-
//
|
|
116
|
+
// controller/foo/bar.js => [ 'foo', 'bar' ]
|
|
159
117
|
const properties = getProperties(filepath, this.options);
|
|
160
|
-
//
|
|
118
|
+
// debug('[parse] properties %o', properties);
|
|
119
|
+
// controller/foo/bar.js => controller.foo.bar
|
|
161
120
|
const pathName = directory.split(/[/\\]/).slice(-1) + '.' + properties.join('.');
|
|
121
|
+
// debug('[parse] pathName %s', pathName);
|
|
162
122
|
// get exports from the file
|
|
163
123
|
let exports = getExports(fullpath, this.options, pathName);
|
|
164
124
|
// ignore exports when it's null or false returned by filter function
|
|
165
|
-
if (exports == null
|
|
125
|
+
if (exports == null) continue;
|
|
166
126
|
|
|
167
127
|
// set properties of class
|
|
168
|
-
if (is.class(exports) ||
|
|
128
|
+
if (is.class(exports) || isBytecodeClass(exports)) {
|
|
169
129
|
exports.prototype.pathName = pathName;
|
|
170
130
|
exports.prototype.fullPath = fullpath;
|
|
171
131
|
}
|
|
172
|
-
|
|
173
132
|
items.push({ fullpath, properties, exports });
|
|
174
|
-
debug('parse %s, properties %
|
|
133
|
+
//debug('[parse] fullpath %s, properties %o, export %o', fullpath, properties, exports);
|
|
175
134
|
}
|
|
176
135
|
}
|
|
177
|
-
|
|
136
|
+
//debug('[parse] items %O', items);
|
|
178
137
|
return items;
|
|
179
138
|
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* attach items to target object for addons.
|
|
183
|
-
* `app/addon/group/index.js` => `target.group`
|
|
184
|
-
* @return {Object} target
|
|
185
|
-
* @since 1.0.0
|
|
186
|
-
*/
|
|
187
|
-
loadAddons() {
|
|
188
|
-
const items = [];
|
|
189
|
-
const files = '*';
|
|
190
|
-
const app = this.options.inject;
|
|
191
|
-
const loader = this.options.loader;
|
|
192
|
-
const target = this.options.target;
|
|
193
|
-
let directories = this.options.directory;
|
|
194
|
-
|
|
195
|
-
if (!Array.isArray(directories)) {
|
|
196
|
-
directories = [ directories ];
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// check addon
|
|
200
|
-
const config = app.config.addons;
|
|
201
|
-
let filterAddons = [];
|
|
202
|
-
for (let key of Object.keys(config)) {
|
|
203
|
-
if (!config[key].enable) {
|
|
204
|
-
filterAddons.push(key);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
for (const directory of directories) {
|
|
209
|
-
const addonpaths = globby.sync(files, { cwd: directory, deep: 1, onlyDirectories: true});
|
|
210
|
-
for (const addonName of addonpaths) {
|
|
211
|
-
if (filterAddons.includes(addonName)) continue;
|
|
212
|
-
|
|
213
|
-
const filepath = path.join(directory, addonName, 'index');
|
|
214
|
-
const fullpath = loader.resolveModule(filepath);
|
|
215
|
-
if (!fs.existsSync(fullpath)) {
|
|
216
|
-
throw new Error(`The ${filepath} file does not exist`);
|
|
217
|
-
}
|
|
218
|
-
if (!fs.statSync(fullpath).isFile()) continue;
|
|
219
|
-
|
|
220
|
-
let exports = getExports(fullpath, this.options, addonName);
|
|
221
|
-
if (exports == null) continue;
|
|
222
|
-
|
|
223
|
-
const properties = [addonName];
|
|
224
|
-
if (is.class(exports) || Utils.isBytecodeClass(exports)) {
|
|
225
|
-
exports.prototype.pathName = addonName;
|
|
226
|
-
exports.prototype.fullPath = fullpath;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
items.push({ fullpath, properties, exports });
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
for (const item of items) {
|
|
233
|
-
const property = item.properties[0];
|
|
234
|
-
let obj = item.exports;
|
|
235
|
-
if (obj && !is.primitive(obj)) {
|
|
236
|
-
obj[FULLPATH] = item.fullpath;
|
|
237
|
-
obj[EXPORTS] = true;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
target[property] = obj;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return target;
|
|
245
|
-
}
|
|
246
139
|
}
|
|
247
140
|
|
|
248
|
-
module.exports = FileLoader;
|
|
249
|
-
module.exports.EXPORTS = EXPORTS;
|
|
250
|
-
module.exports.FULLPATH = FULLPATH;
|
|
251
|
-
|
|
252
141
|
// convert file path to an array of properties
|
|
253
142
|
// a/b/c.js => ['a', 'b', 'c']
|
|
254
143
|
function getProperties(filepath, { caseStyle }) {
|
|
@@ -265,29 +154,18 @@ function getProperties(filepath, { caseStyle }) {
|
|
|
265
154
|
// Get exports from filepath
|
|
266
155
|
// If exports is null/undefined, it will be ignored
|
|
267
156
|
function getExports(fullpath, { initializer, call, inject }, pathName) {
|
|
268
|
-
let exports =
|
|
269
|
-
|
|
270
|
-
// process exports as you like
|
|
157
|
+
let exports = loadFile(fullpath);
|
|
158
|
+
//debug('[getExports] exports %o', exports);
|
|
271
159
|
if (initializer) {
|
|
160
|
+
// exports type is Class or Object
|
|
272
161
|
exports = initializer(exports, { path: fullpath, pathName });
|
|
273
162
|
}
|
|
274
163
|
|
|
275
|
-
|
|
276
|
-
//
|
|
277
|
-
// module.exports = class Service {};
|
|
278
|
-
// or
|
|
279
|
-
// module.exports = function*() {}
|
|
280
|
-
//new exports;
|
|
281
|
-
|
|
282
|
-
if (is.class(exports) || is.generatorFunction(exports) || is.asyncFunction(exports) || Utils.isBytecodeClass(exports)) {
|
|
164
|
+
if (is.class(exports) || is.generatorFunction(exports) || is.asyncFunction(exports) || isBytecodeClass(exports)) {
|
|
283
165
|
return exports;
|
|
284
166
|
}
|
|
285
167
|
|
|
286
|
-
//
|
|
287
|
-
//
|
|
288
|
-
// module.exports = function(app) {
|
|
289
|
-
// return {};
|
|
290
|
-
// }
|
|
168
|
+
// whether to execute the function
|
|
291
169
|
if (call && is.function(exports)) {
|
|
292
170
|
exports = exports(inject);
|
|
293
171
|
if (exports != null) {
|
|
@@ -295,7 +173,6 @@ function getExports(fullpath, { initializer, call, inject }, pathName) {
|
|
|
295
173
|
}
|
|
296
174
|
}
|
|
297
175
|
|
|
298
|
-
// return exports what is
|
|
299
176
|
return exports;
|
|
300
177
|
}
|
|
301
178
|
|
|
@@ -311,7 +188,7 @@ function defaultCamelize(filepath, caseStyle) {
|
|
|
311
188
|
// fooBar.js > FooBar
|
|
312
189
|
// FooBar.js > FooBar
|
|
313
190
|
// FooBar.js > FooBar
|
|
314
|
-
// FooBar.js > fooBar
|
|
191
|
+
// FooBar.js > fooBar
|
|
315
192
|
property = property.replace(/[_-][a-z]/ig, s => s.substring(1).toUpperCase());
|
|
316
193
|
let first = property[0];
|
|
317
194
|
switch (caseStyle) {
|
|
@@ -327,3 +204,9 @@ function defaultCamelize(filepath, caseStyle) {
|
|
|
327
204
|
return first + property.substring(1);
|
|
328
205
|
});
|
|
329
206
|
}
|
|
207
|
+
|
|
208
|
+
module.exports = {
|
|
209
|
+
FileLoader,
|
|
210
|
+
EXPORTS,
|
|
211
|
+
FULLPATH,
|
|
212
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const extensions: any;
|
|
2
|
+
export declare function loadFile(filepath: any): any;
|
|
3
|
+
export declare function callFn(fn: any, args: any, ctx: any): Promise<any>;
|
|
4
|
+
export declare function getResolvedFilename(filepath: any, baseDir: any): any;
|
|
5
|
+
/**
|
|
6
|
+
* 字节码类
|
|
7
|
+
*/
|
|
8
|
+
export declare function isBytecodeClass(exports: any): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* 文件类型
|
|
11
|
+
*/
|
|
12
|
+
export declare function filePatterns(): string[];
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('bytenode');
|
|
4
|
+
const is = require('is-type-of');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const BuiltinModule = require('module');
|
|
8
|
+
|
|
9
|
+
// Guard against poorly mocked module constructors.
|
|
10
|
+
const Module = module.constructor.length > 1
|
|
11
|
+
? module.constructor
|
|
12
|
+
/* istanbul ignore next */
|
|
13
|
+
: BuiltinModule;
|
|
14
|
+
|
|
15
|
+
// Module._extensions:
|
|
16
|
+
// '.js': [Function (anonymous)],
|
|
17
|
+
// '.json': [Function (anonymous)],
|
|
18
|
+
// '.node': [Function: func],
|
|
19
|
+
// '.jsc': [Function (anonymous)]
|
|
20
|
+
|
|
21
|
+
const extensions = Module._extensions;
|
|
22
|
+
|
|
23
|
+
function loadFile(filepath) {
|
|
24
|
+
try {
|
|
25
|
+
// if not js module, just return content buffer
|
|
26
|
+
const extname = path.extname(filepath);
|
|
27
|
+
if (extname && !Module._extensions[extname]) {
|
|
28
|
+
return fs.readFileSync(filepath);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// require js module
|
|
32
|
+
const obj = require(filepath);
|
|
33
|
+
if (!obj) return obj;
|
|
34
|
+
// it's es module
|
|
35
|
+
if (obj.__esModule) return 'default' in obj ? obj.default : obj;
|
|
36
|
+
return obj;
|
|
37
|
+
} catch (err) {
|
|
38
|
+
err.message = `[ee-core] load file: ${filepath}, error: ${err.message}`;
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function callFn(fn, args, ctx) {
|
|
44
|
+
args = args || [];
|
|
45
|
+
if (!is.function(fn)) return;
|
|
46
|
+
return ctx ? fn.call(ctx, ...args) : fn(...args);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getResolvedFilename(filepath, baseDir) {
|
|
50
|
+
const reg = /[/\\]/g;
|
|
51
|
+
return filepath.replace(baseDir + path.sep, '').replace(reg, '/');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 字节码类
|
|
56
|
+
*/
|
|
57
|
+
function isBytecodeClass(exports) {
|
|
58
|
+
let isClass = false;
|
|
59
|
+
|
|
60
|
+
// 标识
|
|
61
|
+
if (exports.toString().indexOf('[class') != -1) {
|
|
62
|
+
isClass = true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return isClass;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 文件类型
|
|
70
|
+
*/
|
|
71
|
+
function filePatterns() {
|
|
72
|
+
const files = [ '**/*.js','**/*.jsc' ];
|
|
73
|
+
return files;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = {
|
|
77
|
+
extensions,
|
|
78
|
+
loadFile,
|
|
79
|
+
callFn,
|
|
80
|
+
getResolvedFilename,
|
|
81
|
+
isBytecodeClass,
|
|
82
|
+
filePatterns,
|
|
83
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare class Timing {
|
|
2
|
+
_enable: boolean;
|
|
3
|
+
init(): void;
|
|
4
|
+
start(name: any, start: any): {
|
|
5
|
+
name: any;
|
|
6
|
+
start: any;
|
|
7
|
+
end: any;
|
|
8
|
+
duration: any;
|
|
9
|
+
pid: number;
|
|
10
|
+
index: number;
|
|
11
|
+
};
|
|
12
|
+
end(name: any): any;
|
|
13
|
+
enable(): void;
|
|
14
|
+
disable(): void;
|
|
15
|
+
clear(): void;
|
|
16
|
+
toJSON(): any[];
|
|
17
|
+
[MAP]: Map<any, any>;
|
|
18
|
+
[LIST]: any[];
|
|
19
|
+
}
|
|
20
|
+
declare const MAP: unique symbol;
|
|
21
|
+
declare const LIST: unique symbol;
|
|
22
|
+
export {};
|