oox 0.3.0-beta8 → 0.3.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 (45) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +29 -32
  3. package/app.js +131 -131
  4. package/bin/argv.js +63 -70
  5. package/bin/cli.js +57 -43
  6. package/bin/configurer.js +60 -62
  7. package/bin/loader.mjs +392 -279
  8. package/bin/proxy-import.js +12 -0
  9. package/bin/proxy-require.js +88 -0
  10. package/bin/register.js +46 -55
  11. package/bin/starter.js +63 -64
  12. package/index.js +155 -168
  13. package/index.mjs +4 -4
  14. package/logger.js +25 -40
  15. package/modules/http/index.js +234 -186
  16. package/modules/http/utils.js +74 -73
  17. package/modules/index.js +86 -88
  18. package/modules/module.js +11 -16
  19. package/modules/socketio/client.js +97 -101
  20. package/modules/socketio/index.js +171 -168
  21. package/modules/socketio/server.js +188 -136
  22. package/modules/socketio/socket.js +1 -4
  23. package/package.json +14 -12
  24. package/types/app.d.ts +50 -40
  25. package/types/bin/argv.d.ts +8 -8
  26. package/types/bin/cli.d.ts +6 -2
  27. package/types/bin/configurer.d.ts +3 -1
  28. package/types/bin/proxy-import.d.ts +4 -0
  29. package/types/bin/proxy-require.d.ts +5 -0
  30. package/types/bin/register.d.ts +1 -1
  31. package/types/bin/starter.d.ts +5 -1
  32. package/types/index.d.ts +78 -76
  33. package/types/logger.d.ts +5 -4
  34. package/types/modules/http/index.d.ts +58 -47
  35. package/types/modules/http/utils.d.ts +14 -17
  36. package/types/modules/index.d.ts +24 -24
  37. package/types/modules/module.d.ts +11 -13
  38. package/types/modules/socketio/client.d.ts +23 -23
  39. package/types/modules/socketio/index.d.ts +37 -37
  40. package/types/modules/socketio/server.d.ts +44 -35
  41. package/types/modules/socketio/socket.d.ts +11 -11
  42. package/types/utils.d.ts +6 -6
  43. package/utils.js +57 -63
  44. package/bin/proxyer.js +0 -61
  45. package/types/bin/proxyer.d.ts +0 -1
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 lipingruan
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2020 lipingruan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,32 +1,29 @@
1
- ![oox-logo-dark](https://user-images.githubusercontent.com/16621637/146079784-d4d5805f-903d-44bd-998e-ff374b91ccb4.png#gh-light-mode-only)
2
-
3
- ![oox-logo-light](https://user-images.githubusercontent.com/16621637/146079978-29a0b6fc-ec6d-4d8f-9b80-9a089f716405.png#gh-dark-mode-only)
4
-
5
- graceful microservice framework.
6
-
7
- ### Features
8
- - [x] HTTP & socket.io support (native SSL coming soon)
9
- - [x] Zero configure startup
10
- - [x] Non-invasive coding style
11
- - [x] Intuitive route style
12
- - [x] Intuitive RPC style
13
- - [x] Anywhere interceptor
14
- - [x] Distributed tracing
15
- - [x] Service nodes expand infinitely
16
- - [x] Automatic service discovery (P2P)
17
- - [x] Automatic load balancing (support customization)
18
- - [x] `Distributed / Standalone` seamless handoff
19
- - [x] Highly customizable
20
-
21
- ### Installation
22
- ```bash
23
- npm install -g oox
24
- ```
25
-
26
- ### Usage
27
- ```bash
28
- oox --help
29
- ```
30
-
31
- ### Documentation
32
- [oox.js.org](https://oox.js.org/)
1
+ ![oox-logo-dark](https://user-images.githubusercontent.com/16621637/146079784-d4d5805f-903d-44bd-998e-ff374b91ccb4.png#gh-light-mode-only)
2
+
3
+ ![oox-logo-light](https://user-images.githubusercontent.com/16621637/146079978-29a0b6fc-ec6d-4d8f-9b80-9a089f716405.png#gh-dark-mode-only)
4
+
5
+ graceful microservice framework.
6
+
7
+ ### Features
8
+ - [x] HTTP & socket.io support (native SSL supported)
9
+ - [x] Zero configure startup
10
+ - [x] Non-invasive coding style
11
+ - [x] Intuitive route style
12
+ - [x] Intuitive RPC style
13
+ - [x] Anywhere interceptor
14
+ - [x] Distributed tracing
15
+ - [x] Service nodes expand infinitely
16
+ - [x] Automatic service discovery (P2P)
17
+ - [x] Automatic load balancing (support customization)
18
+ - [x] `Distributed / Standalone` seamless handoff
19
+ - [x] Highly customizable
20
+
21
+ ### Installation
22
+ ```bash
23
+ npm install oox
24
+ ```
25
+
26
+ ### Usage
27
+ ```bash
28
+ npx oox --help
29
+ ```
package/app.js CHANGED
@@ -1,131 +1,131 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.execute = exports.call = exports.on = exports.getMethods = exports.setMethods = exports.sourceKVMethods = exports.kvMethods = exports.eventHub = exports.asyncStore = exports.Context = exports.logger = void 0;
4
- const node_events_1 = require("node:events");
5
- const node_async_hooks_1 = require("node:async_hooks");
6
- const utils_1 = require("./utils");
7
- exports.logger = require("./logger");
8
- class Context {
9
- // 请求溯源ID
10
- traceId = '';
11
- }
12
- exports.Context = Context;
13
- exports.asyncStore = new node_async_hooks_1.AsyncLocalStorage();
14
- exports.eventHub = new node_events_1.EventEmitter();
15
- /**
16
- * sourceMethods => methods
17
- */
18
- let sourceMethods = {};
19
- /**
20
- * the kvMethods is all actions refs [has bind this]
21
- */
22
- exports.kvMethods = new Map();
23
- exports.sourceKVMethods = new Map();
24
- function setMethods(methods) {
25
- sourceMethods = methods;
26
- exports.kvMethods.clear();
27
- exports.sourceKVMethods.clear();
28
- (0, utils_1.genKVMethods)(methods, exports.kvMethods, exports.sourceKVMethods);
29
- }
30
- exports.setMethods = setMethods;
31
- function getMethods() {
32
- return sourceMethods;
33
- }
34
- exports.getMethods = getMethods;
35
- function on(event, listener) {
36
- return exports.eventHub.on(event, listener);
37
- }
38
- exports.on = on;
39
- /**
40
- * Call an Function on RPC server
41
- * @param action
42
- * @param params
43
- * @param context
44
- * @returns
45
- */
46
- async function call(action, params = [], context) {
47
- if (!Array.isArray(params))
48
- params = [params];
49
- const { traceId } = context;
50
- exports.eventHub.emit('request', action, params, context);
51
- const returns = {
52
- traceId,
53
- success: false
54
- };
55
- try {
56
- const result = await execute(action, [...params], context);
57
- returns.body = result;
58
- returns.success = true;
59
- exports.eventHub.emit('success', action, params, context, result);
60
- }
61
- catch (error) {
62
- returns.error = {
63
- message: error.message,
64
- stack: error.stack
65
- };
66
- exports.eventHub.emit('fail', action, params, context, error);
67
- }
68
- finally {
69
- return returns;
70
- }
71
- }
72
- exports.call = call;
73
- async function execute(action, params, context) {
74
- const __proxy = '__proxy', _proxy = '_proxy';
75
- if (__proxy === action || _proxy === action || action.endsWith(_proxy))
76
- throw new Error('Invalid Action[' + action + ']');
77
- const methods = exports.kvMethods;
78
- // 目标函数
79
- const target = methods.get(action);
80
- // 目标代理函数
81
- const targetProxy = methods.get(action + _proxy);
82
- // 即不存在目标也不存在目标代理时, 报错函数不存在
83
- if (!target && !targetProxy)
84
- throw new Error('Unknown Action [' + action + ']');
85
- exports.asyncStore.enterWith(context);
86
- // ============================ PROXY BEGIN ============================
87
- // 最顶层代理
88
- const topProxy = methods.get(__proxy);
89
- if (topProxy) {
90
- const proxyReturns = await topProxy(action, params, context);
91
- if (proxyReturns !== undefined)
92
- return proxyReturns;
93
- }
94
- // 'x.y.z' => [ 'x', 'y', 'z' ]
95
- const nameStack = action.split('.'), size = nameStack.length - 1;
96
- let index = -1, proxyPrefix = '';
97
- // 根代理遍历
98
- while (++index < size) {
99
- // x.
100
- // x.y.
101
- proxyPrefix += nameStack[index] + '.';
102
- // x.__proxy
103
- // x.y.__proxy
104
- const rootProxy = methods.get(proxyPrefix + __proxy);
105
- // x.__proxy ( 'y.z', ... )
106
- // x.y.__proxy ( 'z', ... )
107
- if (rootProxy) {
108
- const proxyReturns = await rootProxy(nameStack.slice(index).join('.'), params, context);
109
- if (proxyReturns !== undefined)
110
- return proxyReturns;
111
- }
112
- }
113
- // 同级代理
114
- const layerProxy = methods.get(proxyPrefix + _proxy);
115
- if (layerProxy) {
116
- const proxyReturns = await layerProxy(nameStack[index], params, context);
117
- if (proxyReturns !== undefined)
118
- return proxyReturns;
119
- }
120
- if (targetProxy) {
121
- const proxyReturns = await targetProxy(params, context);
122
- if (proxyReturns !== undefined)
123
- return proxyReturns;
124
- }
125
- // ============================= PROXY END =============================
126
- // make sure target action execute after all proxies
127
- if (target) {
128
- return await target(...params);
129
- }
130
- }
131
- exports.execute = execute;
1
+ import { EventEmitter } from 'node:events';
2
+ import { AsyncLocalStorage } from 'node:async_hooks';
3
+ import { genKVMethods } from './utils.js';
4
+ export * as logger from './logger.js';
5
+ export class Context {
6
+ // 请求溯源ID
7
+ traceId = '';
8
+ }
9
+ export const asyncStore = new AsyncLocalStorage();
10
+ export const eventHub = new EventEmitter();
11
+ /**
12
+ * sourceMethods => methods
13
+ */
14
+ let sourceMethods = {};
15
+ /**
16
+ * the kvMethods is all actions refs [has bind this]
17
+ */
18
+ export const kvMethods = new Map();
19
+ export const sourceKVMethods = new Map();
20
+ export function setMethods(methods) {
21
+ sourceMethods = methods;
22
+ kvMethods.clear();
23
+ sourceKVMethods.clear();
24
+ genKVMethods(methods, kvMethods, sourceKVMethods);
25
+ }
26
+ export function getMethods() {
27
+ return sourceMethods;
28
+ }
29
+ export function on(event, listener) {
30
+ eventHub.on(event, listener);
31
+ }
32
+ export function once(event, listener) {
33
+ eventHub.once(event, listener);
34
+ }
35
+ export function off(event, listener) {
36
+ eventHub.off(event, listener);
37
+ }
38
+ export function emit(event, ...args) {
39
+ return eventHub.emit(event, ...args);
40
+ }
41
+ /**
42
+ * Call an Function on RPC server
43
+ * @param action
44
+ * @param params
45
+ * @param context
46
+ * @returns
47
+ */
48
+ export async function call(action, params = [], context) {
49
+ asyncStore.enterWith(context);
50
+ if (!Array.isArray(params))
51
+ params = [params];
52
+ const { traceId } = context;
53
+ emit('call:start', Date.now(), action, params, context);
54
+ const returns = {
55
+ traceId,
56
+ success: true
57
+ };
58
+ try {
59
+ const result = await execute(action, [...params], context);
60
+ returns.body = result;
61
+ emit('call:success', Date.now(), action, params, context, result);
62
+ }
63
+ catch (error) {
64
+ returns.success = false;
65
+ returns.error = {
66
+ message: error.message,
67
+ stack: error.stack
68
+ };
69
+ emit('call:fail', Date.now(), action, params, context, error);
70
+ }
71
+ finally {
72
+ return returns;
73
+ }
74
+ }
75
+ export async function execute(action, params, context) {
76
+ const __proxy = '__proxy', _proxy = '_proxy';
77
+ if (__proxy === action || _proxy === action || action.endsWith(_proxy))
78
+ throw new Error('Invalid Action[' + action + ']');
79
+ const methods = kvMethods;
80
+ // 目标函数
81
+ const target = methods.get(action);
82
+ // 目标代理函数
83
+ const targetProxy = methods.get(action + _proxy);
84
+ // 即不存在目标也不存在目标代理时, 报错函数不存在
85
+ if (!target && !targetProxy)
86
+ throw new Error('Unknown Action [' + action + ']');
87
+ // ============================ PROXY BEGIN ============================
88
+ // 最顶层代理
89
+ const topProxy = methods.get(__proxy);
90
+ if (topProxy) {
91
+ const proxyReturns = await topProxy(action, params, context);
92
+ if (proxyReturns !== undefined)
93
+ return proxyReturns;
94
+ }
95
+ // 'x.y.z' => [ 'x', 'y', 'z' ]
96
+ const nameStack = action.split('.'), size = nameStack.length - 1;
97
+ let index = -1, proxyPrefix = '';
98
+ // 根代理遍历
99
+ while (++index < size) {
100
+ // x.
101
+ // x.y.
102
+ proxyPrefix += nameStack[index] + '.';
103
+ // x.__proxy
104
+ // x.y.__proxy
105
+ const rootProxy = methods.get(proxyPrefix + __proxy);
106
+ // x.__proxy ( 'y.z', ... )
107
+ // x.y.__proxy ( 'z', ... )
108
+ if (rootProxy) {
109
+ const proxyReturns = await rootProxy(nameStack.slice(index).join('.'), params, context);
110
+ if (proxyReturns !== undefined)
111
+ return proxyReturns;
112
+ }
113
+ }
114
+ // 同级代理
115
+ const layerProxy = methods.get(proxyPrefix + _proxy);
116
+ if (layerProxy) {
117
+ const proxyReturns = await layerProxy(nameStack[index], params, context);
118
+ if (proxyReturns !== undefined)
119
+ return proxyReturns;
120
+ }
121
+ if (targetProxy) {
122
+ const proxyReturns = await targetProxy(params, context);
123
+ if (proxyReturns !== undefined)
124
+ return proxyReturns;
125
+ }
126
+ // ============================= PROXY END =============================
127
+ // make sure target action execute after all proxies
128
+ if (target) {
129
+ return await target(...params);
130
+ }
131
+ }
package/bin/argv.js CHANGED
@@ -1,70 +1,63 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseEnvArg = exports.getEnvArg = exports.getEnvArgs = exports.getAllEnvArgs = void 0;
4
- function getAllEnvArgs() {
5
- const args = process.argv.slice(2);
6
- const env = {};
7
- for (const arg of args) {
8
- if (arg.startsWith('--')) {
9
- env[arg.slice(2)] = true;
10
- }
11
- else if (arg.startsWith('-')) {
12
- env[arg.slice(1)] = true;
13
- }
14
- else if (!arg.includes('=')) {
15
- env[arg] = true;
16
- }
17
- else {
18
- const index = arg.indexOf('=');
19
- const key = arg.slice(0, index);
20
- const val = arg.slice(index + 1);
21
- env[key] = parseEnvArg(val);
22
- }
23
- }
24
- return env;
25
- }
26
- exports.getAllEnvArgs = getAllEnvArgs;
27
- function getEnvArgs(names) {
28
- const env = {};
29
- for (let name of names) {
30
- env[name] = getEnvArg(name);
31
- }
32
- return env;
33
- }
34
- exports.getEnvArgs = getEnvArgs;
35
- // 从命令行参数列表中获取参数值
36
- function getEnvArg(name) {
37
- if (process.argv.includes(name) ||
38
- process.argv.includes('-' + name) ||
39
- process.argv.includes('--' + name)) {
40
- return true;
41
- }
42
- else {
43
- const prefix = name + '=';
44
- const [argv] = process.argv.filter(arg => arg.startsWith(prefix));
45
- if (!argv)
46
- return null;
47
- const arg = argv.slice(prefix.length);
48
- return parseEnvArg(arg);
49
- }
50
- }
51
- exports.getEnvArg = getEnvArg;
52
- function parseEnvArg(value) {
53
- switch (value) {
54
- case 'no': return false;
55
- case 'yes': return true;
56
- case 'none':
57
- case 'NULL':
58
- case 'nil': return null;
59
- default:
60
- try {
61
- return JSON.parse(value);
62
- }
63
- catch (error) {
64
- if (value.includes(','))
65
- return value.split(',');
66
- return value;
67
- }
68
- }
69
- }
70
- exports.parseEnvArg = parseEnvArg;
1
+ export function getAllEnvArgs() {
2
+ const args = process.argv.slice(2);
3
+ const env = {};
4
+ for (const arg of args) {
5
+ if (arg.startsWith('--')) {
6
+ env[arg.slice(2)] = true;
7
+ }
8
+ else if (arg.startsWith('-')) {
9
+ env[arg.slice(1)] = true;
10
+ }
11
+ else if (!arg.includes('=')) {
12
+ env[arg] = true;
13
+ }
14
+ else {
15
+ const index = arg.indexOf('=');
16
+ const key = arg.slice(0, index);
17
+ const val = arg.slice(index + 1);
18
+ env[key] = parseEnvArg(val);
19
+ }
20
+ }
21
+ return env;
22
+ }
23
+ export function getEnvArgs(names) {
24
+ const env = {};
25
+ for (let name of names) {
26
+ env[name] = getEnvArg(name);
27
+ }
28
+ return env;
29
+ }
30
+ // 从命令行参数列表中获取参数值
31
+ export function getEnvArg(name) {
32
+ if (process.argv.includes(name) ||
33
+ process.argv.includes('-' + name) ||
34
+ process.argv.includes('--' + name)) {
35
+ return true;
36
+ }
37
+ else {
38
+ const prefix = name + '=';
39
+ const argv = process.argv.filter(arg => arg.startsWith(prefix)).pop();
40
+ if (!argv)
41
+ return null;
42
+ const arg = argv.slice(prefix.length);
43
+ return parseEnvArg(arg);
44
+ }
45
+ }
46
+ export function parseEnvArg(value) {
47
+ switch (value) {
48
+ case 'no': return false;
49
+ case 'yes': return true;
50
+ case 'none':
51
+ case 'NULL':
52
+ case 'nil': return null;
53
+ default:
54
+ try {
55
+ return JSON.parse(value);
56
+ }
57
+ catch (error) {
58
+ if (value.includes(','))
59
+ return value.split(',');
60
+ return value;
61
+ }
62
+ }
63
+ }
package/bin/cli.js CHANGED
@@ -1,43 +1,57 @@
1
- #! /usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const chalk_1 = require("chalk");
5
- const starter_1 = require("./starter");
6
- const pkg = require("../package.json");
7
- const args = process.argv.slice(2);
8
- const command = args[0];
9
- var isStartup = true;
10
- if (!command || ['help', '-h', '-help', '--help', 'version', '-v', '-version', '--version'].includes(command)) {
11
- isStartup = false;
12
- console.log();
13
- console.log('OOX Service');
14
- console.log((0, chalk_1.bold) `version`, chalk_1.bold.green `${pkg.version}`);
15
- console.log((0, chalk_1.underline) `${pkg.homepage}`);
16
- console.log();
17
- }
18
- if (['help', '-h', '-help', '--help'].includes(command)) {
19
- console.log((0, chalk_1.bold) `Usage:`);
20
- console.log(' oox entry.js');
21
- console.log();
22
- console.log(' oox entry.js port=8080');
23
- console.log();
24
- console.log(' oox app/entry/index.js group=app/ env=envs/entry.js ignore=core');
25
- console.log();
26
- console.log((0, chalk_1.bold) `Params:`);
27
- const params = [
28
- [' default-env [ file ] ', '.js or .json file, merge to oox.config'],
29
- [' env [ file ] ', '.js or .json file, merge to oox.config', (0, chalk_1.bold) `(after default-env)`],
30
- [' port [ int ] ', 'set', (0, chalk_1.bold) `0`, 'for random port, or any integer > 0'],
31
- [' group [ dir ] ', 'service group directory, all LocalCall transform to RPC'],
32
- [' ignore [ name ] ', 'set a name for LocalCall do not transform to RPC, support string | array<string>'],
33
- [' http [ json ] ', 'HTTP server options, support flat name, ex: http.path=/api'],
34
- [' socketio [ json ] ', 'SocketIO server options, support flat name'],
35
- [' registry [ urls ] ', 'registry service url, support string | array<string>'],
36
- [' origin [ urls ] ', 'set', (0, chalk_1.bold) `*`, 'allow any connections <Access-Control-Allow-Origin>'],
37
- [' ... ', 'set params as', (0, chalk_1.bold) `foo=bar` + ',', 'usage as', (0, chalk_1.bold) `oox.config.foo`]
38
- ];
39
- params.forEach(row => console.log(...row, '\n'));
40
- console.log();
41
- }
42
- if (isStartup)
43
- (0, starter_1.startup)();
1
+ #! /usr/bin/env node
2
+ import chalk from 'chalk';
3
+ import { fileURLToPath } from 'node:url';
4
+ import * as oox from '../index.js';
5
+ import { configure, startup } from './starter.js';
6
+ import { inGroupConvertRequireToRPC } from './proxy-require.js';
7
+ import { registModuleLoader } from './proxy-import.js';
8
+ import pkg from '../package.json' with { type: 'json' };
9
+ export const version = pkg.version;
10
+ export { configure, startup, inGroupConvertRequireToRPC, registModuleLoader, };
11
+ const execFilename = process.argv[1];
12
+ if (execFilename.endsWith('oox') || fileURLToPath(import.meta.url) === execFilename) {
13
+ const args = process.argv.slice(2);
14
+ const command = args[0];
15
+ var isStartup = true;
16
+ if (!command || ['help', '-h', '-help', '--help', 'version', '-v', '-version', '--version'].includes(command)) {
17
+ isStartup = false;
18
+ console.log();
19
+ console.log('OOX Service Engine');
20
+ console.log(chalk.bold('version'), chalk.bold.green(`${pkg.version}`));
21
+ console.log(chalk.underline(`${pkg.homepage}`));
22
+ console.log();
23
+ }
24
+ if (['help', '-h', '-help', '--help'].includes(command)) {
25
+ console.log(chalk.bold('Usage:'));
26
+ console.log(' oox entry.js');
27
+ console.log();
28
+ console.log(' oox entry.js port=8080');
29
+ console.log();
30
+ console.log(' oox app/entry/index.js group=app/ env=envs/entry.js ignore=core');
31
+ console.log();
32
+ console.log(chalk.bold('Params:'));
33
+ const params = [
34
+ [' default-env [ file ] ', '.js or .json file, merge to oox.config'],
35
+ [' env [ file ] ', '.js or .json file, merge to oox.config', chalk.bold('(after default-env)')],
36
+ [' port [ int ] ', 'set', chalk.bold('0'), 'for random port, or any integer > 0'],
37
+ [' group [ dir ] ', 'service group directory, all LocalCall transform to RPC'],
38
+ [' ignore [ name ] ', 'set a name for LocalCall do not transform to RPC, support string | array<string>'],
39
+ [' http [ json ] ', 'HTTP server options, support flat name, ex: http.path=/api'],
40
+ [' socketio [ json ] ', 'SocketIO server options, support flat name'],
41
+ [' registry [ urls ] ', 'registry service url, support string | array<string>'],
42
+ [' origin [ urls ] ', 'set', chalk.bold('*'), 'allow any connections <Access-Control-Allow-Origin>'],
43
+ [' errorStack [ bool ] ', 'set no to hidden error stack return'],
44
+ [' ... ', 'set params as', chalk.bold('foo=bar') + ',', 'usage as', chalk.bold('oox.config.foo')]
45
+ ];
46
+ params.forEach(row => console.log(...row, '\n'));
47
+ console.log();
48
+ }
49
+ if (isStartup) {
50
+ await configure();
51
+ if (oox.config.group) {
52
+ inGroupConvertRequireToRPC();
53
+ await registModuleLoader();
54
+ }
55
+ await startup();
56
+ }
57
+ }