@wooksjs/event-cli 0.3.0 → 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.
- package/README.md +4 -4
- package/dist/index.cjs +30 -15
- package/dist/index.d.ts +28 -8
- package/dist/index.mjs +29 -13
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -21,13 +21,13 @@ As a part of `wooks` event processing framework, `@wooksjs/event-cli` implements
|
|
|
21
21
|
|
|
22
22
|
```js
|
|
23
23
|
import { useRouteParams } from 'wooks'
|
|
24
|
-
import { createCliApp,
|
|
24
|
+
import { createCliApp, useCliOptions } from '@wooksjs/event-cli'
|
|
25
25
|
|
|
26
26
|
const app = createCliApp()
|
|
27
27
|
|
|
28
28
|
app.cli('test', () => {
|
|
29
|
-
console.log('
|
|
30
|
-
return
|
|
29
|
+
console.log('options:')
|
|
30
|
+
return useCliOptions()
|
|
31
31
|
})
|
|
32
32
|
|
|
33
33
|
app.cli(':arg', () => {
|
|
@@ -43,4 +43,4 @@ app.run()
|
|
|
43
43
|
|
|
44
44
|
## Documentation
|
|
45
45
|
|
|
46
|
-
To check out docs, visit [wooksjs.org](https://wooksjs.org/).
|
|
46
|
+
To check out docs, visit [wooksjs.org](https://wooksjs.org/guide/cli/).
|
package/dist/index.cjs
CHANGED
|
@@ -11,6 +11,11 @@ function createCliContext(data, options) {
|
|
|
11
11
|
options,
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Wrapper on top of useEventContext that provides
|
|
16
|
+
* proper context types for CLI event
|
|
17
|
+
* @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
|
|
18
|
+
*/
|
|
14
19
|
function useCliContext() {
|
|
15
20
|
return eventCore.useEventContext('CLI');
|
|
16
21
|
}
|
|
@@ -251,6 +256,12 @@ class WooksCli extends wooks.WooksAdapterBase {
|
|
|
251
256
|
}
|
|
252
257
|
}
|
|
253
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* Factory for WooksCli App
|
|
261
|
+
* @param opts TWooksCliOptions
|
|
262
|
+
* @param wooks Wooks | WooksAdapterBase
|
|
263
|
+
* @returns WooksHttp
|
|
264
|
+
*/
|
|
254
265
|
function createCliApp(opts, wooks) {
|
|
255
266
|
return new WooksCli(opts, wooks);
|
|
256
267
|
}
|
|
@@ -304,7 +315,7 @@ function useCliHelp() {
|
|
|
304
315
|
*/
|
|
305
316
|
function useAutoHelp(keys = ['help'], colors = true) {
|
|
306
317
|
for (const option of keys) {
|
|
307
|
-
if (
|
|
318
|
+
if (useCliOption(option) === true) {
|
|
308
319
|
// try {
|
|
309
320
|
useCliHelp().print(colors);
|
|
310
321
|
return true;
|
|
@@ -391,7 +402,12 @@ function useCommandLookupHelp(lookupDepth = 3) {
|
|
|
391
402
|
}
|
|
392
403
|
}
|
|
393
404
|
|
|
394
|
-
|
|
405
|
+
/**
|
|
406
|
+
* Get CLI Options
|
|
407
|
+
*
|
|
408
|
+
* @returns an object with CLI options
|
|
409
|
+
*/
|
|
410
|
+
function useCliOptions() {
|
|
395
411
|
const { store } = useCliContext();
|
|
396
412
|
const flags = store('flags');
|
|
397
413
|
if (!flags.value) {
|
|
@@ -399,15 +415,21 @@ function useFlags() {
|
|
|
399
415
|
}
|
|
400
416
|
return flags.value;
|
|
401
417
|
}
|
|
402
|
-
|
|
418
|
+
/**
|
|
419
|
+
* Getter for Cli Option value
|
|
420
|
+
*
|
|
421
|
+
* @param name name of the option
|
|
422
|
+
* @returns value of a CLI option
|
|
423
|
+
*/
|
|
424
|
+
function useCliOption(name) {
|
|
403
425
|
var _a;
|
|
404
426
|
try {
|
|
405
427
|
const options = ((_a = useCliHelp().getEntry()) === null || _a === void 0 ? void 0 : _a.options) || [];
|
|
406
428
|
const opt = options.find(o => o.keys.includes(name));
|
|
407
429
|
if (opt) {
|
|
408
430
|
for (const key of opt.keys) {
|
|
409
|
-
if (
|
|
410
|
-
return
|
|
431
|
+
if (useCliOptions()[key]) {
|
|
432
|
+
return useCliOptions()[key];
|
|
411
433
|
}
|
|
412
434
|
}
|
|
413
435
|
}
|
|
@@ -415,13 +437,7 @@ function useFlag(name) {
|
|
|
415
437
|
catch (e) {
|
|
416
438
|
//
|
|
417
439
|
}
|
|
418
|
-
return
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
function usePathParams() {
|
|
422
|
-
const { store } = useCliContext();
|
|
423
|
-
const event = store('event');
|
|
424
|
-
return event.get('pathParams');
|
|
440
|
+
return useCliOptions()[name];
|
|
425
441
|
}
|
|
426
442
|
|
|
427
443
|
exports.WooksCli = WooksCli;
|
|
@@ -431,7 +447,6 @@ exports.createCliContext = createCliContext;
|
|
|
431
447
|
exports.useAutoHelp = useAutoHelp;
|
|
432
448
|
exports.useCliContext = useCliContext;
|
|
433
449
|
exports.useCliHelp = useCliHelp;
|
|
450
|
+
exports.useCliOption = useCliOption;
|
|
451
|
+
exports.useCliOptions = useCliOptions;
|
|
434
452
|
exports.useCommandLookupHelp = useCommandLookupHelp;
|
|
435
|
-
exports.useFlag = useFlag;
|
|
436
|
-
exports.useFlags = useFlags;
|
|
437
|
-
exports.usePathParams = usePathParams;
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,12 @@ export declare const cliShortcuts: {
|
|
|
15
15
|
cli: string;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Factory for WooksCli App
|
|
20
|
+
* @param opts TWooksCliOptions
|
|
21
|
+
* @param wooks Wooks | WooksAdapterBase
|
|
22
|
+
* @returns WooksHttp
|
|
23
|
+
*/
|
|
18
24
|
export declare function createCliApp(opts?: TWooksCliOptions, wooks?: Wooks | WooksAdapterBase): WooksCli;
|
|
19
25
|
|
|
20
26
|
export declare function createCliContext(data: Omit<TCliEventData, 'type'>, options: TEventOptions): {
|
|
@@ -105,6 +111,11 @@ export declare interface TWooksCliOptions {
|
|
|
105
111
|
*/
|
|
106
112
|
export declare function useAutoHelp(keys?: string[], colors?: boolean): true | undefined;
|
|
107
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Wrapper on top of useEventContext that provides
|
|
116
|
+
* proper context types for CLI event
|
|
117
|
+
* @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
|
|
118
|
+
*/
|
|
108
119
|
export declare function useCliContext<T extends TEmpty>(): {
|
|
109
120
|
getCtx: () => TCliContextStore & T & TGenericContextStore<TCliEventData>;
|
|
110
121
|
restoreCtx: () => TGenericContextStore<TEmpty>;
|
|
@@ -147,6 +158,23 @@ export declare function useCliHelp(): {
|
|
|
147
158
|
print: (withColors?: boolean) => void;
|
|
148
159
|
};
|
|
149
160
|
|
|
161
|
+
/**
|
|
162
|
+
* Getter for Cli Option value
|
|
163
|
+
*
|
|
164
|
+
* @param name name of the option
|
|
165
|
+
* @returns value of a CLI option
|
|
166
|
+
*/
|
|
167
|
+
export declare function useCliOption(name: string): string | boolean;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Get CLI Options
|
|
171
|
+
*
|
|
172
|
+
* @returns an object with CLI options
|
|
173
|
+
*/
|
|
174
|
+
export declare function useCliOptions(): {
|
|
175
|
+
[name: string]: string | boolean;
|
|
176
|
+
};
|
|
177
|
+
|
|
150
178
|
/**
|
|
151
179
|
* ##useCommandLookupHelp
|
|
152
180
|
* ### Composable
|
|
@@ -182,14 +210,6 @@ export declare function useCliHelp(): {
|
|
|
182
210
|
*/
|
|
183
211
|
export declare function useCommandLookupHelp(lookupDepth?: number): void;
|
|
184
212
|
|
|
185
|
-
export declare function useFlag(name: string): string | boolean;
|
|
186
|
-
|
|
187
|
-
export declare function useFlags(): {
|
|
188
|
-
[name: string]: string | boolean;
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
export declare function usePathParams(): string[];
|
|
192
|
-
|
|
193
213
|
export declare class WooksCli extends WooksAdapterBase {
|
|
194
214
|
protected opts?: TWooksCliOptions | undefined;
|
|
195
215
|
protected logger: TConsoleBase;
|
package/dist/index.mjs
CHANGED
|
@@ -9,6 +9,11 @@ function createCliContext(data, options) {
|
|
|
9
9
|
options,
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Wrapper on top of useEventContext that provides
|
|
14
|
+
* proper context types for CLI event
|
|
15
|
+
* @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
|
|
16
|
+
*/
|
|
12
17
|
function useCliContext() {
|
|
13
18
|
return useEventContext('CLI');
|
|
14
19
|
}
|
|
@@ -249,6 +254,12 @@ class WooksCli extends WooksAdapterBase {
|
|
|
249
254
|
}
|
|
250
255
|
}
|
|
251
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Factory for WooksCli App
|
|
259
|
+
* @param opts TWooksCliOptions
|
|
260
|
+
* @param wooks Wooks | WooksAdapterBase
|
|
261
|
+
* @returns WooksHttp
|
|
262
|
+
*/
|
|
252
263
|
function createCliApp(opts, wooks) {
|
|
253
264
|
return new WooksCli(opts, wooks);
|
|
254
265
|
}
|
|
@@ -302,7 +313,7 @@ function useCliHelp() {
|
|
|
302
313
|
*/
|
|
303
314
|
function useAutoHelp(keys = ['help'], colors = true) {
|
|
304
315
|
for (const option of keys) {
|
|
305
|
-
if (
|
|
316
|
+
if (useCliOption(option) === true) {
|
|
306
317
|
// try {
|
|
307
318
|
useCliHelp().print(colors);
|
|
308
319
|
return true;
|
|
@@ -389,7 +400,12 @@ function useCommandLookupHelp(lookupDepth = 3) {
|
|
|
389
400
|
}
|
|
390
401
|
}
|
|
391
402
|
|
|
392
|
-
|
|
403
|
+
/**
|
|
404
|
+
* Get CLI Options
|
|
405
|
+
*
|
|
406
|
+
* @returns an object with CLI options
|
|
407
|
+
*/
|
|
408
|
+
function useCliOptions() {
|
|
393
409
|
const { store } = useCliContext();
|
|
394
410
|
const flags = store('flags');
|
|
395
411
|
if (!flags.value) {
|
|
@@ -397,15 +413,21 @@ function useFlags() {
|
|
|
397
413
|
}
|
|
398
414
|
return flags.value;
|
|
399
415
|
}
|
|
400
|
-
|
|
416
|
+
/**
|
|
417
|
+
* Getter for Cli Option value
|
|
418
|
+
*
|
|
419
|
+
* @param name name of the option
|
|
420
|
+
* @returns value of a CLI option
|
|
421
|
+
*/
|
|
422
|
+
function useCliOption(name) {
|
|
401
423
|
var _a;
|
|
402
424
|
try {
|
|
403
425
|
const options = ((_a = useCliHelp().getEntry()) === null || _a === void 0 ? void 0 : _a.options) || [];
|
|
404
426
|
const opt = options.find(o => o.keys.includes(name));
|
|
405
427
|
if (opt) {
|
|
406
428
|
for (const key of opt.keys) {
|
|
407
|
-
if (
|
|
408
|
-
return
|
|
429
|
+
if (useCliOptions()[key]) {
|
|
430
|
+
return useCliOptions()[key];
|
|
409
431
|
}
|
|
410
432
|
}
|
|
411
433
|
}
|
|
@@ -413,13 +435,7 @@ function useFlag(name) {
|
|
|
413
435
|
catch (e) {
|
|
414
436
|
//
|
|
415
437
|
}
|
|
416
|
-
return
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
function usePathParams() {
|
|
420
|
-
const { store } = useCliContext();
|
|
421
|
-
const event = store('event');
|
|
422
|
-
return event.get('pathParams');
|
|
438
|
+
return useCliOptions()[name];
|
|
423
439
|
}
|
|
424
440
|
|
|
425
|
-
export { WooksCli, cliShortcuts, createCliApp, createCliContext, useAutoHelp, useCliContext, useCliHelp,
|
|
441
|
+
export { WooksCli, cliShortcuts, createCliApp, createCliContext, useAutoHelp, useCliContext, useCliHelp, useCliOption, useCliOptions, useCommandLookupHelp };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/event-cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "@wooksjs/event-cli",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"url": "https://github.com/wooksjs/wooksjs/issues"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"wooks": "0.3.
|
|
35
|
-
"@wooksjs/event-core": "0.3.
|
|
34
|
+
"wooks": "0.3.1",
|
|
35
|
+
"@wooksjs/event-core": "0.3.1"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"minimist": "^1.2.6",
|