@gunshi/plugin 0.27.0-alpha.8 → 0.27.0-alpha.9
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 +40 -6
- package/lib/index.js +15 -2
- package/package.json +4 -4
package/lib/index.d.ts
CHANGED
|
@@ -278,12 +278,12 @@ type PluginFunction<G extends GunshiParams = DefaultGunshiParams> = (ctx: Readon
|
|
|
278
278
|
* Plugin extension for CommandContext
|
|
279
279
|
* @since v0.27.0
|
|
280
280
|
*/
|
|
281
|
-
type PluginExtension<T = Record<string, unknown>, G extends GunshiParams = DefaultGunshiParams> = (ctx: CommandContextCore<G>, cmd: Command<G>) => T
|
|
281
|
+
type PluginExtension<T = Record<string, unknown>, G extends GunshiParams = DefaultGunshiParams> = (ctx: CommandContextCore<G>, cmd: Command<G>) => Awaitable<T>;
|
|
282
282
|
/**
|
|
283
283
|
* Plugin extension callback type
|
|
284
284
|
* @since v0.27.0
|
|
285
285
|
*/
|
|
286
|
-
type OnPluginExtension<G extends GunshiParams = DefaultGunshiParams> = (ctx: Readonly<CommandContext<G>>, cmd: Readonly<Command<G>>) => void
|
|
286
|
+
type OnPluginExtension<G extends GunshiParams = DefaultGunshiParams> = (ctx: Readonly<CommandContext<G>>, cmd: Readonly<Command<G>>) => Awaitable<void>;
|
|
287
287
|
/**
|
|
288
288
|
* Plugin definition options
|
|
289
289
|
* @since v0.27.0
|
|
@@ -357,14 +357,14 @@ declare function plugin<I extends string, P extends PluginExtension<any, Default
|
|
|
357
357
|
dependencies?: (PluginDependency | string)[];
|
|
358
358
|
setup?: (ctx: Readonly<PluginContext<GunshiParams<{
|
|
359
359
|
args: Args;
|
|
360
|
-
extensions: { [K in I]: ReturnType<P
|
|
360
|
+
extensions: { [K in I]: Awaited<ReturnType<P>> };
|
|
361
361
|
}>>>) => Awaitable<void>;
|
|
362
362
|
extension: P;
|
|
363
363
|
onExtension?: OnPluginExtension<{
|
|
364
364
|
args: Args;
|
|
365
|
-
extensions: { [K in I]: ReturnType<P
|
|
365
|
+
extensions: { [K in I]: Awaited<ReturnType<P>> };
|
|
366
366
|
}>;
|
|
367
|
-
}): PluginWithExtension<ReturnType<P
|
|
367
|
+
}): PluginWithExtension<Awaited<ReturnType<P>>>;
|
|
368
368
|
/**
|
|
369
369
|
* Define a plugin without extension capabilities
|
|
370
370
|
* @param options - {@link PluginOptions | plugin options} without extension
|
|
@@ -376,6 +376,7 @@ declare function plugin(options: {
|
|
|
376
376
|
name?: string;
|
|
377
377
|
dependencies?: (PluginDependency | string)[];
|
|
378
378
|
setup?: (ctx: Readonly<PluginContext<DefaultGunshiParams>>) => Awaitable<void>;
|
|
379
|
+
onExtension?: OnPluginExtension<DefaultGunshiParams>;
|
|
379
380
|
}): PluginWithoutExtension<DefaultGunshiParams['extensions']>;
|
|
380
381
|
//#endregion
|
|
381
382
|
//#region ../gunshi/src/types.d.ts
|
|
@@ -732,6 +733,33 @@ interface CommandContextExtension<E extends GunshiParams['extensions'] = Default
|
|
|
732
733
|
readonly factory: (ctx: CommandContextCore, cmd: Command) => Awaitable<E>;
|
|
733
734
|
readonly onFactory?: (ctx: Readonly<CommandContext>, cmd: Readonly<Command>) => Awaitable<void>;
|
|
734
735
|
}
|
|
736
|
+
/**
|
|
737
|
+
* Rendering control options
|
|
738
|
+
* @since v0.27.0
|
|
739
|
+
*/
|
|
740
|
+
interface RenderingOptions<G extends GunshiParamsConstraint = DefaultGunshiParams> {
|
|
741
|
+
/**
|
|
742
|
+
* Header rendering configuration
|
|
743
|
+
* - `null`: Disable rendering
|
|
744
|
+
* - `function`: Use custom renderer
|
|
745
|
+
* - `undefined` (when omitted): Use default renderer
|
|
746
|
+
*/
|
|
747
|
+
header?: ((ctx: Readonly<CommandContext<G>>) => Promise<string>) | null;
|
|
748
|
+
/**
|
|
749
|
+
* Usage rendering configuration
|
|
750
|
+
* - `null`: Disable rendering
|
|
751
|
+
* - `function`: Use custom renderer
|
|
752
|
+
* - `undefined` (when omitted): Use default renderer
|
|
753
|
+
*/
|
|
754
|
+
usage?: ((ctx: Readonly<CommandContext<G>>) => Promise<string>) | null;
|
|
755
|
+
/**
|
|
756
|
+
* Validation errors rendering configuration
|
|
757
|
+
* - `null`: Disable rendering
|
|
758
|
+
* - `function`: Use custom renderer
|
|
759
|
+
* - `undefined` (when omitted): Use default renderer
|
|
760
|
+
*/
|
|
761
|
+
validationErrors?: ((ctx: Readonly<CommandContext<G>>, error: AggregateError) => Promise<string>) | null;
|
|
762
|
+
}
|
|
735
763
|
/**
|
|
736
764
|
* Command interface.
|
|
737
765
|
*/
|
|
@@ -778,6 +806,11 @@ interface Command<G extends GunshiParamsConstraint = DefaultGunshiParams> {
|
|
|
778
806
|
* @since v0.27.0
|
|
779
807
|
*/
|
|
780
808
|
entry?: boolean;
|
|
809
|
+
/**
|
|
810
|
+
* Rendering control options
|
|
811
|
+
* @since v0.27.0
|
|
812
|
+
*/
|
|
813
|
+
rendering?: RenderingOptions<G>;
|
|
781
814
|
}
|
|
782
815
|
/**
|
|
783
816
|
* Lazy command interface.
|
|
@@ -845,6 +878,7 @@ type RendererDecorator<T, G extends GunshiParamsConstraint = DefaultGunshiParams
|
|
|
845
878
|
type ValidationErrorsDecorator<G extends GunshiParamsConstraint = DefaultGunshiParams> = (baseRenderer: (ctx: Readonly<CommandContext<G>>, error: AggregateError) => Promise<string>, ctx: Readonly<CommandContext<G>>, error: AggregateError) => Promise<string>;
|
|
846
879
|
//#endregion
|
|
847
880
|
//#region ../gunshi/src/constants.d.ts
|
|
881
|
+
declare const ANONYMOUS_COMMAND_NAME = "(anonymous)";
|
|
848
882
|
declare const CLI_OPTIONS_DEFAULT: CliOptions<DefaultGunshiParams>;
|
|
849
883
|
//#endregion
|
|
850
884
|
//#region ../gunshi/src/context.d.ts
|
|
@@ -936,4 +970,4 @@ declare function createCommandContext<G extends GunshiParamsConstraint = Default
|
|
|
936
970
|
extensions: ExtractExtensions<E>;
|
|
937
971
|
}>>>>;
|
|
938
972
|
//#endregion
|
|
939
|
-
export { ArgSchema, ArgToken, ArgValues, Args, Awaitable, CLI_OPTIONS_DEFAULT, Command, CommandContext, CommandContextCore, CommandDecorator, CommandExamplesFetcher, CommandRunner, DefaultGunshiParams, ExtendContext, ExtractArgs, GunshiParams, GunshiParamsConstraint, LazyCommand, NormalizeToGunshiParams, OnPluginExtension, Plugin, PluginContext, PluginDependency, PluginExtension, PluginFunction, PluginOptions, PluginWithExtension, PluginWithoutExtension, RendererDecorator, ValidationErrorsDecorator, createCommandContext, plugin };
|
|
973
|
+
export { ANONYMOUS_COMMAND_NAME, type ArgSchema, type ArgToken, type ArgValues, type Args, Awaitable, CLI_OPTIONS_DEFAULT, Command, CommandContext, CommandContextCore, CommandContextExtension, CommandDecorator, CommandExamplesFetcher, CommandRunner, DefaultGunshiParams, ExtendContext, ExtractArgs, GunshiParams, GunshiParamsConstraint, LazyCommand, NormalizeToGunshiParams, OnPluginExtension, Plugin, PluginContext, PluginDependency, PluginExtension, PluginFunction, PluginOptions, PluginWithExtension, PluginWithoutExtension, RendererDecorator, ValidationErrorsDecorator, createCommandContext, plugin };
|
package/lib/index.js
CHANGED
|
@@ -59,6 +59,15 @@ async function createCommandContext({ args, explicit, values, positionals, rest,
|
|
|
59
59
|
*/
|
|
60
60
|
const env = Object.assign(create(), CLI_OPTIONS_DEFAULT, cliOptions);
|
|
61
61
|
/**
|
|
62
|
+
* apply Command definition's rendering option with highest priority
|
|
63
|
+
*/
|
|
64
|
+
if (command.rendering) {
|
|
65
|
+
const { header, usage, validationErrors } = command.rendering;
|
|
66
|
+
if (header !== void 0) env.renderHeader = header;
|
|
67
|
+
if (usage !== void 0) env.renderUsage = usage;
|
|
68
|
+
if (validationErrors !== void 0) env.renderValidationErrors = validationErrors;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
62
71
|
* create the command context
|
|
63
72
|
*/
|
|
64
73
|
const core = Object.assign(create(), {
|
|
@@ -105,6 +114,9 @@ function getCommandName(cmd) {
|
|
|
105
114
|
|
|
106
115
|
//#endregion
|
|
107
116
|
//#region ../gunshi/src/plugin/core.ts
|
|
117
|
+
const NOOP_EXTENSION = () => {
|
|
118
|
+
return Object.create(null);
|
|
119
|
+
};
|
|
108
120
|
/**
|
|
109
121
|
* Define a plugin
|
|
110
122
|
* @param options - {@link PluginOptions | plugin options}
|
|
@@ -112,7 +124,8 @@ function getCommandName(cmd) {
|
|
|
112
124
|
* @since v0.27.0
|
|
113
125
|
*/
|
|
114
126
|
function plugin(options) {
|
|
115
|
-
const { id, name, setup,
|
|
127
|
+
const { id, name, setup, onExtension, dependencies } = options;
|
|
128
|
+
const extension = options.extension || NOOP_EXTENSION;
|
|
116
129
|
const pluginFn = async (ctx) => {
|
|
117
130
|
if (setup) await setup(ctx);
|
|
118
131
|
};
|
|
@@ -149,4 +162,4 @@ function plugin(options) {
|
|
|
149
162
|
}
|
|
150
163
|
|
|
151
164
|
//#endregion
|
|
152
|
-
export { CLI_OPTIONS_DEFAULT, createCommandContext, plugin };
|
|
165
|
+
export { ANONYMOUS_COMMAND_NAME, CLI_OPTIONS_DEFAULT, createCommandContext, plugin };
|
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.27.0-alpha.
|
|
4
|
+
"version": "0.27.0-alpha.9",
|
|
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.4.
|
|
54
|
+
"deno": "^2.4.2",
|
|
55
55
|
"jsr": "^0.13.5",
|
|
56
56
|
"jsr-exports-lint": "^0.4.1",
|
|
57
57
|
"publint": "^0.3.12",
|
|
58
|
-
"tsdown": "^0.
|
|
59
|
-
"gunshi": "0.27.0-alpha.
|
|
58
|
+
"tsdown": "^0.13.0",
|
|
59
|
+
"gunshi": "0.27.0-alpha.9"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "tsdown",
|