@wooksjs/event-cli 0.2.17 → 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 +34 -37
- 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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TConsoleBase } from '@prostojs/logger';
|
|
2
|
+
import { TEmpty } from '@wooksjs/event-core';
|
|
2
3
|
import { TEventOptions } from '@wooksjs/event-core';
|
|
3
4
|
import { TGenericContextStore } from '@wooksjs/event-core';
|
|
4
|
-
import {
|
|
5
|
-
import { TProstoRouterPathBuilder } from '@prostojs/router';
|
|
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,40 +13,37 @@ 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): {
|
|
17
|
-
getCtx: () => TCliContextStore
|
|
18
|
-
restoreCtx: () =>
|
|
16
|
+
export declare function createCliContext(data: Omit<TCliEventData, 'type'>, options: TEventOptions): {
|
|
17
|
+
getCtx: () => TCliContextStore & TGenericContextStore<TCliEventData>;
|
|
18
|
+
restoreCtx: () => TGenericContextStore<TEmpty>;
|
|
19
19
|
clearCtx: () => null;
|
|
20
|
-
store: <K extends keyof
|
|
21
|
-
value: TCliContextStore[K];
|
|
22
|
-
hook: <K2 extends keyof Required<TCliContextStore
|
|
23
|
-
value: Required<TCliContextStore
|
|
20
|
+
store: <K extends "flags" | keyof TGenericContextStore<TCliEventData>>(key: K) => {
|
|
21
|
+
value: (TCliContextStore & TGenericContextStore<TCliEventData>)[K];
|
|
22
|
+
hook: <K2 extends keyof Required<TCliContextStore & TGenericContextStore<TCliEventData>>[K]>(key2: K2) => {
|
|
23
|
+
value: Required<TCliContextStore & TGenericContextStore<TCliEventData>>[K][K2];
|
|
24
24
|
isDefined: boolean;
|
|
25
25
|
};
|
|
26
|
-
init: <K2_1 extends keyof Required<TCliContextStore
|
|
27
|
-
set: <K2_2 extends keyof Required<TCliContextStore
|
|
28
|
-
get: <K2_3 extends keyof Required<TCliContextStore
|
|
29
|
-
has: <K2_4 extends keyof Required<TCliContextStore
|
|
30
|
-
del: <K2_5 extends keyof Required<TCliContextStore
|
|
26
|
+
init: <K2_1 extends keyof Required<TCliContextStore & TGenericContextStore<TCliEventData>>[K]>(key2: K2_1, getter: () => Required<Required<TCliContextStore & TGenericContextStore<TCliEventData>>[K]>[K2_1]) => Required<Required<TCliContextStore & TGenericContextStore<TCliEventData>>[K]>[K2_1];
|
|
27
|
+
set: <K2_2 extends keyof Required<TCliContextStore & TGenericContextStore<TCliEventData>>[K]>(key2: K2_2, v: Required<(TCliContextStore & TGenericContextStore<TCliEventData>)[K]>[K2_2]) => Required<(TCliContextStore & TGenericContextStore<TCliEventData>)[K]>[K2_2];
|
|
28
|
+
get: <K2_3 extends keyof Required<TCliContextStore & TGenericContextStore<TCliEventData>>[K]>(key2: K2_3) => Required<TCliContextStore & TGenericContextStore<TCliEventData>>[K][K2_3];
|
|
29
|
+
has: <K2_4 extends keyof Required<TCliContextStore & TGenericContextStore<TCliEventData>>[K]>(key2: K2_4) => boolean;
|
|
30
|
+
del: <K2_5 extends keyof Required<TCliContextStore & TGenericContextStore<TCliEventData>>[K]>(key2: K2_5) => void;
|
|
31
31
|
entries: () => [string, unknown][];
|
|
32
32
|
clear: () => void;
|
|
33
33
|
};
|
|
34
|
-
getStore: <K_1 extends keyof
|
|
35
|
-
setStore: <K_2 extends keyof
|
|
34
|
+
getStore: <K_1 extends "flags" | keyof TGenericContextStore<TCliEventData>>(key: K_1) => (TCliContextStore & TGenericContextStore<TCliEventData>)[K_1];
|
|
35
|
+
setStore: <K_2 extends "flags" | keyof TGenericContextStore<TCliEventData>>(key: K_2, v: (TCliContextStore & TGenericContextStore<TCliEventData>)[K_2]) => void;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
declare interface TCliContextStore
|
|
38
|
+
export declare interface TCliContextStore {
|
|
39
39
|
flags?: {
|
|
40
40
|
[name: string]: boolean | string;
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
declare interface
|
|
45
|
-
type: 'CLI';
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
declare interface TCliEventData {
|
|
44
|
+
export declare interface TCliEventData {
|
|
49
45
|
argv: string[];
|
|
46
|
+
type: 'CLI';
|
|
50
47
|
}
|
|
51
48
|
|
|
52
49
|
export declare interface TWooksCliOptions {
|
|
@@ -56,26 +53,26 @@ export declare interface TWooksCliOptions {
|
|
|
56
53
|
eventOptions?: TEventOptions;
|
|
57
54
|
}
|
|
58
55
|
|
|
59
|
-
export declare function useCliContext<T extends
|
|
60
|
-
getCtx: () => TCliContextStore & T
|
|
61
|
-
restoreCtx: () =>
|
|
56
|
+
export declare function useCliContext<T extends TEmpty>(): {
|
|
57
|
+
getCtx: () => TCliContextStore & T & TGenericContextStore<TCliEventData>;
|
|
58
|
+
restoreCtx: () => TGenericContextStore<TEmpty>;
|
|
62
59
|
clearCtx: () => null;
|
|
63
|
-
store: <K extends keyof
|
|
64
|
-
value: (TCliContextStore & T)[K];
|
|
65
|
-
hook: <K2 extends keyof Required<TCliContextStore & T
|
|
66
|
-
value: Required<TCliContextStore & T
|
|
60
|
+
store: <K extends "flags" | keyof TGenericContextStore<TCliEventData> | keyof T>(key: K) => {
|
|
61
|
+
value: (TCliContextStore & T & TGenericContextStore<TCliEventData>)[K];
|
|
62
|
+
hook: <K2 extends keyof Required<TCliContextStore & T & TGenericContextStore<TCliEventData>>[K]>(key2: K2) => {
|
|
63
|
+
value: Required<TCliContextStore & T & TGenericContextStore<TCliEventData>>[K][K2];
|
|
67
64
|
isDefined: boolean;
|
|
68
65
|
};
|
|
69
|
-
init: <K2_1 extends keyof Required<TCliContextStore & T
|
|
70
|
-
set: <K2_2 extends keyof Required<TCliContextStore & T
|
|
71
|
-
get: <K2_3 extends keyof Required<TCliContextStore & T
|
|
72
|
-
has: <K2_4 extends keyof Required<TCliContextStore & T
|
|
73
|
-
del: <K2_5 extends keyof Required<TCliContextStore & T
|
|
66
|
+
init: <K2_1 extends keyof Required<TCliContextStore & T & TGenericContextStore<TCliEventData>>[K]>(key2: K2_1, getter: () => Required<Required<TCliContextStore & T & TGenericContextStore<TCliEventData>>[K]>[K2_1]) => Required<Required<TCliContextStore & T & TGenericContextStore<TCliEventData>>[K]>[K2_1];
|
|
67
|
+
set: <K2_2 extends keyof Required<TCliContextStore & T & TGenericContextStore<TCliEventData>>[K]>(key2: K2_2, v: Required<(TCliContextStore & T & TGenericContextStore<TCliEventData>)[K]>[K2_2]) => Required<(TCliContextStore & T & TGenericContextStore<TCliEventData>)[K]>[K2_2];
|
|
68
|
+
get: <K2_3 extends keyof Required<TCliContextStore & T & TGenericContextStore<TCliEventData>>[K]>(key2: K2_3) => Required<TCliContextStore & T & TGenericContextStore<TCliEventData>>[K][K2_3];
|
|
69
|
+
has: <K2_4 extends keyof Required<TCliContextStore & T & TGenericContextStore<TCliEventData>>[K]>(key2: K2_4) => boolean;
|
|
70
|
+
del: <K2_5 extends keyof Required<TCliContextStore & T & TGenericContextStore<TCliEventData>>[K]>(key2: K2_5) => void;
|
|
74
71
|
entries: () => [string, unknown][];
|
|
75
72
|
clear: () => void;
|
|
76
73
|
};
|
|
77
|
-
getStore: <K_1 extends keyof
|
|
78
|
-
setStore: <K_2 extends keyof
|
|
74
|
+
getStore: <K_1 extends "flags" | keyof TGenericContextStore<TCliEventData> | keyof T>(key: K_1) => (TCliContextStore & T & TGenericContextStore<TCliEventData>)[K_1];
|
|
75
|
+
setStore: <K_2 extends "flags" | keyof TGenericContextStore<TCliEventData> | keyof T>(key: K_2, v: (TCliContextStore & T & TGenericContextStore<TCliEventData>)[K_2]) => void;
|
|
79
76
|
};
|
|
80
77
|
|
|
81
78
|
export declare function useFlag(name: string): string | boolean;
|
|
@@ -88,7 +85,7 @@ export declare class WooksCli extends WooksAdapterBase {
|
|
|
88
85
|
protected opts?: TWooksCliOptions | undefined;
|
|
89
86
|
protected logger: TConsoleBase;
|
|
90
87
|
constructor(opts?: TWooksCliOptions | undefined, wooks?: Wooks | WooksAdapterBase);
|
|
91
|
-
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>;
|
|
92
89
|
run(_argv?: string[]): Promise<void>;
|
|
93
90
|
onError(e: Error): void;
|
|
94
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
|
}
|