@wooksjs/event-cli 0.2.12 → 0.2.14

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/dist/index.cjs CHANGED
@@ -4,9 +4,10 @@ var eventCore = require('@wooksjs/event-core');
4
4
  var wooks = require('wooks');
5
5
  var minimist = require('minimist');
6
6
 
7
- function createCliContext(data) {
7
+ function createCliContext(data, options) {
8
8
  return eventCore.createEventContext({
9
9
  event: Object.assign(Object.assign({}, data), { type: 'CLI' }),
10
+ options,
10
11
  });
11
12
  }
12
13
  function useCliContext() {
@@ -45,17 +46,19 @@ class WooksCli extends wooks.WooksAdapterBase {
45
46
  constructor(opts, wooks) {
46
47
  super(wooks);
47
48
  this.opts = opts;
49
+ this.logger = (opts === null || opts === void 0 ? void 0 : opts.logger) || this.getLogger('wooks-cli');
48
50
  }
49
51
  cli(path, handler) {
50
52
  return this.on('CLI', path, handler);
51
53
  }
52
54
  run(_argv) {
55
+ var _a;
53
56
  return __awaiter(this, void 0, void 0, function* () {
54
57
  const argv = process.argv.slice(2) || _argv;
55
58
  const firstFlagIndex = argv.findIndex(a => a.startsWith('-')) + 1;
56
59
  const pathParams = (firstFlagIndex ? argv.slice(0, firstFlagIndex - 1) : argv);
57
60
  const path = '/' + pathParams.map(v => encodeURIComponent(v)).join('/');
58
- const { restoreCtx, clearCtx } = createCliContext({ argv });
61
+ const { restoreCtx, clearCtx } = createCliContext({ argv }, ((_a = this.opts) === null || _a === void 0 ? void 0 : _a.eventOptions) || {});
59
62
  const handlers = this.wooks.lookup('CLI', path);
60
63
  if (handlers) {
61
64
  try {
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { TConsoleBase } from '@prostojs/logger';
2
+ import { TEventOptions } from '@wooksjs/event-core';
1
3
  import { TGenericContextStore } from '@wooksjs/event-core';
2
4
  import { TGenericEvent } from '@wooksjs/event-core';
3
5
  import { TProstoRouterPathBuilder } from '@prostojs/router';
@@ -11,7 +13,7 @@ export declare const cliShortcuts: {
11
13
 
12
14
  export declare function createCliApp(opts?: TWooksCliOptions, wooks?: Wooks | WooksAdapterBase): WooksCli;
13
15
 
14
- export declare function createCliContext(data: TCliEventData): {
16
+ export declare function createCliContext(data: TCliEventData, options: TEventOptions): {
15
17
  getCtx: () => TCliContextStore;
16
18
  restoreCtx: () => TCliContextStore;
17
19
  clearCtx: () => null;
@@ -50,6 +52,8 @@ declare interface TCliEventData {
50
52
  export declare interface TWooksCliOptions {
51
53
  onError?(e: Error): void;
52
54
  onUnknownParams?(pathParams: string[]): void;
55
+ logger?: TConsoleBase;
56
+ eventOptions?: TEventOptions;
53
57
  }
54
58
 
55
59
  export declare function useCliContext<T extends object>(): {
@@ -82,6 +86,7 @@ export declare function useFlags(): {
82
86
 
83
87
  export declare class WooksCli extends WooksAdapterBase {
84
88
  protected opts?: TWooksCliOptions | undefined;
89
+ protected logger: TConsoleBase;
85
90
  constructor(opts?: TWooksCliOptions | undefined, wooks?: Wooks | WooksAdapterBase);
86
91
  cli<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): TProstoRouterPathBuilder<ParamsType>;
87
92
  run(_argv?: string[]): Promise<void>;
package/dist/index.mjs CHANGED
@@ -2,9 +2,10 @@ import { createEventContext, useEventContext } from '@wooksjs/event-core';
2
2
  import { WooksAdapterBase } from 'wooks';
3
3
  import minimist from 'minimist';
4
4
 
5
- function createCliContext(data) {
5
+ function createCliContext(data, options) {
6
6
  return createEventContext({
7
7
  event: Object.assign(Object.assign({}, data), { type: 'CLI' }),
8
+ options,
8
9
  });
9
10
  }
10
11
  function useCliContext() {
@@ -43,17 +44,19 @@ class WooksCli extends WooksAdapterBase {
43
44
  constructor(opts, wooks) {
44
45
  super(wooks);
45
46
  this.opts = opts;
47
+ this.logger = (opts === null || opts === void 0 ? void 0 : opts.logger) || this.getLogger('wooks-cli');
46
48
  }
47
49
  cli(path, handler) {
48
50
  return this.on('CLI', path, handler);
49
51
  }
50
52
  run(_argv) {
53
+ var _a;
51
54
  return __awaiter(this, void 0, void 0, function* () {
52
55
  const argv = process.argv.slice(2) || _argv;
53
56
  const firstFlagIndex = argv.findIndex(a => a.startsWith('-')) + 1;
54
57
  const pathParams = (firstFlagIndex ? argv.slice(0, firstFlagIndex - 1) : argv);
55
58
  const path = '/' + pathParams.map(v => encodeURIComponent(v)).join('/');
56
- const { restoreCtx, clearCtx } = createCliContext({ argv });
59
+ const { restoreCtx, clearCtx } = createCliContext({ argv }, ((_a = this.opts) === null || _a === void 0 ? void 0 : _a.eventOptions) || {});
57
60
  const handlers = this.wooks.lookup('CLI', path);
58
61
  if (handlers) {
59
62
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/event-cli",
3
- "version": "0.2.12",
3
+ "version": "0.2.14",
4
4
  "description": "@wooksjs/event-cli",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -31,11 +31,12 @@
31
31
  "url": "https://github.com/wooksjs/wooksjs/issues"
32
32
  },
33
33
  "peerDependencies": {
34
- "wooks": "0.2.12",
35
- "@wooksjs/event-core": "0.2.12"
34
+ "wooks": "0.2.14",
35
+ "@wooksjs/event-core": "0.2.14"
36
36
  },
37
37
  "dependencies": {
38
- "minimist": "^1.2.6"
38
+ "minimist": "^1.2.6",
39
+ "@prostojs/logger": "^0.3.2"
39
40
  },
40
41
  "homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/event-cli#readme"
41
42
  }