@gunshi/plugin 0.26.3 → 0.27.0-alpha.2
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/lib/index.d.ts +37 -16
- package/lib/index.js +1 -0
- package/package.json +5 -5
package/lib/index.d.ts
CHANGED
|
@@ -48,13 +48,14 @@ interface ArgToken {
|
|
|
48
48
|
* Inline value, e.g. `--foo=bar` => `true`, `-x=bar` => `true`.
|
|
49
49
|
*/
|
|
50
50
|
inlineValue?: boolean;
|
|
51
|
-
}
|
|
52
|
-
//#region ../../node_modules/.pnpm/args-tokens@0.20.1/node_modules/args-tokens/lib/resolver-U72Jg6Ll.d.ts
|
|
53
|
-
|
|
51
|
+
}
|
|
54
52
|
/**
|
|
55
53
|
* Parser Options.
|
|
56
54
|
*/
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region ../../node_modules/.pnpm/args-tokens@0.20.1/node_modules/args-tokens/lib/resolver-U72Jg6Ll.d.ts
|
|
57
57
|
//#region src/resolver.d.ts
|
|
58
|
+
|
|
58
59
|
/**
|
|
59
60
|
* An argument schema
|
|
60
61
|
* This schema is similar to the schema of the `node:utils`.
|
|
@@ -142,20 +143,21 @@ type FilterArgs<A extends Args, V extends Record<keyof A, unknown>, K extends ke
|
|
|
142
143
|
* @internal
|
|
143
144
|
*/
|
|
144
145
|
type FilterPositionalArgs<A extends Args, V extends Record<keyof A, unknown>> = { [Arg in keyof A as A[Arg]["type"] extends "positional" ? Arg : never]: V[Arg] };
|
|
145
|
-
|
|
146
|
-
//#endregion
|
|
147
|
-
//#region ../gunshi/src/types.d.ts
|
|
148
146
|
/**
|
|
149
147
|
* An arguments for {@link resolveArgs | resolve arguments}.
|
|
150
148
|
*/
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region ../gunshi/src/types.d.ts
|
|
151
151
|
type Awaitable<T> = T | Promise<T>;
|
|
152
152
|
/**
|
|
153
153
|
* Extend command context type. This type is used to extend the command context with additional properties at {@link CommandContext.extensions}.
|
|
154
|
+
* @since v0.27.0
|
|
154
155
|
*/
|
|
155
156
|
type ExtendContext = Record<string, unknown>;
|
|
156
157
|
/**
|
|
157
158
|
* Gunshi unified parameter type.
|
|
158
159
|
* This type combines both argument definitions and command context extensions.
|
|
160
|
+
* @since v0.27.0
|
|
159
161
|
*/
|
|
160
162
|
interface GunshiParams<P extends {
|
|
161
163
|
args?: Args;
|
|
@@ -179,11 +181,13 @@ interface GunshiParams<P extends {
|
|
|
179
181
|
}
|
|
180
182
|
/**
|
|
181
183
|
* Default Gunshi parameters
|
|
184
|
+
* @since v0.27.0
|
|
182
185
|
*/
|
|
183
186
|
type DefaultGunshiParams = GunshiParams;
|
|
184
187
|
/**
|
|
185
188
|
* Generic constraint for command-related types.
|
|
186
189
|
* This type constraint allows both GunshiParams and objects with extensions.
|
|
190
|
+
* @since v0.27.0
|
|
187
191
|
*/
|
|
188
192
|
type GunshiParamsConstraint = GunshiParams<any> | {
|
|
189
193
|
extensions: ExtendContext;
|
|
@@ -285,16 +289,19 @@ interface CommandEnvironment<G extends GunshiParamsConstraint = DefaultGunshiPar
|
|
|
285
289
|
/**
|
|
286
290
|
* Hook that runs before any command execution
|
|
287
291
|
* @see {@link CliOptions.onBeforeCommand}
|
|
292
|
+
* @since v0.27.0
|
|
288
293
|
*/
|
|
289
294
|
onBeforeCommand: ((ctx: Readonly<CommandContext<G>>) => Awaitable<void>) | undefined;
|
|
290
295
|
/**
|
|
291
296
|
* Hook that runs after successful command execution
|
|
292
297
|
* @see {@link CliOptions.onAfterCommand}
|
|
298
|
+
* @since v0.27.0
|
|
293
299
|
*/
|
|
294
|
-
onAfterCommand: ((ctx: Readonly<CommandContext<G>>, result: string |
|
|
300
|
+
onAfterCommand: ((ctx: Readonly<CommandContext<G>>, result: string | undefined) => Awaitable<void>) | undefined;
|
|
295
301
|
/**
|
|
296
302
|
* Hook that runs when a command throws an error
|
|
297
303
|
* @see {@link CliOptions.onErrorCommand}
|
|
304
|
+
* @since v0.27.0
|
|
298
305
|
*/
|
|
299
306
|
onErrorCommand: ((ctx: Readonly<CommandContext<G>>, error: Error) => Awaitable<void>) | undefined;
|
|
300
307
|
}
|
|
@@ -377,7 +384,8 @@ interface CommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
377
384
|
*/
|
|
378
385
|
log: (message?: any, ...optionalParams: any[]) => void;
|
|
379
386
|
/**
|
|
380
|
-
*
|
|
387
|
+
* Command context extensions.
|
|
388
|
+
* @since v0.27.0
|
|
381
389
|
*/
|
|
382
390
|
extensions: keyof ExtractExtensions<G> extends never ? undefined : ExtractExtensions<G>;
|
|
383
391
|
/**
|
|
@@ -388,10 +396,12 @@ interface CommandContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
388
396
|
}
|
|
389
397
|
/**
|
|
390
398
|
* CommandContextCore type (base type without extensions)
|
|
399
|
+
* @since v0.27.0
|
|
391
400
|
*/
|
|
392
401
|
type CommandContextCore<G extends GunshiParamsConstraint = DefaultGunshiParams> = Readonly<CommandContext<G>>;
|
|
393
402
|
/**
|
|
394
403
|
* Command context extension
|
|
404
|
+
* @since v0.27.0
|
|
395
405
|
*/
|
|
396
406
|
interface CommandContextExtension<E extends GunshiParams['extensions'] = DefaultGunshiParams['extensions']> {
|
|
397
407
|
readonly key: symbol;
|
|
@@ -461,7 +471,7 @@ type CommandExamplesFetcher<G extends GunshiParamsConstraint = DefaultGunshiPara
|
|
|
461
471
|
* @param ctx A {@link CommandContext | command context}
|
|
462
472
|
* @returns void or string (for CLI output)
|
|
463
473
|
*/
|
|
464
|
-
type CommandRunner<G extends GunshiParamsConstraint = DefaultGunshiParams> = (ctx: Readonly<CommandContext<G>>) => Awaitable<
|
|
474
|
+
type CommandRunner<G extends GunshiParamsConstraint = DefaultGunshiParams> = (ctx: Readonly<CommandContext<G>>) => Awaitable<string | void>;
|
|
465
475
|
/**
|
|
466
476
|
* Command loader.
|
|
467
477
|
* A function that returns a command or command runner.
|
|
@@ -474,14 +484,16 @@ type CommandRunner<G extends GunshiParamsConstraint = DefaultGunshiParams> = (ct
|
|
|
474
484
|
* A function that wraps a command runner to add or modify its behavior.
|
|
475
485
|
* @param baseRunner The base command runner to decorate
|
|
476
486
|
* @returns The decorated command runner
|
|
487
|
+
* @since v0.27.0
|
|
477
488
|
*/
|
|
478
|
-
type CommandDecorator<G extends GunshiParamsConstraint = DefaultGunshiParams> = (baseRunner: (ctx: Readonly<CommandContext<G>>) => Awaitable<
|
|
489
|
+
type CommandDecorator<G extends GunshiParamsConstraint = DefaultGunshiParams> = (baseRunner: (ctx: Readonly<CommandContext<G>>) => Awaitable<string | void>) => (ctx: Readonly<CommandContext<G>>) => Awaitable<string | void>;
|
|
479
490
|
/**
|
|
480
491
|
* Renderer decorator type.
|
|
481
492
|
* A function that wraps a base renderer to add or modify its behavior.
|
|
482
493
|
* @param baseRenderer The base renderer function to decorate
|
|
483
494
|
* @param ctx The command context
|
|
484
495
|
* @returns The decorated result
|
|
496
|
+
* @since v0.27.0
|
|
485
497
|
*/
|
|
486
498
|
type RendererDecorator<T, G extends GunshiParamsConstraint = DefaultGunshiParams> = (baseRenderer: (ctx: Readonly<CommandContext<G>>) => Promise<T>, ctx: Readonly<CommandContext<G>>) => Promise<T>;
|
|
487
499
|
/**
|
|
@@ -491,8 +503,10 @@ type RendererDecorator<T, G extends GunshiParamsConstraint = DefaultGunshiParams
|
|
|
491
503
|
* @param ctx The command context
|
|
492
504
|
* @param error The aggregate error containing validation errors
|
|
493
505
|
* @returns The decorated result
|
|
506
|
+
* @since v0.27.0
|
|
494
507
|
*/
|
|
495
|
-
type ValidationErrorsDecorator<G extends GunshiParamsConstraint = DefaultGunshiParams> = (baseRenderer: (ctx: Readonly<CommandContext<G>>, error: AggregateError) => Promise<string>, ctx: Readonly<CommandContext<G>>, error: AggregateError) => Promise<string>;
|
|
508
|
+
type ValidationErrorsDecorator<G extends GunshiParamsConstraint = DefaultGunshiParams> = (baseRenderer: (ctx: Readonly<CommandContext<G>>, error: AggregateError) => Promise<string>, ctx: Readonly<CommandContext<G>>, error: AggregateError) => Promise<string>;
|
|
509
|
+
//#endregion
|
|
496
510
|
//#region ../gunshi/src/plugin/context.d.ts
|
|
497
511
|
/**
|
|
498
512
|
* Type helper to create GunshiParams from extracted args and extensions
|
|
@@ -504,6 +518,7 @@ type ExtractedParams<G extends GunshiParamsConstraint, L extends Record<string,
|
|
|
504
518
|
};
|
|
505
519
|
/**
|
|
506
520
|
* Gunshi plugin context interface.
|
|
521
|
+
* @since v0.27.0
|
|
507
522
|
*/
|
|
508
523
|
interface PluginContext<G extends GunshiParamsConstraint = DefaultGunshiParams> {
|
|
509
524
|
/**
|
|
@@ -539,16 +554,16 @@ interface PluginContext<G extends GunshiParamsConstraint = DefaultGunshiParams>
|
|
|
539
554
|
*/
|
|
540
555
|
decorateCommand<L extends Record<string, unknown> = DefaultGunshiParams['extensions']>(decorator: (baseRunner: (ctx: Readonly<CommandContext<ExtractedParams<G, L>>>) => Awaitable<void | string>) => (ctx: Readonly<CommandContext<ExtractedParams<G, L>>>) => Awaitable<void | string>): void;
|
|
541
556
|
}
|
|
542
|
-
|
|
543
|
-
//#endregion
|
|
544
|
-
//#region ../gunshi/src/plugin/core.d.ts
|
|
545
557
|
/**
|
|
546
558
|
* Factory function for creating a plugin context.
|
|
547
559
|
* @param decorators - A {@link Decorators} instance.
|
|
548
560
|
* @returns A new {@link PluginContext} instance.
|
|
549
561
|
*/
|
|
562
|
+
//#endregion
|
|
563
|
+
//#region ../gunshi/src/plugin/core.d.ts
|
|
550
564
|
/**
|
|
551
565
|
* Plugin dependency definition
|
|
566
|
+
* @since v0.27.0
|
|
552
567
|
*/
|
|
553
568
|
interface PluginDependency {
|
|
554
569
|
/**
|
|
@@ -562,19 +577,23 @@ interface PluginDependency {
|
|
|
562
577
|
optional?: boolean;
|
|
563
578
|
}
|
|
564
579
|
/**
|
|
565
|
-
*
|
|
580
|
+
* Plugin function type
|
|
581
|
+
* @since v0.27.0
|
|
566
582
|
*/
|
|
567
583
|
type PluginFunction<G extends GunshiParams = DefaultGunshiParams> = (ctx: Readonly<PluginContext<G>>) => Awaitable<void>;
|
|
568
584
|
/**
|
|
569
585
|
* Plugin extension for CommandContext
|
|
586
|
+
* @since v0.27.0
|
|
570
587
|
*/
|
|
571
588
|
type PluginExtension<T = Record<string, unknown>, G extends GunshiParams = DefaultGunshiParams> = (ctx: CommandContextCore<G>, cmd: Command<G>) => T;
|
|
572
589
|
/**
|
|
573
590
|
* Plugin extension callback type
|
|
591
|
+
* @since v0.27.0
|
|
574
592
|
*/
|
|
575
593
|
type OnPluginExtension<G extends GunshiParams = DefaultGunshiParams> = (ctx: Readonly<CommandContext<G>>, cmd: Readonly<Command<G>>) => void;
|
|
576
594
|
/**
|
|
577
595
|
* Plugin definition options
|
|
596
|
+
* @since v0.27.0
|
|
578
597
|
*/
|
|
579
598
|
interface PluginOptions<T extends Record<string, unknown> = Record<never, never>, G extends GunshiParams = DefaultGunshiParams> {
|
|
580
599
|
/**
|
|
@@ -606,6 +625,7 @@ interface PluginOptions<T extends Record<string, unknown> = Record<never, never>
|
|
|
606
625
|
* Gunshi plugin, which is a function that receives a PluginContext.
|
|
607
626
|
* @param ctx - A {@link PluginContext}.
|
|
608
627
|
* @returns An {@link Awaitable} that resolves when the plugin is loaded.
|
|
628
|
+
* @since v0.27.0
|
|
609
629
|
*/
|
|
610
630
|
type Plugin<E extends GunshiParams['extensions'] = DefaultGunshiParams['extensions']> = PluginFunction & {
|
|
611
631
|
id: string;
|
|
@@ -636,6 +656,7 @@ interface PluginWithoutExtension<E extends GunshiParams['extensions'] = DefaultG
|
|
|
636
656
|
* Define a plugin with extension capabilities
|
|
637
657
|
* @param options - {@link PluginOptions | plugin options}
|
|
638
658
|
* @return A defined plugin with extension capabilities.
|
|
659
|
+
* @since v0.27.0
|
|
639
660
|
*/
|
|
640
661
|
declare function plugin<I extends string, P extends PluginExtension<any, DefaultGunshiParams>>(options: {
|
|
641
662
|
id: I;
|
|
@@ -655,6 +676,7 @@ declare function plugin<I extends string, P extends PluginExtension<any, Default
|
|
|
655
676
|
* Define a plugin without extension capabilities
|
|
656
677
|
* @param options - {@link PluginOptions | plugin options} without extension
|
|
657
678
|
* @returns A defined plugin without extension capabilities.
|
|
679
|
+
* @since v0.27.0
|
|
658
680
|
*/
|
|
659
681
|
declare function plugin(options: {
|
|
660
682
|
id: string;
|
|
@@ -662,6 +684,5 @@ declare function plugin(options: {
|
|
|
662
684
|
dependencies?: (PluginDependency | string)[];
|
|
663
685
|
setup?: (ctx: Readonly<PluginContext<DefaultGunshiParams>>) => Awaitable<void>;
|
|
664
686
|
}): PluginWithoutExtension<DefaultGunshiParams['extensions']>;
|
|
665
|
-
|
|
666
687
|
//#endregion
|
|
667
688
|
export { ArgSchema, ArgToken, ArgValues, Args, Awaitable, Command, CommandContext, CommandContextCore, CommandDecorator, CommandExamplesFetcher, CommandRunner, DefaultGunshiParams, ExtendContext, ExtractArgs, GunshiParams, GunshiParamsConstraint, LazyCommand, NormalizeToGunshiParams, OnPluginExtension, Plugin, PluginContext, PluginDependency, PluginExtension, PluginFunction, PluginOptions, PluginWithExtension, PluginWithoutExtension, RendererDecorator, ValidationErrorsDecorator, plugin };
|
package/lib/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gunshi/plugin",
|
|
3
3
|
"description": "utilities for gunshi plugin",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.27.0-alpha.2",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -51,12 +51,12 @@
|
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"deno": "^2.
|
|
55
|
-
"jsr": "^0.13.
|
|
54
|
+
"deno": "^2.4.0",
|
|
55
|
+
"jsr": "^0.13.5",
|
|
56
56
|
"jsr-exports-lint": "^0.4.1",
|
|
57
57
|
"publint": "^0.3.12",
|
|
58
|
-
"tsdown": "^0.12.
|
|
59
|
-
"gunshi": "0.
|
|
58
|
+
"tsdown": "^0.12.9",
|
|
59
|
+
"gunshi": "0.27.0-alpha.2"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "tsdown",
|