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,28 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
-
5
- module.exports = {
6
-
7
- /**
8
- * Load app/service
9
- * @function EeLoader#loadService
10
- * @param {Object} opt - LoaderOptions
11
- * @since 1.0.0
12
- */
13
- loadService(opt) {
14
- this.timing.start('Load Service');
15
- // 载入到 app.serviceClasses
16
- opt = Object.assign({
17
- call: true,
18
- caseStyle: 'lower',
19
- fieldClass: 'serviceClasses',
20
- directory: this.getLoadUnits().map(unit => path.join(unit.path, 'service')), // this.getLoadUnits().map(unit => path.join(unit.path, 'app/service'))
21
- }, opt);
22
-
23
- const servicePaths = opt.directory;
24
- this.loadToContext(servicePaths, 'service', opt);
25
- this.timing.end('Load Service');
26
- },
27
-
28
- };
@@ -1,34 +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
- * {@link Helper}, {@link Service} is extending it.
7
- */
8
- class BaseContextClass {
9
-
10
- /**
11
- * @class
12
- * @param {Context} ctx - context instance
13
- * @since 1.0.0
14
- */
15
- constructor(ctx) {
16
- /**
17
- * @member {Application} BaseContextClass#app
18
- * @since 1.0.0
19
- */
20
- this.app = ctx;
21
- /**
22
- * @member {Config} BaseContextClass#config
23
- * @since 1.0.0
24
- */
25
- this.config = ctx.config;
26
- /**
27
- * @member {Service} BaseContextClass#service
28
- * @since 1.0.0
29
- */
30
- this.service = ctx.service;
31
- }
32
- }
33
-
34
- module.exports = BaseContextClass;
@@ -1,30 +0,0 @@
1
- const assert = require('assert');
2
-
3
- /**
4
- * A empty function.
5
- *
6
- * @return {Function}
7
- * @public
8
- */
9
- exports.noop = function noop() {};
10
-
11
- /**
12
- * Get a function parameter's names.
13
- *
14
- * @param {Function} func
15
- * @param {Boolean} [useCache], default is true
16
- * @return {Array} names
17
- */
18
- exports.getParamNames = function getParamNames(func, cache) {
19
- var type = typeof func;
20
- assert(type === 'function', 'The "func" must be a function. Received type "' + type + '"');
21
-
22
- cache = cache !== false;
23
- if (cache && func.__cache_names) {
24
- return func.__cache_names;
25
- }
26
- var str = func.toString();
27
- var names = str.slice(str.indexOf('(') + 1, str.indexOf(')')).match(/([^\s,]+)/g) || [];
28
- func.__cache_names = names;
29
- return names;
30
- };
@@ -1,133 +0,0 @@
1
- 'use strict';
2
-
3
- require('bytenode');
4
- const convert = require('koa-convert');
5
- const is = require('is-type-of');
6
- const path = require('path');
7
- const fs = require('fs');
8
- const co = require('../../../utils/co');
9
- const BuiltinModule = require('module');
10
-
11
- // Guard against poorly mocked module constructors.
12
- const Module = module.constructor.length > 1
13
- ? module.constructor
14
- /* istanbul ignore next */
15
- : BuiltinModule;
16
-
17
- // Module._extensions:
18
- // '.js': [Function (anonymous)],
19
- // '.json': [Function (anonymous)],
20
- // '.node': [Function: func],
21
- // '.jsc': [Function (anonymous)]
22
-
23
- module.exports = {
24
- extensions: Module._extensions,
25
-
26
- loadFile(filepath) {
27
- try {
28
- // if not js module, just return content buffer
29
- const extname = path.extname(filepath);
30
- if (extname && !Module._extensions[extname]) {
31
- return fs.readFileSync(filepath);
32
- }
33
-
34
- // require js module
35
- const obj = require(filepath);
36
- if (!obj) return obj;
37
- // it's es module
38
- if (obj.__esModule) return 'default' in obj ? obj.default : obj;
39
- return obj;
40
- } catch (err) {
41
- err.message = `[ee-core] load file: ${filepath}, error: ${err.message}`;
42
- throw err;
43
- }
44
- },
45
-
46
- methods: [ 'head', 'options', 'get', 'put', 'patch', 'post', 'delete' ],
47
-
48
- async callFn(fn, args, ctx) {
49
- args = args || [];
50
- if (!is.function(fn)) return;
51
- if (is.generatorFunction(fn)) fn = co.wrap(fn);
52
- return ctx ? fn.call(ctx, ...args) : fn(...args);
53
- },
54
-
55
- middleware(fn) {
56
- return is.generatorFunction(fn) ? convert(fn) : fn;
57
- },
58
-
59
- getCalleeFromStack(withLine, stackIndex) {
60
- stackIndex = stackIndex === undefined ? 2 : stackIndex;
61
- const limit = Error.stackTraceLimit;
62
- const prep = Error.prepareStackTrace;
63
-
64
- Error.prepareStackTrace = prepareObjectStackTrace;
65
- Error.stackTraceLimit = 5;
66
-
67
- // capture the stack
68
- const obj = {};
69
- Error.captureStackTrace(obj);
70
- let callSite = obj.stack[stackIndex];
71
- let fileName;
72
- /* istanbul ignore else */
73
- if (callSite) {
74
- fileName = callSite.getFileName();
75
- /* istanbul ignore if */
76
- if (fileName && fileName.endsWith('egg-mock/lib/app.js')) {
77
- // TODO: add test
78
- callSite = obj.stack[stackIndex + 1];
79
- fileName = callSite.getFileName();
80
- }
81
- }
82
-
83
- Error.prepareStackTrace = prep;
84
- Error.stackTraceLimit = limit;
85
-
86
- /* istanbul ignore if */
87
- if (!callSite || !fileName) return '<anonymous>';
88
- if (!withLine) return fileName;
89
- return `${fileName}:${callSite.getLineNumber()}:${callSite.getColumnNumber()}`;
90
- },
91
-
92
- getResolvedFilename(filepath, baseDir) {
93
- const reg = /[/\\]/g;
94
- return filepath.replace(baseDir + path.sep, '').replace(reg, '/');
95
- },
96
-
97
- /**
98
- * 字节码类
99
- */
100
- isBytecodeClass (exports) {
101
- let isClass = false;
102
-
103
- // 标识
104
- if (exports.toString().indexOf('[class') != -1) {
105
- isClass = true;
106
- }
107
- // TODO 更严谨的判断,应该加上文件名和路径
108
-
109
- return isClass;
110
- },
111
-
112
- /**
113
- * 文件类型
114
- */
115
- filePatterns () {
116
- const files = (process.env.EE_TYPESCRIPT === 'true' && Module._extensions['.ts'])
117
- ? [ '**/*.(js|ts)', '!**/*.d.ts' ]
118
- : [ '**/*.js','**/*.jsc' ];
119
-
120
- return files;
121
- }
122
-
123
- };
124
-
125
-
126
- /**
127
- * Capture call site stack from v8.
128
- * https://github.com/v8/v8/wiki/Stack-Trace-API
129
- */
130
-
131
- function prepareObjectStackTrace(obj, stack) {
132
- return stack;
133
- }
@@ -1,59 +0,0 @@
1
- 'use strict';
2
-
3
- const debug = require('debug')('ee-core#sequencify');
4
-
5
- function sequence(tasks, names, results, missing, recursive, nest, optional, parent) {
6
- names.forEach(function(name) {
7
- if (results.requires[name]) return;
8
-
9
- const node = tasks[name];
10
-
11
- if (!node) {
12
- if (optional === true) return;
13
- missing.push(name);
14
- } else if (nest.includes(name)) {
15
- nest.push(name);
16
- recursive.push(nest.slice(0));
17
- nest.pop(name);
18
- } else if (node.dependencies.length || node.optionalDependencies.length) {
19
- nest.push(name);
20
- if (node.dependencies.length) {
21
- sequence(tasks, node.dependencies, results, missing, recursive, nest, optional, name);
22
- }
23
- if (node.optionalDependencies.length) {
24
- sequence(tasks, node.optionalDependencies, results, missing, recursive, nest, true, name);
25
- }
26
- nest.pop(name);
27
- }
28
- if (!optional) {
29
- results.requires[name] = true;
30
- debug('task: %s is enabled by %s', name, parent);
31
- }
32
- if (!results.sequence.includes(name)) {
33
- results.sequence.push(name);
34
- }
35
- });
36
- }
37
-
38
- // tasks: object with keys as task names
39
- // names: array of task names
40
- module.exports = function(tasks, names) {
41
- const results = {
42
- sequence: [],
43
- requires: {},
44
- }; // the final sequence
45
- const missing = []; // missing tasks
46
- const recursive = []; // recursive task dependencies
47
-
48
- sequence(tasks, names, results, missing, recursive, [], false, 'app');
49
-
50
- if (missing.length || recursive.length) {
51
- results.sequence = []; // results are incomplete at best, completely wrong at worst, remove them to avoid confusion
52
- }
53
-
54
- return {
55
- sequence: results.sequence.filter(item => results.requires[item]),
56
- missingTasks: missing,
57
- recursiveDependencies: recursive,
58
- };
59
- };
package/ee/appLoader.js DELETED
@@ -1,48 +0,0 @@
1
- const EeLoader = require('../core/index').EeLoader;
2
-
3
- /**
4
- * App Loader
5
- * @see
6
- */
7
- class AppLoader extends EeLoader {
8
-
9
- /**
10
- * loadPlugin first, then loadConfig
11
- * @since 1.0.0
12
- */
13
- loadConfig() {
14
- super.loadConfig();
15
- }
16
-
17
- /**
18
- * Load all directories in convention
19
- * @since 1.0.0
20
- */
21
- load() {
22
-
23
- // app > plugin
24
- this.loadService();
25
-
26
- // app
27
- this.loadController();
28
-
29
- }
30
-
31
- /**
32
- * load addons
33
- * @since 1.0.0
34
- */
35
- loadAddons() {
36
- this.loadAddon();
37
- }
38
-
39
- /**
40
- * load electron modules
41
- * @since 1.0.0
42
- */
43
- loadElectron() {
44
-
45
- }
46
- }
47
-
48
- module.exports = AppLoader;
package/ee/application.js DELETED
@@ -1,101 +0,0 @@
1
- const Exception = require('../exception');
2
- const { app } = require('electron');
3
- const path = require('path');
4
- const debug = require('debug')('ee-core:Appliaction');
5
- const EeApp = require('./eeApp');
6
- const Utils = require('../utils');
7
- const Ps = require('../ps');
8
- const EE = require('./index');
9
-
10
- class Appliaction extends EeApp {
11
- constructor() {
12
- Exception.start();
13
- const { env } = process;
14
-
15
- // initialize mode
16
- Ps.initMode();
17
-
18
- let options = {
19
- env: 'prod',
20
- serverScope: '',
21
- type: 'application',
22
- baseDir: path.join(app.getAppPath(), 'electron'),
23
- homeDir: app.getAppPath(),
24
- framework: path.join(app.getAppPath(), 'node_modules', 'ee-core'),
25
- appName: app.getName(),
26
- userHome: app.getPath('home'),
27
- appData: app.getPath('appData'),
28
- appUserData: app.getPath('userData'),
29
- appVersion: app.getVersion(),
30
- isPackaged: app.isPackaged,
31
- execDir: app.getAppPath(),
32
- isEncrypted: false
33
- }
34
-
35
- // argv
36
- let hotReload = false;
37
- for (let i = 0; i < process.argv.length; i++) {
38
- const tmpArgv = process.argv[i]
39
- if (tmpArgv.indexOf('--env=') !== -1) {
40
- options.env = tmpArgv.substring(6);
41
- }
42
- if (tmpArgv.indexOf('--hot-reload=') !== -1) {
43
- hotReload = tmpArgv.substring(13) == 1 ? true : false;
44
- }
45
- }
46
-
47
- // exec directory (exe dmg dep) for prod
48
- if (options.env == 'prod' && app.isPackaged) {
49
- options.execDir = path.dirname(app.getPath('exe'));
50
- }
51
-
52
- // Todo app.getAppPath() ??? process.cwd()
53
- // Use encryption, base directory is public/electron
54
- if (options.env == 'prod' && Utils.isEncrypt(app.getAppPath())) {
55
- options.baseDir = Ps.getEncryptDir(app.getAppPath());
56
- options.isEncrypted = true;
57
- }
58
-
59
- // normalize env
60
- env.EE_APP_NAME = options.appName;
61
- env.EE_APP_VERSION = options.appVersion;
62
- env.EE_HOME = options.homeDir;
63
- env.EE_BASE_DIR = options.baseDir;
64
- env.EE_SERVER_ENV = options.env;
65
- env.EE_SERVER_SCOPE = options.serverScope;
66
- env.EE_USER_HOME = options.userHome;
67
- env.EE_APP_DATA = options.appData;
68
- env.EE_APP_USER_DATA = options.appUserData;
69
- env.HOT_RELOAD = hotReload;
70
- env.EE_EXEC_DIR = options.execDir;
71
- env.EE_IS_PACKAGED = options.isPackaged;
72
- env.EE_IS_ENCRYPTED = options.isEncrypted;
73
- env.EE_DATABASE_DIR = null;
74
- env.EE_MAIN_PORT = null;
75
- env.EE_SOCKET_PORT = null;
76
- env.EE_HTTP_PORT = null;
77
- debug('options:%j', options)
78
-
79
- super(options);
80
-
81
- // 设置全局this
82
- EE.CoreApp = this;
83
-
84
- this.initialize();
85
- }
86
-
87
- async initialize () {
88
-
89
- await this.createPorts();
90
-
91
- await this.startSocket();
92
-
93
- await this.ready();
94
-
95
- await this.createElectronApp();
96
-
97
- await this.InitModuleMode();
98
- }
99
- }
100
-
101
- module.exports = Appliaction;
package/ee/baseApp.js DELETED
@@ -1,99 +0,0 @@
1
- const EeAppCore = require('../core/index').EeCore;
2
- const EE_PATH = Symbol.for('ee#eePath');
3
- const path = require('path');
4
- const EE_LOADER = Symbol.for('ee#loader');
5
- const AppLoader = require('./appLoader');
6
- const HttpClient = require('../httpclient');
7
- const HTTPCLIENT = Symbol('EeApplication#httpclient');
8
- const LOGGERS = Symbol('EeApplication#loggers');
9
- const Log = require('../log');
10
-
11
- class BaseApp extends EeAppCore {
12
- constructor (options = {}) {
13
-
14
- super(options);
15
-
16
- this.loader.loadConfig();
17
-
18
- this.loader.load();
19
-
20
- this.HttpClient = HttpClient;
21
- }
22
-
23
- get [EE_PATH]() {
24
- return path.join(__dirname, '..');
25
- }
26
-
27
- get [EE_LOADER]() {
28
- return AppLoader;
29
- }
30
-
31
- /**
32
- * loggers
33
- * @member {Object}
34
- * @since 1.0.0
35
- */
36
- get loggers() {
37
- if (!this[LOGGERS]) {
38
- this[LOGGERS] = Log.create(this.config);
39
- }
40
- return this[LOGGERS];
41
- }
42
-
43
- /**
44
- * Get logger by name, it's equal to app.loggers['name'],
45
- * but you can extend it with your own logical.
46
- * @param {String} name - logger name
47
- * @return {Logger} logger
48
- */
49
- getLogger(name) {
50
- return this.loggers[name] || null;
51
- }
52
-
53
- /**
54
- * application logger, log file is `$HOME/logs/ee.log`
55
- * @member {Logger}
56
- * @since 1.0.0
57
- */
58
- get logger() {
59
- return this.getLogger('logger');
60
- }
61
-
62
- /**
63
- * core logger for framework and plugins, log file is `$HOME/logs/ee-core.log`
64
- * @member {Logger}
65
- * @since 1.0.0
66
- */
67
- get coreLogger() {
68
- return this.getLogger('coreLogger');
69
- }
70
-
71
- /**
72
- * @class curl
73
- * @since 1.0.0
74
- */
75
- curl(url, opts) {
76
- return this.httpclient.request(url, opts);
77
- }
78
-
79
- /**
80
- * HttpClient instance
81
- * @see https://github.com/node-modules/urllib
82
- * @member {HttpClient}
83
- */
84
- get httpclient() {
85
- if (!this[HTTPCLIENT]) {
86
- this[HTTPCLIENT] = new this.HttpClient(this.config.httpclient);
87
- }
88
- return this[HTTPCLIENT];
89
- }
90
-
91
- /**
92
- * core app have been loaded
93
- */
94
- async ready () {
95
- // do some things
96
- }
97
- }
98
-
99
- module.exports = BaseApp;