@gunshi/plugin-renderer 0.33.0 → 0.35.0

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.
Files changed (3) hide show
  1. package/README.md +20 -13
  2. package/lib/index.js +34 -14
  3. package/package.json +5 -7
package/README.md CHANGED
@@ -38,9 +38,13 @@ const command = define({
38
38
  description: 'Deploy your application',
39
39
  args: {
40
40
  environment: {
41
- type: 'string',
42
- description: 'Target environment',
43
- required: true
41
+ type: 'positional',
42
+ description: 'Target environment'
43
+ },
44
+ region: {
45
+ type: 'positional',
46
+ required: false,
47
+ description: 'Optional deployment region'
44
48
  },
45
49
  force: {
46
50
  type: 'boolean',
@@ -48,9 +52,10 @@ const command = define({
48
52
  description: 'Force deployment without confirmation'
49
53
  }
50
54
  },
51
- examples: '$ deploy production --force',
55
+ examples: ['$ deploy production --force', '$ deploy production us-east-1 --force'],
52
56
  run: async ctx => {
53
- console.log(`Deploying to ${ctx.values.environment}...`)
57
+ const region = ctx.values.region ? ` in ${ctx.values.region}` : ''
58
+ console.log(`Deploying to ${ctx.values.environment}${region}...`)
54
59
  }
55
60
  })
56
61
 
@@ -94,18 +99,20 @@ When a user runs `--help`, the output looks like:
94
99
  ```sh
95
100
  deploy - Deploy your application
96
101
 
97
- USAGE
98
- $ deploy [options] <environment>
102
+ USAGE:
103
+ deploy <OPTIONS> <environment> [<region>]
99
104
 
100
- ARGUMENTS
101
- environment Target environment
105
+ ARGUMENTS:
106
+ environment Target environment
107
+ region Optional deployment region
102
108
 
103
- OPTIONS
104
- -f, --force Force deployment without confirmation
105
- -h, --help Display this help message
109
+ OPTIONS:
110
+ -f, --force Force deployment without confirmation
111
+ -h, --help Display this help message
106
112
 
107
- EXAMPLES
113
+ EXAMPLES:
108
114
  $ deploy production --force
115
+ $ deploy production us-east-1 --force
109
116
  ```
110
117
 
111
118
  ### Exported Functions
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ANONYMOUS_COMMAND_NAME, plugin } from "@gunshi/plugin";
2
- //#region ../../node_modules/.pnpm/args-tokens@0.25.0/node_modules/args-tokens/lib/utils.js
2
+ //#region ../../node_modules/.pnpm/args-tokens@0.27.0/node_modules/args-tokens/lib/utils.js
3
3
  /**
4
4
  * Entry point of utils.
5
5
  *
@@ -303,6 +303,15 @@ const pluginId = namespacedId("renderer");
303
303
  * @license MIT
304
304
  */
305
305
  const COMMON_ARGS_KEYS = Object.keys(COMMON_ARGS);
306
+ function isHiddenArg(schema) {
307
+ return schema.hidden === true;
308
+ }
309
+ function getVisibleOptionalArgs(args) {
310
+ return Object.entries(args).filter(([_, schema]) => schema.type !== "positional" && !isHiddenArg(schema));
311
+ }
312
+ function getVisiblePositionalArgs(args) {
313
+ return Object.entries(args).filter(([_, schema]) => schema.type === "positional" && !isHiddenArg(schema));
314
+ }
306
315
  /**
307
316
  * Render the usage.
308
317
  *
@@ -484,7 +493,7 @@ async function hasCommands(ctx) {
484
493
  * @returns True if the command has options
485
494
  */
486
495
  function hasOptionalArgs(args) {
487
- return Object.values(args).some((arg) => arg.type !== "positional");
496
+ return getVisibleOptionalArgs(args).length > 0;
488
497
  }
489
498
  /**
490
499
  * Check if the command has positional arguments
@@ -493,7 +502,7 @@ function hasOptionalArgs(args) {
493
502
  * @returns True if the command has options
494
503
  */
495
504
  function hasPositionalArgs(args) {
496
- return Object.values(args).some((arg) => arg.type === "positional");
505
+ return getVisiblePositionalArgs(args).length > 0;
497
506
  }
498
507
  /**
499
508
  * Check if all options have default values
@@ -502,7 +511,8 @@ function hasPositionalArgs(args) {
502
511
  * @returns True if all options have default values
503
512
  */
504
513
  function hasAllDefaultOptions(args) {
505
- return !!(args && Object.values(args).every((arg) => arg.default));
514
+ const visibleOptionalArgs = getVisibleOptionalArgs(args);
515
+ return visibleOptionalArgs.length > 0 && visibleOptionalArgs.every(([_, arg]) => arg.default);
506
516
  }
507
517
  /**
508
518
  * Generate options symbols for usage
@@ -512,7 +522,7 @@ function hasAllDefaultOptions(args) {
512
522
  * @returns Options symbols for usage
513
523
  */
514
524
  async function generateOptionsSymbols(ctx, args) {
515
- return hasOptionalArgs(args) ? hasAllDefaultOptions(args) ? `[${await ctx.extensions[pluginId].text(resolveBuiltInKey("OPTIONS"))}]` : `<${await ctx.extensions[pluginId].text(resolveBuiltInKey("OPTIONS"))}>` : "";
525
+ return getVisibleOptionalArgs(args).length > 0 ? hasAllDefaultOptions(args) ? `[${await ctx.extensions[pluginId].text(resolveBuiltInKey("OPTIONS"))}]` : `<${await ctx.extensions[pluginId].text(resolveBuiltInKey("OPTIONS"))}>` : "";
516
526
  }
517
527
  /**
518
528
  * Get optional arguments pairs for usage
@@ -521,8 +531,7 @@ async function generateOptionsSymbols(ctx, args) {
521
531
  * @returns Options pairs for usage
522
532
  */
523
533
  function getOptionalArgsPairs(ctx) {
524
- return Object.entries(ctx.args).reduce((acc, [name, schema]) => {
525
- if (schema.type === "positional") return acc;
534
+ return getVisibleOptionalArgs(ctx.args).reduce((acc, [name, schema]) => {
526
535
  let key = makeShortLongOptionPair(schema, name, ctx.toKebab);
527
536
  if (schema.type !== "boolean") {
528
537
  const displayName = ctx.toKebab || schema.toKebab ? kebabnize(name) : name;
@@ -562,9 +571,11 @@ async function resolveDisplayValue(ctx, key) {
562
571
  * @returns Generated options usage
563
572
  */
564
573
  async function generateOptionalArgsUsage(ctx, optionsPairs) {
565
- const optionsMaxLength = Math.max(...Object.entries(optionsPairs).map(([_, value]) => value.length));
566
- const optionSchemaMaxLength = ctx.env.usageOptionType ? Math.max(...Object.entries(optionsPairs).map(([key]) => resolveNegatableType(key, ctx).length)) : 0;
567
- return (await Promise.all(Object.entries(optionsPairs).map(async ([key, value]) => {
574
+ const optionsPairsEntries = Object.entries(optionsPairs);
575
+ if (optionsPairsEntries.length === 0) return "";
576
+ const optionsMaxLength = Math.max(...optionsPairsEntries.map(([_, value]) => value.length));
577
+ const optionSchemaMaxLength = ctx.env.usageOptionType ? Math.max(...optionsPairsEntries.map(([key]) => resolveNegatableType(key, ctx).length)) : 0;
578
+ return (await Promise.all(optionsPairsEntries.map(async ([key, value]) => {
568
579
  let rawDesc = await ctx.extensions[pluginId].text(resolveArgKey(key, ctx.name));
569
580
  if (!rawDesc && key.startsWith("no-")) {
570
581
  const name = resolveNegatableKey(key);
@@ -581,10 +592,11 @@ async function generateOptionalArgsUsage(ctx, optionsPairs) {
581
592
  }))).join("\n");
582
593
  }
583
594
  function getPositionalArgs(args) {
584
- return Object.entries(args).filter(([_, schema]) => schema.type === "positional");
595
+ return getVisiblePositionalArgs(args);
585
596
  }
586
597
  async function generatePositionalArgsUsage(ctx) {
587
598
  const positionals = getPositionalArgs(ctx.args);
599
+ if (positionals.length === 0) return "";
588
600
  const argsMaxLength = Math.max(...positionals.map(([name]) => name.length));
589
601
  return (await Promise.all(positionals.map(async ([name]) => {
590
602
  const desc = await ctx.extensions[pluginId].text(resolveArgKey(name, ctx.name)) || ctx.args[name].description || "";
@@ -593,13 +605,21 @@ async function generatePositionalArgsUsage(ctx) {
593
605
  }))).join("\n");
594
606
  }
595
607
  function generatePositionalSymbols(args) {
596
- return hasPositionalArgs(args) ? getPositionalArgs(args).map(([name, arg]) => {
608
+ const visiblePositionalArgs = getVisiblePositionalArgs(args);
609
+ return visiblePositionalArgs.length > 0 ? visiblePositionalArgs.map(([name, arg]) => {
597
610
  const elements = [];
598
- if (!arg.multiple || arg.required) elements.push(`<${name}>`);
599
- if (arg.multiple) elements.push(`[<${name}> ...]`);
611
+ if (arg.multiple) {
612
+ if (arg.required) elements.push(`<${name}>`);
613
+ elements.push(`[<${name}> ...]`);
614
+ } else elements.push(isRequiredSinglePositionalArg(arg) ? `<${name}>` : `[<${name}>]`);
600
615
  return elements.join(" ");
601
616
  }).join(" ") : "";
602
617
  }
618
+ function isRequiredSinglePositionalArg(arg) {
619
+ if (arg.required === true) return true;
620
+ if (arg.required === false) return false;
621
+ return arg.default == null;
622
+ }
603
623
  //#endregion
604
624
  //#region src/validation.ts
605
625
  /**
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.33.0",
4
+ "version": "0.35.0",
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": "0.33.0"
56
+ "@gunshi/plugin": "0.35.0"
57
57
  },
58
58
  "peerDependencies": {
59
- "@gunshi/plugin-i18n": "0.33.0"
59
+ "@gunshi/plugin-i18n": "0.35.0"
60
60
  },
61
61
  "devDependencies": {
62
62
  "deno": "^2.7.14",
@@ -64,13 +64,11 @@
64
64
  "jsr-exports-lint": "^0.4.2",
65
65
  "publint": "^0.3.20",
66
66
  "tsdown": "0.21.0",
67
- "typedoc": "^0.28.19",
68
- "typedoc-plugin-markdown": "^4.11.0",
69
- "@gunshi/shared": "0.33.0"
67
+ "@gunshi/shared": "0.35.0"
70
68
  },
71
69
  "scripts": {
72
70
  "build": "tsdown",
73
- "build:docs": "typedoc --excludeInternal",
71
+ "build:docs": "tsx ../../scripts/api-references.ts",
74
72
  "lint:jsr": "jsr publish --dry-run --allow-dirty",
75
73
  "typecheck:deno": "deno check --import-map=../../importmap.json ./src"
76
74
  }