oox 0.3.0-beta11 → 0.3.0-beta12
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/LICENSE +21 -21
- package/README.md +32 -32
- package/app.js +143 -143
- package/bin/argv.js +70 -70
- package/bin/cli.js +49 -49
- package/bin/configurer.js +64 -64
- package/bin/loader.mjs +459 -459
- package/bin/proxyer.js +66 -66
- package/bin/register.js +55 -55
- package/bin/starter.js +71 -71
- package/index.js +168 -168
- package/index.mjs +4 -4
- package/logger.js +40 -40
- package/modules/http/index.js +192 -192
- package/modules/http/utils.js +73 -73
- package/modules/index.js +88 -88
- package/modules/module.js +16 -16
- package/modules/socketio/client.js +101 -101
- package/modules/socketio/index.js +168 -168
- package/modules/socketio/server.js +136 -136
- package/modules/socketio/socket.js +4 -4
- package/package.json +1 -1
- package/types/app.d.ts +51 -51
- package/types/bin/argv.d.ts +8 -8
- package/types/bin/cli.d.ts +4 -4
- package/types/bin/configurer.d.ts +3 -3
- package/types/bin/proxyer.d.ts +1 -1
- package/types/bin/register.d.ts +1 -1
- package/types/bin/starter.d.ts +3 -3
- package/types/index.d.ts +76 -76
- package/types/logger.d.ts +4 -4
- package/types/modules/http/index.d.ts +47 -47
- package/types/modules/http/utils.d.ts +17 -17
- package/types/modules/index.d.ts +24 -24
- package/types/modules/module.d.ts +13 -13
- package/types/modules/socketio/client.d.ts +23 -23
- package/types/modules/socketio/index.d.ts +37 -37
- package/types/modules/socketio/server.d.ts +35 -35
- package/types/modules/socketio/socket.d.ts +11 -11
- package/types/utils.d.ts +6 -6
- package/utils.js +63 -63
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,32 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
|
-

|
|
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
|
+

|
|
2
|
+
|
|
3
|
+

|
|
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/)
|
package/app.js
CHANGED
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.execute = exports.call = exports.emit = exports.off = exports.once = 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
|
-
exports.eventHub.on(event, listener);
|
|
37
|
-
}
|
|
38
|
-
exports.on = on;
|
|
39
|
-
function once(event, listener) {
|
|
40
|
-
exports.eventHub.once(event, listener);
|
|
41
|
-
}
|
|
42
|
-
exports.once = once;
|
|
43
|
-
function off(event, listener) {
|
|
44
|
-
exports.eventHub.off(event, listener);
|
|
45
|
-
}
|
|
46
|
-
exports.off = off;
|
|
47
|
-
function emit(event, ...args) {
|
|
48
|
-
return exports.eventHub.emit(event, ...args);
|
|
49
|
-
}
|
|
50
|
-
exports.emit = emit;
|
|
51
|
-
/**
|
|
52
|
-
* Call an Function on RPC server
|
|
53
|
-
* @param action
|
|
54
|
-
* @param params
|
|
55
|
-
* @param context
|
|
56
|
-
* @returns
|
|
57
|
-
*/
|
|
58
|
-
async function call(action, params = [], context) {
|
|
59
|
-
if (!Array.isArray(params))
|
|
60
|
-
params = [params];
|
|
61
|
-
const { traceId } = context;
|
|
62
|
-
exports.eventHub.emit('request', action, params, context);
|
|
63
|
-
const returns = {
|
|
64
|
-
traceId,
|
|
65
|
-
success: false
|
|
66
|
-
};
|
|
67
|
-
try {
|
|
68
|
-
const result = await execute(action, [...params], context);
|
|
69
|
-
returns.body = result;
|
|
70
|
-
returns.success = true;
|
|
71
|
-
exports.eventHub.emit('success', action, params, context, result);
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
returns.error = {
|
|
75
|
-
message: error.message,
|
|
76
|
-
stack: error.stack
|
|
77
|
-
};
|
|
78
|
-
exports.eventHub.emit('fail', action, params, context, error);
|
|
79
|
-
}
|
|
80
|
-
finally {
|
|
81
|
-
return returns;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.call = call;
|
|
85
|
-
async function execute(action, params, context) {
|
|
86
|
-
const __proxy = '__proxy', _proxy = '_proxy';
|
|
87
|
-
if (__proxy === action || _proxy === action || action.endsWith(_proxy))
|
|
88
|
-
throw new Error('Invalid Action[' + action + ']');
|
|
89
|
-
const methods = exports.kvMethods;
|
|
90
|
-
// 目标函数
|
|
91
|
-
const target = methods.get(action);
|
|
92
|
-
// 目标代理函数
|
|
93
|
-
const targetProxy = methods.get(action + _proxy);
|
|
94
|
-
// 即不存在目标也不存在目标代理时, 报错函数不存在
|
|
95
|
-
if (!target && !targetProxy)
|
|
96
|
-
throw new Error('Unknown Action [' + action + ']');
|
|
97
|
-
exports.asyncStore.enterWith(context);
|
|
98
|
-
// ============================ PROXY BEGIN ============================
|
|
99
|
-
// 最顶层代理
|
|
100
|
-
const topProxy = methods.get(__proxy);
|
|
101
|
-
if (topProxy) {
|
|
102
|
-
const proxyReturns = await topProxy(action, params, context);
|
|
103
|
-
if (proxyReturns !== undefined)
|
|
104
|
-
return proxyReturns;
|
|
105
|
-
}
|
|
106
|
-
// 'x.y.z' => [ 'x', 'y', 'z' ]
|
|
107
|
-
const nameStack = action.split('.'), size = nameStack.length - 1;
|
|
108
|
-
let index = -1, proxyPrefix = '';
|
|
109
|
-
// 根代理遍历
|
|
110
|
-
while (++index < size) {
|
|
111
|
-
// x.
|
|
112
|
-
// x.y.
|
|
113
|
-
proxyPrefix += nameStack[index] + '.';
|
|
114
|
-
// x.__proxy
|
|
115
|
-
// x.y.__proxy
|
|
116
|
-
const rootProxy = methods.get(proxyPrefix + __proxy);
|
|
117
|
-
// x.__proxy ( 'y.z', ... )
|
|
118
|
-
// x.y.__proxy ( 'z', ... )
|
|
119
|
-
if (rootProxy) {
|
|
120
|
-
const proxyReturns = await rootProxy(nameStack.slice(index).join('.'), params, context);
|
|
121
|
-
if (proxyReturns !== undefined)
|
|
122
|
-
return proxyReturns;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
// 同级代理
|
|
126
|
-
const layerProxy = methods.get(proxyPrefix + _proxy);
|
|
127
|
-
if (layerProxy) {
|
|
128
|
-
const proxyReturns = await layerProxy(nameStack[index], params, context);
|
|
129
|
-
if (proxyReturns !== undefined)
|
|
130
|
-
return proxyReturns;
|
|
131
|
-
}
|
|
132
|
-
if (targetProxy) {
|
|
133
|
-
const proxyReturns = await targetProxy(params, context);
|
|
134
|
-
if (proxyReturns !== undefined)
|
|
135
|
-
return proxyReturns;
|
|
136
|
-
}
|
|
137
|
-
// ============================= PROXY END =============================
|
|
138
|
-
// make sure target action execute after all proxies
|
|
139
|
-
if (target) {
|
|
140
|
-
return await target(...params);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
exports.execute = execute;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execute = exports.call = exports.emit = exports.off = exports.once = 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
|
+
exports.eventHub.on(event, listener);
|
|
37
|
+
}
|
|
38
|
+
exports.on = on;
|
|
39
|
+
function once(event, listener) {
|
|
40
|
+
exports.eventHub.once(event, listener);
|
|
41
|
+
}
|
|
42
|
+
exports.once = once;
|
|
43
|
+
function off(event, listener) {
|
|
44
|
+
exports.eventHub.off(event, listener);
|
|
45
|
+
}
|
|
46
|
+
exports.off = off;
|
|
47
|
+
function emit(event, ...args) {
|
|
48
|
+
return exports.eventHub.emit(event, ...args);
|
|
49
|
+
}
|
|
50
|
+
exports.emit = emit;
|
|
51
|
+
/**
|
|
52
|
+
* Call an Function on RPC server
|
|
53
|
+
* @param action
|
|
54
|
+
* @param params
|
|
55
|
+
* @param context
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
58
|
+
async function call(action, params = [], context) {
|
|
59
|
+
if (!Array.isArray(params))
|
|
60
|
+
params = [params];
|
|
61
|
+
const { traceId } = context;
|
|
62
|
+
exports.eventHub.emit('request', action, params, context);
|
|
63
|
+
const returns = {
|
|
64
|
+
traceId,
|
|
65
|
+
success: false
|
|
66
|
+
};
|
|
67
|
+
try {
|
|
68
|
+
const result = await execute(action, [...params], context);
|
|
69
|
+
returns.body = result;
|
|
70
|
+
returns.success = true;
|
|
71
|
+
exports.eventHub.emit('success', action, params, context, result);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
returns.error = {
|
|
75
|
+
message: error.message,
|
|
76
|
+
stack: error.stack
|
|
77
|
+
};
|
|
78
|
+
exports.eventHub.emit('fail', action, params, context, error);
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
return returns;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.call = call;
|
|
85
|
+
async function execute(action, params, context) {
|
|
86
|
+
const __proxy = '__proxy', _proxy = '_proxy';
|
|
87
|
+
if (__proxy === action || _proxy === action || action.endsWith(_proxy))
|
|
88
|
+
throw new Error('Invalid Action[' + action + ']');
|
|
89
|
+
const methods = exports.kvMethods;
|
|
90
|
+
// 目标函数
|
|
91
|
+
const target = methods.get(action);
|
|
92
|
+
// 目标代理函数
|
|
93
|
+
const targetProxy = methods.get(action + _proxy);
|
|
94
|
+
// 即不存在目标也不存在目标代理时, 报错函数不存在
|
|
95
|
+
if (!target && !targetProxy)
|
|
96
|
+
throw new Error('Unknown Action [' + action + ']');
|
|
97
|
+
exports.asyncStore.enterWith(context);
|
|
98
|
+
// ============================ PROXY BEGIN ============================
|
|
99
|
+
// 最顶层代理
|
|
100
|
+
const topProxy = methods.get(__proxy);
|
|
101
|
+
if (topProxy) {
|
|
102
|
+
const proxyReturns = await topProxy(action, params, context);
|
|
103
|
+
if (proxyReturns !== undefined)
|
|
104
|
+
return proxyReturns;
|
|
105
|
+
}
|
|
106
|
+
// 'x.y.z' => [ 'x', 'y', 'z' ]
|
|
107
|
+
const nameStack = action.split('.'), size = nameStack.length - 1;
|
|
108
|
+
let index = -1, proxyPrefix = '';
|
|
109
|
+
// 根代理遍历
|
|
110
|
+
while (++index < size) {
|
|
111
|
+
// x.
|
|
112
|
+
// x.y.
|
|
113
|
+
proxyPrefix += nameStack[index] + '.';
|
|
114
|
+
// x.__proxy
|
|
115
|
+
// x.y.__proxy
|
|
116
|
+
const rootProxy = methods.get(proxyPrefix + __proxy);
|
|
117
|
+
// x.__proxy ( 'y.z', ... )
|
|
118
|
+
// x.y.__proxy ( 'z', ... )
|
|
119
|
+
if (rootProxy) {
|
|
120
|
+
const proxyReturns = await rootProxy(nameStack.slice(index).join('.'), params, context);
|
|
121
|
+
if (proxyReturns !== undefined)
|
|
122
|
+
return proxyReturns;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// 同级代理
|
|
126
|
+
const layerProxy = methods.get(proxyPrefix + _proxy);
|
|
127
|
+
if (layerProxy) {
|
|
128
|
+
const proxyReturns = await layerProxy(nameStack[index], params, context);
|
|
129
|
+
if (proxyReturns !== undefined)
|
|
130
|
+
return proxyReturns;
|
|
131
|
+
}
|
|
132
|
+
if (targetProxy) {
|
|
133
|
+
const proxyReturns = await targetProxy(params, context);
|
|
134
|
+
if (proxyReturns !== undefined)
|
|
135
|
+
return proxyReturns;
|
|
136
|
+
}
|
|
137
|
+
// ============================= PROXY END =============================
|
|
138
|
+
// make sure target action execute after all proxies
|
|
139
|
+
if (target) {
|
|
140
|
+
return await target(...params);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.execute = execute;
|
package/bin/argv.js
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
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
|
+
"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;
|
package/bin/cli.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.startup = exports.version = void 0;
|
|
5
|
-
const chalk_1 = require("chalk");
|
|
6
|
-
const starter_1 = require("./starter");
|
|
7
|
-
Object.defineProperty(exports, "startup", { enumerable: true, get: function () { return starter_1.startup; } });
|
|
8
|
-
const pkg = require("../package.json");
|
|
9
|
-
exports.version = pkg.version;
|
|
10
|
-
const jsExecutionFilename = process.argv[1];
|
|
11
|
-
if (/(oox.*cli\.js)$/.test(jsExecutionFilename)) {
|
|
12
|
-
const args = process.argv.slice(2);
|
|
13
|
-
const command = args[0];
|
|
14
|
-
var isStartup = true;
|
|
15
|
-
if (!command || ['help', '-h', '-help', '--help', 'version', '-v', '-version', '--version'].includes(command)) {
|
|
16
|
-
isStartup = false;
|
|
17
|
-
console.log();
|
|
18
|
-
console.log('OOX Service');
|
|
19
|
-
console.log((0, chalk_1.bold) `version`, chalk_1.bold.green `${pkg.version}`);
|
|
20
|
-
console.log((0, chalk_1.underline) `${pkg.homepage}`);
|
|
21
|
-
console.log();
|
|
22
|
-
}
|
|
23
|
-
if (['help', '-h', '-help', '--help'].includes(command)) {
|
|
24
|
-
console.log((0, chalk_1.bold) `Usage:`);
|
|
25
|
-
console.log(' oox entry.js');
|
|
26
|
-
console.log();
|
|
27
|
-
console.log(' oox entry.js port=8080');
|
|
28
|
-
console.log();
|
|
29
|
-
console.log(' oox app/entry/index.js group=app/ env=envs/entry.js ignore=core');
|
|
30
|
-
console.log();
|
|
31
|
-
console.log((0, chalk_1.bold) `Params:`);
|
|
32
|
-
const params = [
|
|
33
|
-
[' default-env [ file ] ', '.js or .json file, merge to oox.config'],
|
|
34
|
-
[' env [ file ] ', '.js or .json file, merge to oox.config', (0, chalk_1.bold) `(after default-env)`],
|
|
35
|
-
[' port [ int ] ', 'set', (0, chalk_1.bold) `0`, 'for random port, or any integer > 0'],
|
|
36
|
-
[' group [ dir ] ', 'service group directory, all LocalCall transform to RPC'],
|
|
37
|
-
[' ignore [ name ] ', 'set a name for LocalCall do not transform to RPC, support string | array<string>'],
|
|
38
|
-
[' http [ json ] ', 'HTTP server options, support flat name, ex: http.path=/api'],
|
|
39
|
-
[' socketio [ json ] ', 'SocketIO server options, support flat name'],
|
|
40
|
-
[' registry [ urls ] ', 'registry service url, support string | array<string>'],
|
|
41
|
-
[' origin [ urls ] ', 'set', (0, chalk_1.bold) `*`, 'allow any connections <Access-Control-Allow-Origin>'],
|
|
42
|
-
[' ... ', 'set params as', (0, chalk_1.bold) `foo=bar` + ',', 'usage as', (0, chalk_1.bold) `oox.config.foo`]
|
|
43
|
-
];
|
|
44
|
-
params.forEach(row => console.log(...row, '\n'));
|
|
45
|
-
console.log();
|
|
46
|
-
}
|
|
47
|
-
if (isStartup)
|
|
48
|
-
(0, starter_1.startup)();
|
|
49
|
-
}
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.startup = exports.version = void 0;
|
|
5
|
+
const chalk_1 = require("chalk");
|
|
6
|
+
const starter_1 = require("./starter");
|
|
7
|
+
Object.defineProperty(exports, "startup", { enumerable: true, get: function () { return starter_1.startup; } });
|
|
8
|
+
const pkg = require("../package.json");
|
|
9
|
+
exports.version = pkg.version;
|
|
10
|
+
const jsExecutionFilename = process.argv[1];
|
|
11
|
+
if (/(oox.*cli\.js)$/.test(jsExecutionFilename)) {
|
|
12
|
+
const args = process.argv.slice(2);
|
|
13
|
+
const command = args[0];
|
|
14
|
+
var isStartup = true;
|
|
15
|
+
if (!command || ['help', '-h', '-help', '--help', 'version', '-v', '-version', '--version'].includes(command)) {
|
|
16
|
+
isStartup = false;
|
|
17
|
+
console.log();
|
|
18
|
+
console.log('OOX Service');
|
|
19
|
+
console.log((0, chalk_1.bold) `version`, chalk_1.bold.green `${pkg.version}`);
|
|
20
|
+
console.log((0, chalk_1.underline) `${pkg.homepage}`);
|
|
21
|
+
console.log();
|
|
22
|
+
}
|
|
23
|
+
if (['help', '-h', '-help', '--help'].includes(command)) {
|
|
24
|
+
console.log((0, chalk_1.bold) `Usage:`);
|
|
25
|
+
console.log(' oox entry.js');
|
|
26
|
+
console.log();
|
|
27
|
+
console.log(' oox entry.js port=8080');
|
|
28
|
+
console.log();
|
|
29
|
+
console.log(' oox app/entry/index.js group=app/ env=envs/entry.js ignore=core');
|
|
30
|
+
console.log();
|
|
31
|
+
console.log((0, chalk_1.bold) `Params:`);
|
|
32
|
+
const params = [
|
|
33
|
+
[' default-env [ file ] ', '.js or .json file, merge to oox.config'],
|
|
34
|
+
[' env [ file ] ', '.js or .json file, merge to oox.config', (0, chalk_1.bold) `(after default-env)`],
|
|
35
|
+
[' port [ int ] ', 'set', (0, chalk_1.bold) `0`, 'for random port, or any integer > 0'],
|
|
36
|
+
[' group [ dir ] ', 'service group directory, all LocalCall transform to RPC'],
|
|
37
|
+
[' ignore [ name ] ', 'set a name for LocalCall do not transform to RPC, support string | array<string>'],
|
|
38
|
+
[' http [ json ] ', 'HTTP server options, support flat name, ex: http.path=/api'],
|
|
39
|
+
[' socketio [ json ] ', 'SocketIO server options, support flat name'],
|
|
40
|
+
[' registry [ urls ] ', 'registry service url, support string | array<string>'],
|
|
41
|
+
[' origin [ urls ] ', 'set', (0, chalk_1.bold) `*`, 'allow any connections <Access-Control-Allow-Origin>'],
|
|
42
|
+
[' ... ', 'set params as', (0, chalk_1.bold) `foo=bar` + ',', 'usage as', (0, chalk_1.bold) `oox.config.foo`]
|
|
43
|
+
];
|
|
44
|
+
params.forEach(row => console.log(...row, '\n'));
|
|
45
|
+
console.log();
|
|
46
|
+
}
|
|
47
|
+
if (isStartup)
|
|
48
|
+
(0, starter_1.startup)();
|
|
49
|
+
}
|