@wooksjs/event-cli 0.7.1 → 0.7.3

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
@@ -38,16 +38,9 @@ const flagsKey = (0, __wooksjs_event_core.key)("cli.flags");
38
38
 
39
39
  //#endregion
40
40
  //#region packages/event-cli/src/event-cli.ts
41
- /** Creates a new event context for a CLI command invocation. */
42
- function createCliContext(data, options) {
43
- const ctx = new __wooksjs_event_core.EventContext(options);
44
- return (fn) => (0, __wooksjs_event_core.run)(ctx, () => ctx.seed(cliKind, {
45
- argv: data.argv,
46
- pathParams: data.pathParams,
47
- command: data.command,
48
- opts: data.opts,
49
- cliHelp: data.cliHelp
50
- }, fn));
41
+ /** Creates a CLI event context and runs `fn` inside it. */
42
+ function createCliContext(options, seeds, fn) {
43
+ return (0, __wooksjs_event_core.createEventContext)(options, cliKind, seeds, fn);
51
44
  }
52
45
 
53
46
  //#endregion
@@ -159,14 +152,13 @@ var WooksCli = class extends wooks.WooksAdapterBase {
159
152
  const parsedFlags = (0, minimist.default)(argv, _opts);
160
153
  const pathParams = parsedFlags._;
161
154
  const path = `/${pathParams.map((v) => encodeURI(v).replace(/\//gu, "%2F")).join("/")}`;
162
- const runInContext = createCliContext({
155
+ return createCliContext(this.getEventContextOptions(), {
163
156
  opts: _opts,
164
157
  argv,
165
158
  pathParams,
166
159
  cliHelp: this.cliHelp,
167
160
  command: path.replace(/\//gu, " ").trim()
168
- }, this.getEventContextOptions());
169
- return runInContext(async () => {
161
+ }, async () => {
170
162
  const ctx = (0, __wooksjs_event_core.current)();
171
163
  ctx.set(flagsKey, parsedFlags);
172
164
  this.computeAliases();
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import * as _prostojs_cli_help from '@prostojs/cli-help';
4
4
  import { CliHelpRenderer, TCliEntry, TCliHelpOptions } from '@prostojs/cli-help';
5
5
  import { TConsoleBase } from '@prostojs/logger';
6
6
  import * as _wooksjs_event_core from '@wooksjs/event-core';
7
- import { EventContextOptions } from '@wooksjs/event-core';
7
+ import { EventContextOptions, EventKindSeeds } from '@wooksjs/event-core';
8
8
  export { EventContext, EventContextOptions, useLogger, useRouteParams } from '@wooksjs/event-core';
9
9
  import minimist from 'minimist';
10
10
  import { TProstoRouterPathHandle } from '@prostojs/router';
@@ -229,15 +229,8 @@ declare function useCliOptions(): Record<string, string | boolean>;
229
229
  */
230
230
  declare function useCliOption(name: string): string | boolean;
231
231
 
232
- interface TCliEventInput {
233
- argv: string[];
234
- pathParams: string[];
235
- command: string;
236
- opts?: minimist.Opts;
237
- cliHelp: TCliHelpRenderer;
238
- }
239
- /** Creates a new event context for a CLI command invocation. */
240
- declare function createCliContext(data: TCliEventInput, options: EventContextOptions): <R>(fn: () => R) => R;
232
+ /** Creates a CLI event context and runs `fn` inside it. */
233
+ declare function createCliContext<R>(options: EventContextOptions, seeds: EventKindSeeds<typeof cliKind>, fn: () => R): R;
241
234
 
242
235
  export { WooksCli, cliKind, cliShortcuts, createCliApp, createCliContext, flagsKey, useAutoHelp, useCliHelp, useCliOption, useCliOptions, useCommandLookupHelp };
243
- export type { TCliEventInput, TCliHelpCustom, TCliHelpRenderer, TWooksCliEntry, TWooksCliOptions };
236
+ export type { TCliHelpCustom, TCliHelpRenderer, TWooksCliEntry, TWooksCliOptions };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CliHelpRenderer } from "@prostojs/cli-help";
2
- import { EventContext, current, defineEventKind, key, run, slot, useLogger, useRouteParams } from "@wooksjs/event-core";
2
+ import { createEventContext, current, defineEventKind, key, slot, useLogger, useRouteParams } from "@wooksjs/event-core";
3
3
  import minimist from "minimist";
4
4
  import { WooksAdapterBase } from "wooks";
5
5
 
@@ -15,16 +15,9 @@ const flagsKey = key("cli.flags");
15
15
 
16
16
  //#endregion
17
17
  //#region packages/event-cli/src/event-cli.ts
18
- /** Creates a new event context for a CLI command invocation. */
19
- function createCliContext(data, options) {
20
- const ctx = new EventContext(options);
21
- return (fn) => run(ctx, () => ctx.seed(cliKind, {
22
- argv: data.argv,
23
- pathParams: data.pathParams,
24
- command: data.command,
25
- opts: data.opts,
26
- cliHelp: data.cliHelp
27
- }, fn));
18
+ /** Creates a CLI event context and runs `fn` inside it. */
19
+ function createCliContext(options, seeds, fn) {
20
+ return createEventContext(options, cliKind, seeds, fn);
28
21
  }
29
22
 
30
23
  //#endregion
@@ -136,14 +129,13 @@ var WooksCli = class extends WooksAdapterBase {
136
129
  const parsedFlags = minimist(argv, _opts);
137
130
  const pathParams = parsedFlags._;
138
131
  const path = `/${pathParams.map((v) => encodeURI(v).replace(/\//gu, "%2F")).join("/")}`;
139
- const runInContext = createCliContext({
132
+ return createCliContext(this.getEventContextOptions(), {
140
133
  opts: _opts,
141
134
  argv,
142
135
  pathParams,
143
136
  cliHelp: this.cliHelp,
144
137
  command: path.replace(/\//gu, " ").trim()
145
- }, this.getEventContextOptions());
146
- return runInContext(async () => {
138
+ }, async () => {
147
139
  const ctx = current();
148
140
  ctx.set(flagsKey, parsedFlags);
149
141
  this.computeAliases();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/event-cli",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "@wooksjs/event-cli",
5
5
  "keywords": [
6
6
  "api",
@@ -52,14 +52,14 @@
52
52
  "@types/minimist": "^1.2.5",
53
53
  "typescript": "^5.9.3",
54
54
  "vitest": "^3.2.4",
55
- "@wooksjs/event-core": "^0.7.1",
56
- "wooks": "^0.7.1"
55
+ "@wooksjs/event-core": "^0.7.3",
56
+ "wooks": "^0.7.3"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "@prostojs/logger": "^0.4.3",
60
60
  "@prostojs/router": "^0.3.2",
61
- "@wooksjs/event-core": "^0.7.1",
62
- "wooks": "^0.7.1"
61
+ "@wooksjs/event-core": "^0.7.3",
62
+ "wooks": "^0.7.3"
63
63
  },
64
64
  "scripts": {
65
65
  "build": "rolldown -c ../../rolldown.config.mjs",