@gunshi/plugin-i18n 1.0.0-rc.4 → 1.0.0-rc.6

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
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![Version][npm-version-src]][npm-version-href]
4
4
  [![InstallSize][install-size-src]][install-size-src]
5
- [![JSR][jsr-src]][jsr-href]
6
5
 
7
6
  > internationalization (i18n) plugin for gunshi.
8
7
 
@@ -20,9 +19,6 @@ pnpm add @gunshi/plugin-i18n
20
19
  # yarn
21
20
  yarn add @gunshi/plugin-i18n
22
21
 
23
- # deno
24
- deno add jsr:@gunshi/plugin-i18n
25
-
26
22
  # bun
27
23
  bun add @gunshi/plugin-i18n
28
24
  ```
@@ -112,6 +108,7 @@ This means:
112
108
  - If you're using the globals plugin (which adds `--help` and `--version` options), the i18n plugin will automatically handle their translations
113
109
  - The translations for "Display this help message" and "Display this version" will be available in your configured locale
114
110
  - You can override these translations by providing your own `help` and `version` keys in your built-in resources
111
+ - The description of `--json` of a command that spreads `jsonArgs` ("Output the result as JSON") is translated by the `json` key of the built-in resources in the same way, unless the resource of the command has its own `arg:json`
115
112
 
116
113
  Example with globals plugin:
117
114
 
@@ -761,6 +758,4 @@ See the [API References](./docs/index.md)
761
758
 
762
759
  [npm-version-src]: https://img.shields.io/npm/v/@gunshi/plugin-i18n?style=flat
763
760
  [npm-version-href]: https://npmjs.com/package/@gunshi/plugin-i18n@alpha
764
- [jsr-src]: https://jsr.io/badges/@gunshi/plugin-i18n
765
- [jsr-href]: https://jsr.io/@gunshi/plugin-i18n
766
761
  [install-size-src]: https://pkg-size.dev/badge/install/67599
package/lib/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { Args, Awaitable, Command, CommandContext, DefaultGunshiParams, ExtendContext, ExtractArgs, ExtractExtensions, GunshiParams, GunshiParamsConstraint, PluginWithExtension, Prettify } from "@gunshi/plugin";
2
- //#region ../../node_modules/.pnpm/args-tokens@1.0.0/node_modules/args-tokens/lib/resolver.d.ts
3
- //#region src/resolver.d.ts
1
+ import { Args, Awaitable, Command, CommandContext, DefaultGunshiParams, ExtendContext, ExtractArgs, ExtractExtensions, GunshiParams, GunshiParamsConstraint, PluginWithExtension, Prettify, SubCommandable } from "@gunshi/plugin";
2
+ //#region ../../node_modules/.pnpm/args-tokens@1.0.2/node_modules/args-tokens/lib/resolver.d.ts
4
3
  /**
5
4
  * An argument schema definition for command-line argument parsing.
6
5
  *
@@ -362,9 +361,9 @@ interface ArgSchema {
362
361
  */
363
362
  toKebab?: true;
364
363
  /**
365
- * Names of other options that conflict with this option.
364
+ * Names of other arguments that conflict with this argument.
366
365
  *
367
- * When this option is used together with any of the conflicting options, the error is an
366
+ * When this argument is used together with any of the conflicting arguments, the error is an
368
367
  * `ArgResolveError` with type 'conflict' and the code `err:arg:conflict`
369
368
  * ({@link ArgsValidationErrorKeys}.conflict). Its `values` has the `displayName` and `name` of
370
369
  * the argument whose `conflicts` names the other one, and the `conflictDisplayName` and
@@ -374,9 +373,8 @@ interface ArgSchema {
374
373
  *
375
374
  * A positional argument can be on either side, such as `[file]` and `--stdin`. It conflicts when
376
375
  * it is given, and it is shown by its name, such as `'file'` (in kebab-case with `toKebab`), as
377
- * in its other errors. The message starts with the kind of the argument given as `name`:
378
- * `Positional argument 'file' conflicts with '--stdin'` or
379
- * `Optional argument '--stdin' conflicts with 'file'`.
376
+ * in its other errors. The message names the argument given as `name` first:
377
+ * `'file' conflicts with '--stdin'` or `'--stdin' conflicts with 'file'`.
380
378
  *
381
379
  * Conflicts only need to be defined on one side - if option A defines a conflict
382
380
  * with option B, the conflict is automatically detected when both are used,
@@ -415,7 +413,7 @@ interface ArgSchema {
415
413
  * }
416
414
  * }
417
415
  * // Usage: --summer --autumn reports an error
418
- * // Error: "Optional argument '--summer' conflicts with '--autumn'"
416
+ * // Error: "'--summer' conflicts with '--autumn'"
419
417
  * ```
420
418
  *
421
419
  * @example
@@ -455,7 +453,7 @@ interface ArgSchema {
455
453
  * toKebab: true // Accessible as --autumn-season
456
454
  * }
457
455
  * }
458
- * // Error: "Optional argument '--summer-season' conflicts with '--autumn-season'"
456
+ * // Error: "'--summer-season' conflicts with '--autumn-season'"
459
457
  * ```
460
458
  */
461
459
  conflicts?: string | string[];
@@ -625,11 +623,13 @@ type CommonArgType = {
625
623
  };
626
624
  };
627
625
  declare const COMMON_ARGS: CommonArgType;
628
- declare const COMMAND_BUILTIN_RESOURCE_KEYS: readonly ["USAGE", "COMMAND", "SUBCOMMAND", "COMMANDS", "ARGUMENTS", "OPTIONS", "EXAMPLES", "FORMORE", "NEGATABLE", "DEFAULT", "CHOICES"];
626
+ declare const COMMAND_BUILTIN_RESOURCE_KEYS: readonly ["USAGE", "COMMAND", "SUBCOMMAND", "COMMANDS", "ARGUMENTS", "OPTIONS", "EXAMPLES", "FORMORE", "NEGATABLE", "DEFAULT", "CHOICES", "CAUSEDBY"];
629
627
  declare const ARG_ERROR_RESOURCE_KEYS: readonly ["err:arg:required-option", "err:arg:required-positional", "err:arg:invalid-type", "err:arg:invalid-choice", "err:arg:custom-parse", "err:arg:unknown-option", "err:arg:unexpected-value", "err:arg:missing-value", "err:arg:conflict", "err:arg:invalid-default"];
630
628
  declare const ARG_ERROR_HINT_RESOURCE_KEYS: readonly ["err:arg:missing-value:hint"];
631
629
  declare const COMMAND_ERROR_RESOURCE_KEYS: readonly ["err:cmd:not-found", "err:cmd:ambiguous", "err:cmd:inconsistent-options", "err:cmd:lazy-schema-mismatch"];
632
630
  declare const SUGGESTION_ERROR_RESOURCE_KEYS: readonly ["err:suggestion:did-you-mean"];
631
+ declare const JSON_RESOURCE_KEYS: readonly ["json", "json:invalid-arguments", "json:next:help", "json:next:help-placeholder"];
632
+ declare const JSON_ERROR_RESOURCE_KEYS: readonly ["err:json:not-supported", "err:json:invalid-result", "err:json:unserializable-result"];
633
633
  //#endregion
634
634
  //#region ../shared/src/types.d.ts
635
635
  type RemoveIndexSignature<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K]; };
@@ -669,14 +669,23 @@ type CommandErrorResourceKeys = (typeof COMMAND_ERROR_RESOURCE_KEYS)[number];
669
669
  * Suggestion error resource keys.
670
670
  */
671
671
  type SuggestionErrorResourceKeys = (typeof SUGGESTION_ERROR_RESOURCE_KEYS)[number];
672
+ /**
673
+ * Resource keys of the errors of the JSON output.
674
+ */
675
+ type JsonErrorResourceKeys = (typeof JSON_ERROR_RESOURCE_KEYS)[number];
676
+ /**
677
+ * Resource keys of the description of the `json` argument of `jsonArgs`, and of the texts that only
678
+ * the JSON errors print.
679
+ */
680
+ type JsonResourceKeys = (typeof JSON_RESOURCE_KEYS)[number];
672
681
  /**
673
682
  * Error resource keys.
674
683
  */
675
- type ErrorResourceKeys = ArgErrorResourceKeys | ArgErrorHintResourceKeys | CommandErrorResourceKeys | SuggestionErrorResourceKeys;
684
+ type ErrorResourceKeys = ArgErrorResourceKeys | ArgErrorHintResourceKeys | CommandErrorResourceKeys | SuggestionErrorResourceKeys | JsonErrorResourceKeys;
676
685
  /**
677
686
  * Built-in resource keys.
678
687
  */
679
- type BuiltinResourceKeys = ErrorResourceKeys | CommandBuiltinArgsKeys | CommandBuiltinResourceKeys;
688
+ type BuiltinResourceKeys = ErrorResourceKeys | CommandBuiltinArgsKeys | CommandBuiltinResourceKeys | JsonResourceKeys;
680
689
  /**
681
690
  * Built-in resource.
682
691
  */
@@ -918,7 +927,7 @@ type I18nCommandDefinitionResult<G extends GunshiParamsConstraint = DefaultGunsh
918
927
  *
919
928
  * @internal
920
929
  */
921
- type WithI18nResourceResult<G extends GunshiParamsConstraint = DefaultGunshiParams, C extends Command<G> = Command<G>> = Prettify<C & {
930
+ type WithI18nResourceResult<G extends GunshiParamsConstraint = DefaultGunshiParams, C extends Command<G> | SubCommandable = Command<G>> = Prettify<C & {
922
931
  resource: CommandResourceFetcher<G>;
923
932
  } & { [K in Exclude<keyof I18nCommand<G>, keyof C | 'resource'>]?: I18nCommand<G>[K]; }>;
924
933
  /**
@@ -1067,7 +1076,7 @@ declare function defineI18nWithTypes<G extends GunshiParamsConstraint>(): Define
1067
1076
  * @param resource - A {@link CommandResourceFetcher | resource fetcher} for the command
1068
1077
  * @returns A {@link I18nCommand | command} with i18n resource support
1069
1078
  */
1070
- declare function withI18nResource<G extends GunshiParamsConstraint, C extends Command<G>>(command: C, resource: CommandResourceFetcher<G>): WithI18nResourceResult<G, C>;
1079
+ declare function withI18nResource<G extends GunshiParamsConstraint, C extends Command<G> | SubCommandable>(command: C, resource: CommandResourceFetcher<G>): WithI18nResourceResult<G, C>;
1071
1080
  //#endregion
1072
1081
  //#region src/translation.d.ts
1073
1082
  /**
package/lib/index.js CHANGED
@@ -3,6 +3,25 @@ import { plugin } from "@gunshi/plugin";
3
3
  * @author kazuya kawaguchi (a.k.a. kazupon)
4
4
  * @license MIT
5
5
  */
6
+ //#endregion
7
+ //#region ../gunshi/src/utils.ts
8
+ /**
9
+ * @author kazuya kawaguchi (a.k.a. kazupon)
10
+ * @license MIT
11
+ */
12
+ /**
13
+ * Check whether an argument schema is the `json` argument of `jsonArgs`, by its mark.
14
+ *
15
+ * @param schema - An argument schema
16
+ * @returns `true` if the schema has the mark of `jsonArgs`
17
+ */
18
+ function isJsonArg(schema) {
19
+ return typeof schema === "object" && schema !== null && schema["~gunshi.json-arg"] === true;
20
+ }
21
+ /**
22
+ * @author kazuya kawaguchi (a.k.a. kazupon)
23
+ * @license MIT
24
+ */
6
25
  const ARG_PREFIX_AND_KEY_SEPARATOR = `arg:`;
7
26
  const ERROR_PREFIX_AND_KEY_SEPARATOR = `err:`;
8
27
  const COMMON_ARGS = {
@@ -31,16 +50,21 @@ var en_US_default = {
31
50
  NEGATABLE: "Negatable of",
32
51
  DEFAULT: "default",
33
52
  CHOICES: "choices",
53
+ CAUSEDBY: "Caused by",
34
54
  help: "Display this help message",
35
55
  version: "Display this version",
36
- "err:arg:required-option": "Optional argument {$displayName} is required",
56
+ json: "Output the result as JSON",
57
+ "json:invalid-arguments": "{$count} arguments are invalid",
58
+ "json:next:help": "See the arguments of the command",
59
+ "json:next:help-placeholder": "Replace <COMMAND> with how you ran this CLI, to see the arguments of the command",
60
+ "err:arg:required-option": "Option {$displayName} is required",
37
61
  "err:arg:required-positional": "Positional argument {$displayName} is required",
38
62
  "err:arg:invalid-type": "Invalid value for {$displayName}: expected {$expected}",
39
63
  "err:arg:invalid-choice": "Invalid value for {$displayName}: expected one of {$choices}",
40
64
  "err:arg:custom-parse": "Invalid value for {$displayName}: {$reason}",
41
65
  "err:arg:unknown-option": "Unknown option: {$rawName}",
42
- "err:arg:unexpected-value": "Optional argument {$displayName} does not take a value",
43
- "err:arg:missing-value": "Optional argument {$displayName} requires a value",
66
+ "err:arg:unexpected-value": "Option {$displayName} does not take a value",
67
+ "err:arg:missing-value": "Option {$displayName} requires a value",
44
68
  "err:arg:missing-value:hint": "(to pass '{$next}' as its value, write '{$suggestion}')",
45
69
  "err:arg:conflict": "{$displayName} conflicts with {$conflictDisplayName}",
46
70
  "err:arg:invalid-default": "Invalid default for {$displayName}: {$actual} is not one of {$choices}",
@@ -48,6 +72,9 @@ var en_US_default = {
48
72
  "err:cmd:ambiguous": "The command is ambiguous. Move options after the command name: {$candidatePaths}",
49
73
  "err:cmd:inconsistent-options": "The options do not identify a consistent command. Move options after the command name.",
50
74
  "err:cmd:lazy-schema-mismatch": "The lazy command definition does not match its loaded options. Declare leading options in the lazy definition or move options after the command name: {$commandPath}",
75
+ "err:json:not-supported": "This command does not support --json",
76
+ "err:json:invalid-result": "The command finished, but did not return an object to output as JSON. A plugin that decorates the command may have dropped its result",
77
+ "err:json:unserializable-result": "The command finished, but its result cannot be converted to JSON: {$message}",
51
78
  "err:suggestion:did-you-mean": "Did you mean {$name}?"
52
79
  };
53
80
  //#endregion
@@ -139,6 +166,11 @@ function formatResource(resource, values = Object.create(null)) {
139
166
  return values[name] == null ? "" : String(values[name]);
140
167
  });
141
168
  }
169
+ /**
170
+ * @author kazuya kawaguchi (a.k.a. kazupon)
171
+ * @license MIT
172
+ */
173
+ namespacedId("i18n");
142
174
  //#endregion
143
175
  //#region ../shared/src/index.ts
144
176
  /**
@@ -449,6 +481,16 @@ function i18n(options = {}) {
449
481
  if (originalResource) loaded = true;
450
482
  const localeStr = toLocaleString(locale);
451
483
  const resource = originalResource ? await normalizeResource(originalResource, ctx) : Object.create(null);
484
+ /**
485
+ * NOTE(kazupon): the `json` argument of `jsonArgs` is described by the built-in resources, as the
486
+ * global options are, unless the resource of the command describes it. A command without a
487
+ * translation of its own keeps the English description of `jsonArgs`.
488
+ */
489
+ if (isJsonArg(ctx.args.json)) {
490
+ const jsonKey = resolveArgKey("json", ctx.name);
491
+ const description = builtinResources[localeStr]?.json;
492
+ if (resource[jsonKey] === void 0 && description) resource[jsonKey] = description;
493
+ }
452
494
  for (const globalOption of getGlobalOptions()) if (globalOptionResources.has(globalOption)) {
453
495
  const optionResource = globalOptionResources.get(globalOption);
454
496
  const globalOptionKey = resolveArgKey(globalOption, ctx.name);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gunshi/plugin-i18n",
3
3
  "description": "internationalization plugin for gunshi",
4
- "version": "1.0.0-rc.4",
4
+ "version": "1.0.0-rc.6",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -53,10 +53,10 @@
53
53
  }
54
54
  },
55
55
  "dependencies": {
56
- "@gunshi/plugin": "1.0.0-rc.4"
56
+ "@gunshi/plugin": "1.0.0-rc.6"
57
57
  },
58
58
  "peerDependencies": {
59
- "@gunshi/plugin-global": "1.0.0-rc.4"
59
+ "@gunshi/plugin-global": "1.0.0-rc.6"
60
60
  },
61
61
  "peerDependenciesMeta": {
62
62
  "@gunshi/plugin-global": {
@@ -64,24 +64,19 @@
64
64
  }
65
65
  },
66
66
  "devDependencies": {
67
- "@gunshi/bone": "1.0.0-rc.4",
68
- "@gunshi/plugin-global": "1.0.0-rc.4",
69
- "@gunshi/plugin-renderer": "1.0.0-rc.4",
70
- "@gunshi/resources": "1.0.0-rc.4",
71
- "@gunshi/shared": "1.0.0-rc.4",
67
+ "@gunshi/bone": "1.0.0-rc.6",
68
+ "@gunshi/plugin-global": "1.0.0-rc.6",
69
+ "@gunshi/plugin-renderer": "1.0.0-rc.6",
70
+ "@gunshi/resources": "1.0.0-rc.6",
71
+ "@gunshi/shared": "1.0.0-rc.6",
72
72
  "@intlify/core-base": "12.0.0-alpha.7",
73
- "deno": "^2.7.14",
74
- "gunshi": "1.0.0-rc.4",
75
- "jsr": "^0.14.3",
76
- "jsr-exports-lint": "^0.4.2",
73
+ "gunshi": "1.0.0-rc.6",
77
74
  "messageformat": "4.1.0",
78
75
  "publint": "^0.3.20",
79
76
  "tsdown": "0.22.14"
80
77
  },
81
78
  "scripts": {
82
79
  "build": "tsdown",
83
- "build:docs": "tsx ../../scripts/api-references.ts",
84
- "lint:jsr": "jsr publish --dry-run --allow-dirty",
85
- "typecheck:deno": "deno check --import-map=../../importmap.json ./src"
80
+ "build:docs": "tsx ../../scripts/api-references.ts"
86
81
  }
87
82
  }