@wooksjs/event-cli 0.1.0 → 0.2.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 CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  <p align="center">
6
6
  <img src="../../logo.png" width="128px"><br>
7
- <a href="https://github.com/prostojs/wooks/blob/main/LICENSE">
7
+ <a href="https://github.com/wooksjs/wooksjs/blob/main/LICENSE">
8
8
  <img src="https://img.shields.io/badge/License-MIT-green?style=for-the-badge" />
9
9
  </a>
10
10
  </p>
@@ -20,10 +20,10 @@ As a part of `wooks` event processing framework, `@wooksjs/event-cli` implements
20
20
  ## Quick Start
21
21
 
22
22
  ```js
23
- import { useRouteParams, Wooks } from 'wooks'
24
- import { WooksCli, cliShortcuts, useFlags } from '@wooksjs/event-cli'
23
+ import { useRouteParams } from 'wooks'
24
+ import { createCliApp, useFlags } from '@wooksjs/event-cli'
25
25
 
26
- const app = new Wooks().shortcuts(cliShortcuts)
26
+ const app = createCliApp()
27
27
 
28
28
  app.cli('test', () => {
29
29
  console.log('flags:')
@@ -35,7 +35,7 @@ app.cli(':arg', () => {
35
35
  return 'done'
36
36
  })
37
37
 
38
- app.subscribe(new WooksCli())
38
+ app.run()
39
39
 
40
40
  // node ./index.js test
41
41
  // node ./index.js random
package/dist/index.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var eventCore = require('@wooksjs/event-core');
4
+ var wooks = require('wooks');
4
5
  var minimist = require('minimist');
5
6
 
6
7
  function createCliContext(data) {
@@ -47,14 +48,21 @@ function logError(error) {
47
48
  const cliShortcuts = {
48
49
  cli: 'CLI',
49
50
  };
50
- class WooksCli {
51
- subscribe(lookup) {
51
+ class WooksCli extends wooks.WooksAdapterBase {
52
+ constructor(opts, wooks) {
53
+ super(wooks);
54
+ this.opts = opts;
55
+ }
56
+ cli(path, handler) {
57
+ return this.on('CLI', path, handler);
58
+ }
59
+ run(_argv) {
52
60
  return __awaiter(this, void 0, void 0, function* () {
53
- const argv = process.argv.slice(2);
61
+ const argv = process.argv.slice(2) || _argv;
54
62
  const firstFlagIndex = argv.findIndex(a => a.startsWith('-')) + 1;
55
- const routing = { method: 'CLI', url: '/' + (firstFlagIndex ? argv.slice(0, firstFlagIndex - 1) : argv).map(v => encodeURIComponent(v)).join('/') };
63
+ const path = '/' + (firstFlagIndex ? argv.slice(0, firstFlagIndex - 1) : argv).map(v => encodeURIComponent(v)).join('/');
56
64
  const { restoreCtx, clearCtx } = createCliContext({ argv });
57
- const handlers = lookup(routing);
65
+ const handlers = this.wooks.lookup('CLI', path);
58
66
  if (handlers) {
59
67
  try {
60
68
  for (const handler of handlers) {
@@ -83,6 +91,9 @@ class WooksCli {
83
91
  }
84
92
  });
85
93
  }
94
+ }
95
+ function createCliApp(opts, wooks) {
96
+ return new WooksCli(opts, wooks);
86
97
  }
87
98
 
88
99
  function useFlags() {
@@ -99,6 +110,7 @@ function useFlag(name) {
99
110
 
100
111
  exports.WooksCli = WooksCli;
101
112
  exports.cliShortcuts = cliShortcuts;
113
+ exports.createCliApp = createCliApp;
102
114
  exports.createCliContext = createCliContext;
103
115
  exports.useCliContext = useCliContext;
104
116
  exports.useFlag = useFlag;
package/dist/index.d.ts CHANGED
@@ -1,13 +1,16 @@
1
1
  import { TGenericContextStore } from '@wooksjs/event-core';
2
2
  import { TGenericEvent } from '@wooksjs/event-core';
3
- import { TWooksLookupArgs } from 'wooks';
4
- import { TWooksLookupHandlers } from 'wooks';
5
- import { TWooksSubscribeAdapter } from 'wooks';
3
+ import { TProstoRouterPathBuilder } from '@prostojs/router';
4
+ import { TWooksHandler } from 'wooks';
5
+ import { Wooks } from 'wooks';
6
+ import { WooksAdapterBase } from 'wooks';
6
7
 
7
8
  export declare const cliShortcuts: {
8
9
  cli: string;
9
10
  };
10
11
 
12
+ export declare function createCliApp(opts?: TWooksCliOptions, wooks?: Wooks | WooksAdapterBase): WooksCli;
13
+
11
14
  export declare function createCliContext(data: TCliEventData): {
12
15
  getCtx: () => TCliContextStore;
13
16
  restoreCtx: () => TCliContextStore;
@@ -44,6 +47,9 @@ declare interface TCliEventData {
44
47
  argv: string[];
45
48
  }
46
49
 
50
+ export declare interface TWooksCliOptions {
51
+ }
52
+
47
53
  export declare function useCliContext<T extends object>(): {
48
54
  getCtx: () => TCliContextStore & T;
49
55
  restoreCtx: () => TCliContextStore & T;
@@ -72,8 +78,11 @@ export declare function useFlags(): {
72
78
  [name: string]: string | boolean;
73
79
  };
74
80
 
75
- export declare class WooksCli implements TWooksSubscribeAdapter {
76
- subscribe(lookup: (route: TWooksLookupArgs) => TWooksLookupHandlers | null): Promise<void>;
81
+ export declare class WooksCli extends WooksAdapterBase {
82
+ protected opts?: TWooksCliOptions | undefined;
83
+ constructor(opts?: TWooksCliOptions | undefined, wooks?: Wooks | WooksAdapterBase);
84
+ cli<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): TProstoRouterPathBuilder<ParamsType>;
85
+ run(_argv?: string[]): Promise<void>;
77
86
  }
78
87
 
79
88
  export { }
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { createEventContext, useEventContext } from '@wooksjs/event-core';
2
+ import { WooksAdapterBase } from 'wooks';
2
3
  import minimist from 'minimist';
3
4
 
4
5
  function createCliContext(data) {
@@ -45,14 +46,21 @@ function logError(error) {
45
46
  const cliShortcuts = {
46
47
  cli: 'CLI',
47
48
  };
48
- class WooksCli {
49
- subscribe(lookup) {
49
+ class WooksCli extends WooksAdapterBase {
50
+ constructor(opts, wooks) {
51
+ super(wooks);
52
+ this.opts = opts;
53
+ }
54
+ cli(path, handler) {
55
+ return this.on('CLI', path, handler);
56
+ }
57
+ run(_argv) {
50
58
  return __awaiter(this, void 0, void 0, function* () {
51
- const argv = process.argv.slice(2);
59
+ const argv = process.argv.slice(2) || _argv;
52
60
  const firstFlagIndex = argv.findIndex(a => a.startsWith('-')) + 1;
53
- const routing = { method: 'CLI', url: '/' + (firstFlagIndex ? argv.slice(0, firstFlagIndex - 1) : argv).map(v => encodeURIComponent(v)).join('/') };
61
+ const path = '/' + (firstFlagIndex ? argv.slice(0, firstFlagIndex - 1) : argv).map(v => encodeURIComponent(v)).join('/');
54
62
  const { restoreCtx, clearCtx } = createCliContext({ argv });
55
- const handlers = lookup(routing);
63
+ const handlers = this.wooks.lookup('CLI', path);
56
64
  if (handlers) {
57
65
  try {
58
66
  for (const handler of handlers) {
@@ -81,6 +89,9 @@ class WooksCli {
81
89
  }
82
90
  });
83
91
  }
92
+ }
93
+ function createCliApp(opts, wooks) {
94
+ return new WooksCli(opts, wooks);
84
95
  }
85
96
 
86
97
  function useFlags() {
@@ -95,4 +106,4 @@ function useFlag(name) {
95
106
  return useFlags()[name];
96
107
  }
97
108
 
98
- export { WooksCli, cliShortcuts, createCliContext, useCliContext, useFlag, useFlags };
109
+ export { WooksCli, cliShortcuts, createCliApp, createCliContext, useCliContext, useFlag, useFlags };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/event-cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "@wooksjs/event-cli",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -33,7 +33,7 @@
33
33
  "homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/event-cli#readme",
34
34
  "dependencies": {
35
35
  "minimist": "^1.2.6",
36
- "@wooksjs/event-core": "0.1.0",
37
- "wooks": "0.1.0"
36
+ "@wooksjs/event-core": "0.2.1",
37
+ "wooks": "0.2.1"
38
38
  }
39
39
  }