@gunshi/plugin-global 0.27.0-alpha.8 → 0.27.0-beta.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.
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @gunshi/plugin-global
2
2
 
3
+ [![Version][npm-version-src]][npm-version-href]
4
+ [![InstallSize][install-size-src]][install-size-src]
5
+ [![JSR][jsr-src]][jsr-href]
6
+
3
7
  > global options plugin for gunshi.
4
8
 
5
9
  This plugin provides standard global options (`--help` and `--version`) for all commands in your CLI application. It's installed by default in gunshi, ensuring consistent behavior across all CLI applications.
@@ -87,6 +91,13 @@ When using the global options plugin, your command context is extended via `ctx.
87
91
 
88
92
  Available extensions:
89
93
 
94
+ <!-- eslint-disable markdown/no-missing-label-refs -->
95
+
96
+ > [!NOTE]
97
+ > The `Awaitable<T>` type used in the method signatures below is equivalent to `T | Promise<T>`, meaning the methods can return either a value directly or a Promise that resolves to that value.
98
+
99
+ <!-- eslint-enable markdown/no-missing-label-refs -->
100
+
90
101
  - **`showVersion(): string`**: Display the application version. Returns `'unknown'` if no version is specified in the CLI configuration.
91
102
 
92
103
  - **`showHeader(): Awaitable<string | undefined>`**: Display the application header. Returns `undefined` if no `renderHeader` function is provided in the CLI configuration.
@@ -98,14 +109,14 @@ Available extensions:
98
109
  ### Usage Example
99
110
 
100
111
  ```ts
101
- import global, { pluginId } from '@gunshi/plugin-global'
112
+ import global, { pluginId as globalId } from '@gunshi/plugin-global'
102
113
  import { cli } from 'gunshi'
103
114
 
104
115
  const command = {
105
116
  name: 'deploy',
106
117
  run: async ctx => {
107
- // Access globals extensions
108
- const { showVersion, showHeader } = ctx.extensions[pluginId]
118
+ // Access global extensions
119
+ const { showVersion, showHeader } = ctx.extensions[globalId]
109
120
 
110
121
  // Manually show version if needed
111
122
  console.log(`Deploying with CLI version: ${showVersion()}`)
@@ -143,3 +154,11 @@ See the [API References](./docs/index.md)
143
154
  ## ©️ License
144
155
 
145
156
  [MIT](http://opensource.org/licenses/MIT)
157
+
158
+ <!-- Badges -->
159
+
160
+ [npm-version-src]: https://img.shields.io/npm/v/@gunshi/plugin-global?style=flat
161
+ [npm-version-href]: https://npmjs.com/package/@gunshi/plugin-global@alpha
162
+ [jsr-src]: https://jsr.io/badges/@gunshi/plugin-global
163
+ [jsr-href]: https://jsr.io/@gunshi/plugin-global
164
+ [install-size-src]: https://pkg-size.dev/badge/install/39632
package/lib/index.d.ts CHANGED
@@ -6,25 +6,29 @@ import { Awaitable, PluginWithExtension } from "@gunshi/plugin";
6
6
  * Extended command context which provides utilities via global options plugin.
7
7
  * These utilities are available via `CommandContext.extensions['g:global']`.
8
8
  */
9
- interface GlobalCommandContext {
9
+ interface GlobalExtension {
10
10
  /**
11
11
  * Show the version of the application. if `--version` option is specified, it will print the version to the console.
12
+ *
12
13
  * @returns The version of the application, or `unknown` if the version is not specified.
13
14
  */
14
15
  showVersion: () => string;
15
16
  /**
16
17
  * Show the header of the application.
18
+ *
17
19
  * @returns The header of the application, or `undefined` if the `renderHeader` is not specified.
18
20
  */
19
21
  showHeader: () => Awaitable<string | undefined>;
20
22
  /**
21
23
  * Show the usage of the application. if `--help` option is specified, it will print the usage to the console.
24
+ *
22
25
  * @returns The usage of the application, or `undefined` if the `renderUsage` is not specified.
23
26
  */
24
27
  showUsage: () => Awaitable<string | undefined>;
25
28
  /**
26
29
  * Show validation errors. This is called when argument validation fails.
27
- * @param error The aggregate error containing validation failures
30
+ *
31
+ * @param error - The aggregate error containing validation failures
28
32
  * @returns The rendered error message, or `undefined` if `renderValidationErrors` is null
29
33
  */
30
34
  showValidationErrors: (error: AggregateError) => Awaitable<string | undefined>;
@@ -40,13 +44,11 @@ declare const PLUGIN_PREFIX = "g";
40
44
  declare const BUILT_IN_KEY_SEPARATOR = ":";
41
45
  //#endregion
42
46
  //#region ../shared/src/types.d.ts
47
+
43
48
  /**
44
49
  * Generate a namespaced key.
45
50
  */
46
51
  type GenerateNamespacedKey<Key extends string, Prefixed extends string = typeof BUILT_IN_PREFIX> = `${Prefixed}${typeof BUILT_IN_KEY_SEPARATOR}${Key}`;
47
- /**
48
- * Command i18n built-in arguments keys.
49
- */
50
52
  //#endregion
51
53
  //#region src/types.d.ts
52
54
  /**
@@ -61,7 +63,9 @@ type PluginId = typeof pluginId;
61
63
  //#region src/index.d.ts
62
64
  /**
63
65
  * global options plugin
66
+ *
67
+ * @returns A defined plugin as global options
64
68
  */
65
- declare function global(): PluginWithExtension<GlobalCommandContext>;
69
+ declare function global(): PluginWithExtension<GlobalExtension>;
66
70
  //#endregion
67
- export { GlobalCommandContext, PluginId, global as default, pluginId };
71
+ export { type GlobalExtension, PluginId, global as default, pluginId };
package/lib/index.js CHANGED
@@ -26,6 +26,14 @@ const COMMON_ARGS = {
26
26
 
27
27
  //#endregion
28
28
  //#region ../shared/src/utils.ts
29
+ /**
30
+ * Generate a namespaced key for a plugin.
31
+ *
32
+ * @typeParam K - The type of the plugin id to generate a namespaced key for.
33
+ *
34
+ * @param id - A plugin id to generate a namespaced key.
35
+ * @returns A namespaced key for the plugin.
36
+ */
29
37
  function namespacedId(id) {
30
38
  return `${PLUGIN_PREFIX}${BUILT_IN_KEY_SEPARATOR}${id}`;
31
39
  }
@@ -41,6 +49,9 @@ const pluginId = namespacedId("global");
41
49
  //#region src/decorator.ts
42
50
  /**
43
51
  * Decorator function to extend the command with global options.
52
+ *
53
+ * @param baseRunner - The base command runner
54
+ * @returns A command decorator that adds global options handling
44
55
  */
45
56
  const decorator = (baseRunner) => async (ctx) => {
46
57
  const { values, validationError, extensions: { [pluginId]: { showVersion, showHeader, showUsage, showValidationErrors } } } = ctx;
@@ -63,6 +74,12 @@ var decorator_default = decorator;
63
74
 
64
75
  //#endregion
65
76
  //#region src/extension.ts
77
+ /**
78
+ * Extends the command context for global options plugin.
79
+ *
80
+ * @param ctx - The {@linkcode CommandContextCore | command context} core
81
+ * @returns An {@linkcode GlobalExtension} of global options plugin
82
+ */
66
83
  function extension(ctx) {
67
84
  return {
68
85
  showVersion: () => {
@@ -105,6 +122,8 @@ function extension(ctx) {
105
122
  //#region src/index.ts
106
123
  /**
107
124
  * global options plugin
125
+ *
126
+ * @returns A defined plugin as global options
108
127
  */
109
128
  function global() {
110
129
  return plugin({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gunshi/plugin-global",
3
3
  "description": "global options plugin for gunshi",
4
- "version": "0.27.0-alpha.8",
4
+ "version": "0.27.0-beta.0",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -51,22 +51,22 @@
51
51
  }
52
52
  },
53
53
  "dependencies": {
54
- "@gunshi/plugin": "0.27.0-alpha.8"
54
+ "@gunshi/plugin": "0.27.0-beta.0"
55
55
  },
56
56
  "devDependencies": {
57
- "deno": "^2.4.0",
57
+ "deno": "^2.5.4",
58
58
  "jsr": "^0.13.5",
59
59
  "jsr-exports-lint": "^0.4.1",
60
- "publint": "^0.3.12",
61
- "tsdown": "^0.12.9",
62
- "typedoc": "^0.28.7",
63
- "typedoc-plugin-markdown": "^4.7.0",
64
- "@gunshi/shared": "0.27.0-alpha.8"
60
+ "publint": "^0.3.14",
61
+ "tsdown": "^0.15.6",
62
+ "typedoc": "^0.28.13",
63
+ "typedoc-plugin-markdown": "^4.9.0",
64
+ "@gunshi/shared": "0.27.0-beta.0"
65
65
  },
66
66
  "scripts": {
67
67
  "build": "tsdown",
68
68
  "build:docs": "typedoc --excludeInternal",
69
69
  "lint:jsr": "jsr publish --dry-run --allow-dirty",
70
- "typecheck:deno": "deno check ./src"
70
+ "typecheck:deno": "deno check --import-map=../../importmap.json ./src"
71
71
  }
72
72
  }