@gunshi/plugin-renderer 0.27.0-beta.3 → 0.27.0-beta.4

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 CHANGED
@@ -42,7 +42,7 @@ type RemovedIndex<T> = RemoveIndexSignature<{ [K in keyof T]: T[K] }>;
42
42
  /**
43
43
  * Resolve a key on {@link Args}.
44
44
  */
45
- type KeyOfArgs<A extends Args$1> = keyof A | { [K in keyof A]: A[K]['type'] extends 'boolean' ? A[K]['negatable'] extends true ? `no-${Extract<K, string>}` : never : never }[keyof A];
45
+ type KeyOfArgs<A$1 extends Args$1> = keyof A$1 | { [K in keyof A$1]: A$1[K]['type'] extends 'boolean' ? A$1[K]['negatable'] extends true ? `no-${Extract<K, string>}` : never : never }[keyof A$1];
46
46
  /**
47
47
  * Generate a namespaced key.
48
48
  */
@@ -67,19 +67,19 @@ type CommandBuiltinKeys = GenerateNamespacedKey<BuiltinResourceKeys>;
67
67
  * Command i18n option keys.
68
68
  * The command i18n option keys are used by the i18n plugin for translation.
69
69
  */
70
- type CommandArgKeys<A extends Args$1, C = {}, K extends string = GenerateNamespacedKey<Extract<KeyOfArgs<RemovedIndex<A>>, string>, typeof ARG_PREFIX>> = C extends {
70
+ type CommandArgKeys<A$1 extends Args$1, C = {}, K$1 extends string = GenerateNamespacedKey<Extract<KeyOfArgs<RemovedIndex<A$1>>, string>, typeof ARG_PREFIX>> = C extends {
71
71
  name: infer N;
72
- } ? (N extends string ? GenerateNamespacedKey<K, N> : K) : K;
72
+ } ? (N extends string ? GenerateNamespacedKey<K$1, N> : K$1) : K$1;
73
73
  /**
74
74
  * Resolve translation keys for command context.
75
75
  */
76
- type ResolveTranslationKeys<A extends Args$1, C = {},
76
+ type ResolveTranslationKeys<A$1 extends Args$1, C = {},
77
77
  // for CommandContext
78
- E extends Record<string, string> = {},
78
+ E$1 extends Record<string, string> = {},
79
79
  // for extended resources
80
- R extends string = keyof RemovedIndex<E>, T extends string = (C extends {
80
+ R extends string = keyof RemovedIndex<E$1>, T extends string = (C extends {
81
81
  name: infer N;
82
- } ? N extends string ? GenerateNamespacedKey<R, N> : R : R | CommandBuiltinKeys), O = CommandArgKeys<A, C>> = CommandBuiltinKeys | O | T;
82
+ } ? N extends string ? GenerateNamespacedKey<R, N> : R : R | CommandBuiltinKeys), O = CommandArgKeys<A$1, C>> = CommandBuiltinKeys | O | T;
83
83
  //#endregion
84
84
  //#region src/types.d.ts
85
85
  /**
@@ -108,11 +108,11 @@ interface UsageRendererExtension<G extends GunshiParams<any> = DefaultGunshiPara
108
108
  * @param values - An optional record of values to interpolate into the translation string.
109
109
  * @returns The resolved translation string with interpolated values if provided.
110
110
  */
111
- text: <A extends Args = G['args'], C = {},
111
+ text: <A$1 extends Args = G['args'], C = {},
112
112
  // for CommandContext
113
- E extends Record<string, string> = {},
113
+ E$1 extends Record<string, string> = {},
114
114
  // for extended resources
115
- K = ResolveTranslationKeys<A, C, E>>(key: K, values?: Record<string, unknown>) => string;
115
+ K$1 = ResolveTranslationKeys<A$1, C, E$1>>(key: K$1, values?: Record<string, unknown>) => Promise<string>;
116
116
  /**
117
117
  * Load commands
118
118
  *
package/lib/index.js CHANGED
@@ -127,38 +127,30 @@ const COMMON_ARGS = {
127
127
 
128
128
  //#endregion
129
129
  //#region ../resources/locales/en-US.json
130
- var COMMAND = "COMMAND";
131
- var COMMANDS = "COMMANDS";
132
- var SUBCOMMAND = "SUBCOMMAND";
133
- var USAGE = "USAGE";
134
- var ARGUMENTS = "ARGUMENTS";
135
- var OPTIONS = "OPTIONS";
136
- var EXAMPLES = "EXAMPLES";
137
- var FORMORE = "For more info, run any command with the `--help` flag";
138
130
  var NEGATABLE = "Negatable of";
139
- var DEFAULT = "default";
140
- var CHOICES = "choices";
141
- var help = "Display this help message";
142
- var version = "Display this version";
143
131
  var en_US_default = {
144
- COMMAND,
145
- COMMANDS,
146
- SUBCOMMAND,
147
- USAGE,
148
- ARGUMENTS,
149
- OPTIONS,
150
- EXAMPLES,
151
- FORMORE,
132
+ COMMAND: "COMMAND",
133
+ COMMANDS: "COMMANDS",
134
+ SUBCOMMAND: "SUBCOMMAND",
135
+ USAGE: "USAGE",
136
+ ARGUMENTS: "ARGUMENTS",
137
+ OPTIONS: "OPTIONS",
138
+ EXAMPLES: "EXAMPLES",
139
+ FORMORE: "For more info, run any command with the `--help` flag",
152
140
  NEGATABLE,
153
- DEFAULT,
154
- CHOICES,
155
- help,
156
- version
141
+ DEFAULT: "default",
142
+ CHOICES: "choices",
143
+ help: "Display this help message",
144
+ version: "Display this version"
157
145
  };
158
146
 
159
147
  //#endregion
160
148
  //#region ../shared/src/utils.ts
161
149
  /**
150
+ * @author kazuya kawaguchi (a.k.a. kazupon)
151
+ * @license MIT
152
+ */
153
+ /**
162
154
  * Resolve a namespaced key for built-in resources.
163
155
  *
164
156
  * Built-in keys are prefixed with "_:".
@@ -240,6 +232,10 @@ function makeShortLongOptionPair(schema, name, toKebab) {
240
232
  //#endregion
241
233
  //#region ../shared/src/localization.ts
242
234
  /**
235
+ * @author kazuya kawaguchi (a.k.a. kazupon)
236
+ * @license MIT
237
+ */
238
+ /**
243
239
  * Create a localizable function for a command.
244
240
  *
245
241
  * This function will resolve the translation key based on the command context and the provided translation function.
@@ -267,7 +263,7 @@ function localizable(ctx, cmd, translate) {
267
263
  }
268
264
  const schema = ctx.args[argKey];
269
265
  if (!schema) return argKey;
270
- return negatable && schema.type === "boolean" && schema.negatable ? `${en_US_default["NEGATABLE"]} ${makeShortLongOptionPair(schema, argKey, ctx.toKebab)}` : schema.description || "";
266
+ return negatable && schema.type === "boolean" && schema.negatable ? `${NEGATABLE} ${makeShortLongOptionPair(schema, argKey, ctx.toKebab)}` : schema.description || "";
271
267
  }
272
268
  if (key === resolveKey("description", ctx.name)) return "";
273
269
  else if (key === resolveKey("examples", ctx.name)) return await resolveExamples(ctx, cmd.examples);
@@ -292,12 +288,20 @@ function renderHeader(ctx) {
292
288
  //#endregion
293
289
  //#region src/types.ts
294
290
  /**
291
+ * @author kazuya kawaguchi (a.k.a. kazupon)
292
+ * @license MIT
293
+ */
294
+ /**
295
295
  * The unique identifier for usage renderer plugin.
296
296
  */
297
297
  const pluginId = namespacedId("renderer");
298
298
 
299
299
  //#endregion
300
300
  //#region src/usage.ts
301
+ /**
302
+ * @author kazuya kawaguchi (a.k.a. kazupon)
303
+ * @license MIT
304
+ */
301
305
  const COMMON_ARGS_KEYS = Object.keys(COMMON_ARGS);
302
306
  /**
303
307
  * Render the usage.
@@ -607,6 +611,35 @@ function renderValidationErrors(_ctx, error) {
607
611
 
608
612
  //#endregion
609
613
  //#region src/index.ts
614
+ /**
615
+ * The entry point of usage renderer plugin
616
+ *
617
+ * @example
618
+ * ```js
619
+ * import renderer from '@gunshi/plugin-renderer'
620
+ * import { cli } from 'gunshi'
621
+ *
622
+ * const entry = (ctx) => {
623
+ * // ...
624
+ * }
625
+ *
626
+ * await cli(process.argv.slice(2), entry, {
627
+ * // ...
628
+ *
629
+ * plugins: [
630
+ * renderer()
631
+ * ],
632
+ *
633
+ * // ...
634
+ * })
635
+ * ```
636
+ *
637
+ * @module
638
+ */
639
+ /**
640
+ * @author kazuya kawaguchi (a.k.a. kazupon)
641
+ * @license MIT
642
+ */
610
643
  const i18nPluginId = namespacedId("i18n");
611
644
  const dependencies = [{
612
645
  id: i18nPluginId,
@@ -622,7 +655,7 @@ function renderer() {
622
655
  id: pluginId,
623
656
  name: "usage renderer",
624
657
  dependencies,
625
- extension: async (ctx, cmd) => {
658
+ extension: (ctx, cmd) => {
626
659
  const i18n = ctx.extensions[i18nPluginId];
627
660
  let cachedCommands;
628
661
  async function loadCommands() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gunshi/plugin-renderer",
3
3
  "description": "usage renderer plugin for gunshi",
4
- "version": "0.27.0-beta.3",
4
+ "version": "0.27.0-beta.4",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -53,20 +53,20 @@
53
53
  }
54
54
  },
55
55
  "dependencies": {
56
- "@gunshi/plugin": "0.27.0-beta.3"
56
+ "@gunshi/plugin": "0.27.0-beta.4"
57
57
  },
58
58
  "peerDependencies": {
59
- "@gunshi/plugin-i18n": "0.27.0-beta.3"
59
+ "@gunshi/plugin-i18n": "0.27.0-beta.4"
60
60
  },
61
61
  "devDependencies": {
62
- "deno": "^2.5.4",
62
+ "deno": "^2.5.6",
63
63
  "jsr": "^0.13.5",
64
64
  "jsr-exports-lint": "^0.4.1",
65
- "publint": "^0.3.14",
66
- "tsdown": "0.15.9",
67
- "typedoc": "^0.28.13",
65
+ "publint": "^0.3.15",
66
+ "tsdown": "0.15.12",
67
+ "typedoc": "^0.28.15",
68
68
  "typedoc-plugin-markdown": "^4.9.0",
69
- "@gunshi/shared": "0.27.0-beta.3"
69
+ "@gunshi/shared": "0.27.0-beta.4"
70
70
  },
71
71
  "scripts": {
72
72
  "build": "tsdown",