@wooksjs/event-cli 0.2.18 → 0.2.19
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/README.md +1 -1
- package/dist/index.cjs +14 -5
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +14 -5
- package/package.json +4 -4
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -28,6 +28,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
28
28
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
29
29
|
PERFORMANCE OF THIS SOFTWARE.
|
|
30
30
|
***************************************************************************** */
|
|
31
|
+
/* global Reflect, Promise */
|
|
32
|
+
|
|
31
33
|
|
|
32
34
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
33
35
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -55,9 +57,11 @@ class WooksCli extends wooks.WooksAdapterBase {
|
|
|
55
57
|
var _a;
|
|
56
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
59
|
const argv = process.argv.slice(2) || _argv;
|
|
58
|
-
const firstFlagIndex = argv.findIndex(a => a.startsWith('-')) + 1;
|
|
59
|
-
const pathParams =
|
|
60
|
-
|
|
60
|
+
const firstFlagIndex = argv.findIndex((a) => a.startsWith('-')) + 1;
|
|
61
|
+
const pathParams = firstFlagIndex
|
|
62
|
+
? argv.slice(0, firstFlagIndex - 1)
|
|
63
|
+
: argv;
|
|
64
|
+
const path = '/' + pathParams.map((v) => encodeURIComponent(v)).join('/');
|
|
61
65
|
const { restoreCtx, clearCtx } = createCliContext({ argv }, this.mergeEventOptions((_a = this.opts) === null || _a === void 0 ? void 0 : _a.eventOptions));
|
|
62
66
|
const handlers = this.wooks.lookup('CLI', path);
|
|
63
67
|
if (handlers) {
|
|
@@ -69,7 +73,9 @@ class WooksCli extends wooks.WooksAdapterBase {
|
|
|
69
73
|
console.log(response);
|
|
70
74
|
}
|
|
71
75
|
else if (Array.isArray(response)) {
|
|
72
|
-
response.forEach(r => console.log(typeof r === 'string'
|
|
76
|
+
response.forEach((r) => console.log(typeof r === 'string'
|
|
77
|
+
? r
|
|
78
|
+
: JSON.stringify(r, null, ' ')));
|
|
73
79
|
}
|
|
74
80
|
else if (response instanceof Error) {
|
|
75
81
|
console.error('[31m' + response.message + '[0m');
|
|
@@ -107,7 +113,10 @@ class WooksCli extends wooks.WooksAdapterBase {
|
|
|
107
113
|
this.opts.onUnknownParams(pathParams);
|
|
108
114
|
}
|
|
109
115
|
else {
|
|
110
|
-
this.error('[0m' +
|
|
116
|
+
this.error('[0m' +
|
|
117
|
+
'Unknown command parameters: ' +
|
|
118
|
+
'[31m' +
|
|
119
|
+
pathParams.join(' '));
|
|
111
120
|
process.exit(1);
|
|
112
121
|
}
|
|
113
122
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { TConsoleBase } from '@prostojs/logger';
|
|
|
2
2
|
import { TEmpty } from '@wooksjs/event-core';
|
|
3
3
|
import { TEventOptions } from '@wooksjs/event-core';
|
|
4
4
|
import { TGenericContextStore } from '@wooksjs/event-core';
|
|
5
|
-
import {
|
|
5
|
+
import { TProstoRouterPathHandle } from '@prostojs/router';
|
|
6
6
|
import { TWooksHandler } from 'wooks';
|
|
7
7
|
import { Wooks } from 'wooks';
|
|
8
8
|
import { WooksAdapterBase } from 'wooks';
|
|
@@ -13,7 +13,7 @@ export declare const cliShortcuts: {
|
|
|
13
13
|
|
|
14
14
|
export declare function createCliApp(opts?: TWooksCliOptions, wooks?: Wooks | WooksAdapterBase): WooksCli;
|
|
15
15
|
|
|
16
|
-
export declare function createCliContext(data: TCliEventData, options: TEventOptions): {
|
|
16
|
+
export declare function createCliContext(data: Omit<TCliEventData, 'type'>, options: TEventOptions): {
|
|
17
17
|
getCtx: () => TCliContextStore & TGenericContextStore<TCliEventData>;
|
|
18
18
|
restoreCtx: () => TGenericContextStore<TEmpty>;
|
|
19
19
|
clearCtx: () => null;
|
|
@@ -85,7 +85,7 @@ export declare class WooksCli extends WooksAdapterBase {
|
|
|
85
85
|
protected opts?: TWooksCliOptions | undefined;
|
|
86
86
|
protected logger: TConsoleBase;
|
|
87
87
|
constructor(opts?: TWooksCliOptions | undefined, wooks?: Wooks | WooksAdapterBase);
|
|
88
|
-
cli<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>):
|
|
88
|
+
cli<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): TProstoRouterPathHandle<ParamsType>;
|
|
89
89
|
run(_argv?: string[]): Promise<void>;
|
|
90
90
|
onError(e: Error): void;
|
|
91
91
|
onUnknownParams(pathParams: string[]): void;
|
package/dist/index.mjs
CHANGED
|
@@ -26,6 +26,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
26
26
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
27
27
|
PERFORMANCE OF THIS SOFTWARE.
|
|
28
28
|
***************************************************************************** */
|
|
29
|
+
/* global Reflect, Promise */
|
|
30
|
+
|
|
29
31
|
|
|
30
32
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
31
33
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -53,9 +55,11 @@ class WooksCli extends WooksAdapterBase {
|
|
|
53
55
|
var _a;
|
|
54
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
57
|
const argv = process.argv.slice(2) || _argv;
|
|
56
|
-
const firstFlagIndex = argv.findIndex(a => a.startsWith('-')) + 1;
|
|
57
|
-
const pathParams =
|
|
58
|
-
|
|
58
|
+
const firstFlagIndex = argv.findIndex((a) => a.startsWith('-')) + 1;
|
|
59
|
+
const pathParams = firstFlagIndex
|
|
60
|
+
? argv.slice(0, firstFlagIndex - 1)
|
|
61
|
+
: argv;
|
|
62
|
+
const path = '/' + pathParams.map((v) => encodeURIComponent(v)).join('/');
|
|
59
63
|
const { restoreCtx, clearCtx } = createCliContext({ argv }, this.mergeEventOptions((_a = this.opts) === null || _a === void 0 ? void 0 : _a.eventOptions));
|
|
60
64
|
const handlers = this.wooks.lookup('CLI', path);
|
|
61
65
|
if (handlers) {
|
|
@@ -67,7 +71,9 @@ class WooksCli extends WooksAdapterBase {
|
|
|
67
71
|
console.log(response);
|
|
68
72
|
}
|
|
69
73
|
else if (Array.isArray(response)) {
|
|
70
|
-
response.forEach(r => console.log(typeof r === 'string'
|
|
74
|
+
response.forEach((r) => console.log(typeof r === 'string'
|
|
75
|
+
? r
|
|
76
|
+
: JSON.stringify(r, null, ' ')));
|
|
71
77
|
}
|
|
72
78
|
else if (response instanceof Error) {
|
|
73
79
|
console.error('[31m' + response.message + '[0m');
|
|
@@ -105,7 +111,10 @@ class WooksCli extends WooksAdapterBase {
|
|
|
105
111
|
this.opts.onUnknownParams(pathParams);
|
|
106
112
|
}
|
|
107
113
|
else {
|
|
108
|
-
this.error('[0m' +
|
|
114
|
+
this.error('[0m' +
|
|
115
|
+
'Unknown command parameters: ' +
|
|
116
|
+
'[31m' +
|
|
117
|
+
pathParams.join(' '));
|
|
109
118
|
process.exit(1);
|
|
110
119
|
}
|
|
111
120
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/event-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.19",
|
|
4
4
|
"description": "@wooksjs/event-cli",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"url": "https://github.com/wooksjs/wooksjs/issues"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"wooks": "0.2.
|
|
35
|
-
"@wooksjs/event-core": "0.2.
|
|
34
|
+
"wooks": "0.2.19",
|
|
35
|
+
"@wooksjs/event-core": "0.2.19"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"minimist": "^1.2.6",
|
|
39
|
-
"@prostojs/logger": "^0.3.
|
|
39
|
+
"@prostojs/logger": "^0.3.6"
|
|
40
40
|
},
|
|
41
41
|
"homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/event-cli#readme"
|
|
42
42
|
}
|