@nuxt/ui 3.0.0-alpha.0 → 3.0.0-alpha.1

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 (170) hide show
  1. package/README.md +1 -1
  2. package/cli/node_modules/.ignored/citty/LICENSE +36 -0
  3. package/cli/node_modules/.ignored/citty/README.md +134 -0
  4. package/cli/node_modules/.ignored/citty/dist/index.cjs +475 -0
  5. package/cli/node_modules/.ignored/citty/dist/index.d.cts +80 -0
  6. package/cli/node_modules/.ignored/citty/dist/index.d.mts +80 -0
  7. package/cli/node_modules/.ignored/citty/dist/index.d.ts +80 -0
  8. package/cli/node_modules/.ignored/citty/dist/index.mjs +463 -0
  9. package/cli/node_modules/.ignored/citty/package.json +49 -0
  10. package/cli/node_modules/.ignored/consola/LICENSE +47 -0
  11. package/cli/node_modules/.ignored/consola/README.md +318 -0
  12. package/cli/node_modules/.ignored/consola/core.d.ts +1 -0
  13. package/cli/node_modules/.ignored/consola/dist/basic.cjs +32 -0
  14. package/cli/node_modules/.ignored/consola/dist/basic.d.ts +9 -0
  15. package/cli/node_modules/.ignored/consola/dist/basic.mjs +24 -0
  16. package/cli/node_modules/.ignored/consola/dist/browser.cjs +80 -0
  17. package/cli/node_modules/.ignored/consola/dist/browser.d.ts +7 -0
  18. package/cli/node_modules/.ignored/consola/dist/browser.mjs +72 -0
  19. package/cli/node_modules/.ignored/consola/dist/chunks/prompt.cjs +436 -0
  20. package/cli/node_modules/.ignored/consola/dist/chunks/prompt.mjs +429 -0
  21. package/cli/node_modules/.ignored/consola/dist/core.cjs +415 -0
  22. package/cli/node_modules/.ignored/consola/dist/core.d.ts +124 -0
  23. package/cli/node_modules/.ignored/consola/dist/core.mjs +410 -0
  24. package/cli/node_modules/.ignored/consola/dist/index.cjs +21 -0
  25. package/cli/node_modules/.ignored/consola/dist/index.d.ts +9 -0
  26. package/cli/node_modules/.ignored/consola/dist/index.mjs +8 -0
  27. package/cli/node_modules/.ignored/consola/dist/shared/consola.06ad8a64.mjs +62 -0
  28. package/cli/node_modules/.ignored/consola/dist/shared/consola.36c0034f.mjs +636 -0
  29. package/cli/node_modules/.ignored/consola/dist/shared/consola.4bbae468.cjs +645 -0
  30. package/cli/node_modules/.ignored/consola/dist/shared/consola.deac7d5a.cjs +65 -0
  31. package/cli/node_modules/.ignored/consola/dist/utils.cjs +308 -0
  32. package/cli/node_modules/.ignored/consola/dist/utils.d.ts +169 -0
  33. package/cli/node_modules/.ignored/consola/dist/utils.mjs +284 -0
  34. package/cli/node_modules/.ignored/consola/lib/index.cjs +9 -0
  35. package/cli/node_modules/.ignored/consola/package.json +101 -0
  36. package/cli/node_modules/.ignored/consola/utils.d.ts +1 -0
  37. package/cli/node_modules/.ignored/pathe/LICENSE +44 -0
  38. package/cli/node_modules/.ignored/pathe/README.md +69 -0
  39. package/cli/node_modules/.ignored/pathe/dist/index.cjs +23 -0
  40. package/cli/node_modules/.ignored/pathe/dist/index.d.cts +36 -0
  41. package/cli/node_modules/.ignored/pathe/dist/index.d.mts +36 -0
  42. package/cli/node_modules/.ignored/pathe/dist/index.d.ts +36 -0
  43. package/cli/node_modules/.ignored/pathe/dist/index.mjs +1 -0
  44. package/cli/node_modules/.ignored/pathe/dist/shared/pathe.1f0a373c.cjs +238 -0
  45. package/cli/node_modules/.ignored/pathe/dist/shared/pathe.ff20891b.mjs +221 -0
  46. package/cli/node_modules/.ignored/pathe/dist/utils.cjs +58 -0
  47. package/cli/node_modules/.ignored/pathe/dist/utils.d.cts +5 -0
  48. package/cli/node_modules/.ignored/pathe/dist/utils.d.mts +5 -0
  49. package/cli/node_modules/.ignored/pathe/dist/utils.d.ts +5 -0
  50. package/cli/node_modules/.ignored/pathe/dist/utils.mjs +54 -0
  51. package/cli/node_modules/.ignored/pathe/package.json +48 -0
  52. package/cli/node_modules/.ignored/pathe/utils.d.ts +1 -0
  53. package/cli/node_modules/.ignored/scule/LICENSE +21 -0
  54. package/cli/node_modules/.ignored/scule/README.md +149 -0
  55. package/cli/node_modules/.ignored/scule/dist/index.cjs +92 -0
  56. package/cli/node_modules/.ignored/scule/dist/index.d.cts +57 -0
  57. package/cli/node_modules/.ignored/scule/dist/index.d.mts +57 -0
  58. package/cli/node_modules/.ignored/scule/dist/index.d.ts +57 -0
  59. package/cli/node_modules/.ignored/scule/dist/index.mjs +80 -0
  60. package/cli/node_modules/.ignored/scule/package.json +43 -0
  61. package/cli/node_modules/.package-lock.json +33 -0
  62. package/dist/module.json +3 -3
  63. package/dist/module.mjs +7 -55
  64. package/dist/runtime/components/Accordion.vue +49 -6
  65. package/dist/runtime/components/Alert.vue +58 -6
  66. package/dist/runtime/components/App.vue +12 -2
  67. package/dist/runtime/components/Avatar.vue +27 -6
  68. package/dist/runtime/components/AvatarGroup.vue +30 -6
  69. package/dist/runtime/components/Badge.vue +28 -6
  70. package/dist/runtime/components/Breadcrumb.vue +44 -6
  71. package/dist/runtime/components/Button.vue +33 -6
  72. package/dist/runtime/components/ButtonGroup.vue +30 -6
  73. package/dist/runtime/components/Card.vue +25 -6
  74. package/dist/runtime/components/Checkbox.vue +45 -6
  75. package/dist/runtime/components/Chip.vue +39 -6
  76. package/dist/runtime/components/Collapsible.vue +27 -6
  77. package/dist/runtime/components/CommandPalette.vue +99 -6
  78. package/dist/runtime/components/Container.vue +22 -6
  79. package/dist/runtime/components/ContextMenu.vue +58 -6
  80. package/dist/runtime/components/ContextMenuContent.vue +18 -4
  81. package/dist/runtime/components/Drawer.vue +48 -6
  82. package/dist/runtime/components/DropdownMenu.vue +66 -6
  83. package/dist/runtime/components/DropdownMenuContent.vue +22 -4
  84. package/dist/runtime/components/Form.vue +34 -13
  85. package/dist/runtime/components/FormField.vue +41 -16
  86. package/dist/runtime/components/Icon.vue +12 -2
  87. package/dist/runtime/components/Input.vue +46 -6
  88. package/dist/runtime/components/InputMenu.vue +113 -6
  89. package/dist/runtime/components/Kbd.vue +28 -6
  90. package/dist/runtime/components/Link.vue +81 -17
  91. package/dist/runtime/components/LinkBase.vue +12 -2
  92. package/dist/runtime/components/Modal.vue +69 -6
  93. package/dist/runtime/components/NavigationMenu.vue +76 -6
  94. package/dist/runtime/components/Pagination.vue +99 -6
  95. package/dist/runtime/components/Popover.vue +42 -6
  96. package/dist/runtime/components/Progress.vue +44 -6
  97. package/dist/runtime/components/RadioGroup.vue +55 -7
  98. package/dist/runtime/components/Select.vue +88 -6
  99. package/dist/runtime/components/SelectMenu.vue +104 -6
  100. package/dist/runtime/components/Separator.vue +41 -6
  101. package/dist/runtime/components/Skeleton.vue +18 -6
  102. package/dist/runtime/components/Slideover.vue +67 -6
  103. package/dist/runtime/components/Slider.vue +36 -6
  104. package/dist/runtime/components/Switch.vue +50 -6
  105. package/dist/runtime/components/Tabs.vue +59 -6
  106. package/dist/runtime/components/Textarea.vue +46 -6
  107. package/dist/runtime/components/Toast.vue +55 -6
  108. package/dist/runtime/components/Toaster.vue +27 -6
  109. package/dist/runtime/components/Tooltip.vue +42 -6
  110. package/dist/runtime/composables/useAvatarGroup.d.ts +2 -2
  111. package/dist/runtime/composables/useButtonGroup.d.ts +3 -3
  112. package/dist/runtime/composables/useFormField.d.ts +6 -3
  113. package/dist/runtime/composables/useFormField.js +11 -7
  114. package/dist/runtime/composables/useModal.d.ts +1 -1
  115. package/dist/runtime/composables/useSlideover.d.ts +1 -1
  116. package/dist/runtime/composables/useToast.d.ts +1 -1
  117. package/dist/runtime/index.css +1 -0
  118. package/dist/runtime/plugins/colors.d.ts +2 -0
  119. package/dist/runtime/plugins/modal.d.ts +2 -0
  120. package/dist/runtime/plugins/slideover.d.ts +2 -0
  121. package/dist/runtime/types/form.d.ts +1 -2
  122. package/dist/runtime/utils/link.d.ts +23 -55
  123. package/package.json +13 -14
  124. package/dist/runtime/assets/css/animations.css +0 -1
  125. package/dist/runtime/components/Accordion.vue.d.ts +0 -492
  126. package/dist/runtime/components/Alert.vue.d.ts +0 -548
  127. package/dist/runtime/components/App.vue.d.ts +0 -25
  128. package/dist/runtime/components/Avatar.vue.d.ts +0 -384
  129. package/dist/runtime/components/AvatarGroup.vue.d.ts +0 -381
  130. package/dist/runtime/components/Badge.vue.d.ts +0 -422
  131. package/dist/runtime/components/Breadcrumb.vue.d.ts +0 -307
  132. package/dist/runtime/components/Button.vue.d.ts +0 -949
  133. package/dist/runtime/components/ButtonGroup.vue.d.ts +0 -182
  134. package/dist/runtime/components/Card.vue.d.ts +0 -191
  135. package/dist/runtime/components/Checkbox.vue.d.ts +0 -819
  136. package/dist/runtime/components/Chip.vue.d.ts +0 -590
  137. package/dist/runtime/components/Collapsible.vue.d.ts +0 -159
  138. package/dist/runtime/components/CommandPalette.vue.d.ts +0 -684
  139. package/dist/runtime/components/Container.vue.d.ts +0 -27
  140. package/dist/runtime/components/ContextMenu.vue.d.ts +0 -796
  141. package/dist/runtime/components/ContextMenuContent.vue.d.ts +0 -0
  142. package/dist/runtime/components/Drawer.vue.d.ts +0 -343
  143. package/dist/runtime/components/DropdownMenu.vue.d.ts +0 -815
  144. package/dist/runtime/components/DropdownMenuContent.vue.d.ts +0 -0
  145. package/dist/runtime/components/Form.vue.d.ts +0 -39
  146. package/dist/runtime/components/FormField.vue.d.ts +0 -356
  147. package/dist/runtime/components/Icon.vue.d.ts +0 -17
  148. package/dist/runtime/components/Input.vue.d.ts +0 -1137
  149. package/dist/runtime/components/InputMenu.vue.d.ts +0 -2121
  150. package/dist/runtime/components/Kbd.vue.d.ts +0 -169
  151. package/dist/runtime/components/Link.vue.d.ts +0 -76
  152. package/dist/runtime/components/LinkBase.vue.d.ts +0 -49
  153. package/dist/runtime/components/Modal.vue.d.ts +0 -319
  154. package/dist/runtime/components/NavigationMenu.vue.d.ts +0 -1789
  155. package/dist/runtime/components/Pagination.vue.d.ts +0 -295
  156. package/dist/runtime/components/Popover.vue.d.ts +0 -197
  157. package/dist/runtime/components/Progress.vue.d.ts +0 -1781
  158. package/dist/runtime/components/RadioGroup.vue.d.ts +0 -1715
  159. package/dist/runtime/components/Select.vue.d.ts +0 -1569
  160. package/dist/runtime/components/SelectMenu.vue.d.ts +0 -1661
  161. package/dist/runtime/components/Separator.vue.d.ts +0 -0
  162. package/dist/runtime/components/Skeleton.vue.d.ts +0 -26
  163. package/dist/runtime/components/Slideover.vue.d.ts +0 -375
  164. package/dist/runtime/components/Slider.vue.d.ts +0 -0
  165. package/dist/runtime/components/Switch.vue.d.ts +0 -1676
  166. package/dist/runtime/components/Tabs.vue.d.ts +0 -934
  167. package/dist/runtime/components/Textarea.vue.d.ts +0 -1133
  168. package/dist/runtime/components/Toast.vue.d.ts +0 -0
  169. package/dist/runtime/components/Toaster.vue.d.ts +0 -362
  170. package/dist/runtime/components/Tooltip.vue.d.ts +0 -248
package/README.md CHANGED
@@ -94,7 +94,7 @@ Licensed under the [MIT license](https://github.com/nuxt/ui/blob/dev/LICENSE.md)
94
94
  [npm-downloads-href]: https://npmjs.com/package/@nuxt/ui
95
95
 
96
96
  [license-src]: https://img.shields.io/github/license/nuxt/ui.svg?style=flat&colorA=18181B&colorB=28CF8D
97
- [license-href]: https://github.com/nuxt/ui/blob/main/LICENSE
97
+ [license-href]: https://github.com/nuxt/ui/blob/main/LICENSE.md
98
98
 
99
99
  [nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js
100
100
  [nuxt-href]: https://nuxt.com
@@ -0,0 +1,36 @@
1
+ MIT License
2
+
3
+ Copyright (c) Pooya Parsa <pooya@pi0.io>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ Parser is based on https://github.com/lukeed/mri
26
+
27
+ The MIT License (MIT)
28
+
29
+ Copyright (c) Luke Edwards luke.edwards05@gmail.com (lukeed.com)
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
32
+
33
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
34
+
35
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36
+
@@ -0,0 +1,134 @@
1
+ # 🌆 citty
2
+
3
+ [![npm version][npm-version-src]][npm-version-href]
4
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
+ [![bundle][bundle-src]][bundle-href]
6
+ [![Codecov][codecov-src]][codecov-href]
7
+ [![License][license-src]][license-href]
8
+
9
+ > Elegant CLI Builder
10
+
11
+ - Fast and lightweight argument parser based on [mri](https://github.com/lukeed/mri)
12
+ - Smart value parsing with typecast, boolean shortcuts and unknown flag handling
13
+ - Nested sub-commands
14
+ - Lazy and Async commands
15
+ - Plugable and composable API
16
+ - Auto generated usage and help
17
+
18
+ 🚧 This project is under heavy development. More features are coming soon!
19
+
20
+ ## Usage
21
+
22
+ Install package:
23
+
24
+ ```sh
25
+ # npm
26
+ npm install citty
27
+
28
+ # yarn
29
+ yarn add citty
30
+
31
+ # pnpm
32
+ pnpm install citty
33
+ ```
34
+
35
+ Import:
36
+
37
+ ```js
38
+ // ESM
39
+ import { defineCommand, runMain } from "citty";
40
+
41
+ // CommonJS
42
+ const { defineCommand, runMain } = require("citty");
43
+ ```
44
+
45
+ Define main command to run:
46
+
47
+ ```ts
48
+ import { defineCommand, runMain } from "citty";
49
+
50
+ const main = defineCommand({
51
+ meta: {
52
+ name: "hello",
53
+ version: "1.0.0",
54
+ description: "My Awesome CLI App",
55
+ },
56
+ args: {
57
+ name: {
58
+ type: "positional",
59
+ description: "Your name",
60
+ required: true,
61
+ },
62
+ friendly: {
63
+ type: "boolean",
64
+ description: "Use friendly greeting",
65
+ },
66
+ },
67
+ run({ args }) {
68
+ console.log(`${args.friendly ? "Hi" : "Greetings"} ${args.name}!`);
69
+ },
70
+ });
71
+
72
+ runMain(main);
73
+ ```
74
+
75
+ ## Utils
76
+
77
+ ### `defineCommand`
78
+
79
+ `defineCommand` is a type helper for defining commands.
80
+
81
+ ### `runMain`
82
+
83
+ Runs a command with usage support and graceful error handling.
84
+
85
+ ### `createMain`
86
+
87
+ Create a wrapper around command that calls `runMain` when called.
88
+
89
+ ### `runCommand`
90
+
91
+ Parses input args and runs command and sub-commands (unsupervised). You can access `result` key from returnd/awaited value to access command's result.
92
+
93
+ ### `parseArgs`
94
+
95
+ Parses input arguments and applies defaults.
96
+
97
+ ### `renderUsage`
98
+
99
+ Renders command usage to a string value.
100
+
101
+ ### `showUsage`
102
+
103
+ Renders usage and prints to the console
104
+
105
+ ## Development
106
+
107
+ - Clone this repository
108
+ - Install latest LTS version of [Node.js](https://nodejs.org/en/)
109
+ - Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
110
+ - Install dependencies using `pnpm install`
111
+ - Run interactive tests using `pnpm dev`
112
+
113
+ ## License
114
+
115
+ Made with 💛 Published under [MIT License](./LICENSE).
116
+
117
+ Argument parser is based on [lukeed/mri](https://github.com/lukeed/mri) by Luke Edwards ([@lukeed](https://github.com/lukeed)).
118
+
119
+ <!-- Badges -->
120
+
121
+ <!-- Badges -->
122
+
123
+ [npm-version-src]: https://img.shields.io/npm/v/citty?style=flat&colorA=18181B&colorB=F0DB4F
124
+ [npm-version-href]: https://npmjs.com/package/citty
125
+ [npm-downloads-src]: https://img.shields.io/npm/dm/citty?style=flat&colorA=18181B&colorB=F0DB4F
126
+ [npm-downloads-href]: https://npmjs.com/package/citty
127
+ [codecov-src]: https://img.shields.io/codecov/c/gh/unjs/citty/main?style=flat&colorA=18181B&colorB=F0DB4F
128
+ [codecov-href]: https://codecov.io/gh/unjs/citty
129
+ [bundle-src]: https://img.shields.io/bundlephobia/minzip/citty?style=flat&colorA=18181B&colorB=F0DB4F
130
+ [bundle-href]: https://bundlephobia.com/result?p=citty
131
+ [license-src]: https://img.shields.io/github/license/unjs/citty.svg?style=flat&colorA=18181B&colorB=F0DB4F
132
+ [license-href]: https://github.com/unjs/citty/blob/main/LICENSE
133
+ [jsdocs-src]: https://img.shields.io/badge/jsDocs.io-reference-18181B?style=flat&colorA=18181B&colorB=F0DB4F
134
+ [jsdocs-href]: https://www.jsdocs.io/package/citty
@@ -0,0 +1,475 @@
1
+ 'use strict';
2
+
3
+ const consola = require('consola');
4
+ const utils = require('consola/utils');
5
+
6
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
7
+
8
+ const consola__default = /*#__PURE__*/_interopDefaultCompat(consola);
9
+
10
+ function toArray(val) {
11
+ if (Array.isArray(val)) {
12
+ return val;
13
+ }
14
+ return val === void 0 ? [] : [val];
15
+ }
16
+ function formatLineColumns(lines, linePrefix = "") {
17
+ const maxLengh = [];
18
+ for (const line of lines) {
19
+ for (const [i, element] of line.entries()) {
20
+ maxLengh[i] = Math.max(maxLengh[i] || 0, element.length);
21
+ }
22
+ }
23
+ return lines.map(
24
+ (l) => l.map(
25
+ (c, i) => linePrefix + c[i === 0 ? "padStart" : "padEnd"](maxLengh[i])
26
+ ).join(" ")
27
+ ).join("\n");
28
+ }
29
+ function resolveValue(input) {
30
+ return typeof input === "function" ? input() : input;
31
+ }
32
+ class CLIError extends Error {
33
+ constructor(message, code) {
34
+ super(message);
35
+ this.code = code;
36
+ this.name = "CLIError";
37
+ }
38
+ }
39
+
40
+ const NUMBER_CHAR_RE = /\d/;
41
+ const STR_SPLITTERS = ["-", "_", "/", "."];
42
+ function isUppercase(char = "") {
43
+ if (NUMBER_CHAR_RE.test(char)) {
44
+ return void 0;
45
+ }
46
+ return char !== char.toLowerCase();
47
+ }
48
+ function splitByCase(str, separators) {
49
+ const splitters = separators ?? STR_SPLITTERS;
50
+ const parts = [];
51
+ if (!str || typeof str !== "string") {
52
+ return parts;
53
+ }
54
+ let buff = "";
55
+ let previousUpper;
56
+ let previousSplitter;
57
+ for (const char of str) {
58
+ const isSplitter = splitters.includes(char);
59
+ if (isSplitter === true) {
60
+ parts.push(buff);
61
+ buff = "";
62
+ previousUpper = void 0;
63
+ continue;
64
+ }
65
+ const isUpper = isUppercase(char);
66
+ if (previousSplitter === false) {
67
+ if (previousUpper === false && isUpper === true) {
68
+ parts.push(buff);
69
+ buff = char;
70
+ previousUpper = isUpper;
71
+ continue;
72
+ }
73
+ if (previousUpper === true && isUpper === false && buff.length > 1) {
74
+ const lastChar = buff.at(-1);
75
+ parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
76
+ buff = lastChar + char;
77
+ previousUpper = isUpper;
78
+ continue;
79
+ }
80
+ }
81
+ buff += char;
82
+ previousUpper = isUpper;
83
+ previousSplitter = isSplitter;
84
+ }
85
+ parts.push(buff);
86
+ return parts;
87
+ }
88
+ function upperFirst(str) {
89
+ return str ? str[0].toUpperCase() + str.slice(1) : "";
90
+ }
91
+ function lowerFirst(str) {
92
+ return str ? str[0].toLowerCase() + str.slice(1) : "";
93
+ }
94
+ function pascalCase(str, opts) {
95
+ return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
96
+ }
97
+ function camelCase(str, opts) {
98
+ return lowerFirst(pascalCase(str || "", opts));
99
+ }
100
+ function kebabCase(str, joiner) {
101
+ return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
102
+ }
103
+
104
+ function toArr(any) {
105
+ return any == void 0 ? [] : Array.isArray(any) ? any : [any];
106
+ }
107
+ function toVal(out, key, val, opts) {
108
+ let x;
109
+ const old = out[key];
110
+ const nxt = ~opts.string.indexOf(key) ? val == void 0 || val === true ? "" : String(val) : typeof val === "boolean" ? val : ~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
111
+ out[key] = old == void 0 ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
112
+ }
113
+ function parseRawArgs(args = [], opts = {}) {
114
+ let k;
115
+ let arr;
116
+ let arg;
117
+ let name;
118
+ let val;
119
+ const out = { _: [] };
120
+ let i = 0;
121
+ let j = 0;
122
+ let idx = 0;
123
+ const len = args.length;
124
+ const alibi = opts.alias !== void 0;
125
+ const strict = opts.unknown !== void 0;
126
+ const defaults = opts.default !== void 0;
127
+ opts.alias = opts.alias || {};
128
+ opts.string = toArr(opts.string);
129
+ opts.boolean = toArr(opts.boolean);
130
+ if (alibi) {
131
+ for (k in opts.alias) {
132
+ arr = opts.alias[k] = toArr(opts.alias[k]);
133
+ for (i = 0; i < arr.length; i++) {
134
+ (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
135
+ }
136
+ }
137
+ }
138
+ for (i = opts.boolean.length; i-- > 0; ) {
139
+ arr = opts.alias[opts.boolean[i]] || [];
140
+ for (j = arr.length; j-- > 0; ) {
141
+ opts.boolean.push(arr[j]);
142
+ }
143
+ }
144
+ for (i = opts.string.length; i-- > 0; ) {
145
+ arr = opts.alias[opts.string[i]] || [];
146
+ for (j = arr.length; j-- > 0; ) {
147
+ opts.string.push(arr[j]);
148
+ }
149
+ }
150
+ if (defaults) {
151
+ for (k in opts.default) {
152
+ name = typeof opts.default[k];
153
+ arr = opts.alias[k] = opts.alias[k] || [];
154
+ if (opts[name] !== void 0) {
155
+ opts[name].push(k);
156
+ for (i = 0; i < arr.length; i++) {
157
+ opts[name].push(arr[i]);
158
+ }
159
+ }
160
+ }
161
+ }
162
+ const keys = strict ? Object.keys(opts.alias) : [];
163
+ for (i = 0; i < len; i++) {
164
+ arg = args[i];
165
+ if (arg === "--") {
166
+ out._ = out._.concat(args.slice(++i));
167
+ break;
168
+ }
169
+ for (j = 0; j < arg.length; j++) {
170
+ if (arg.charCodeAt(j) !== 45) {
171
+ break;
172
+ }
173
+ }
174
+ if (j === 0) {
175
+ out._.push(arg);
176
+ } else if (arg.substring(j, j + 3) === "no-") {
177
+ name = arg.slice(Math.max(0, j + 3));
178
+ if (strict && !~keys.indexOf(name)) {
179
+ return opts.unknown(arg);
180
+ }
181
+ out[name] = false;
182
+ } else {
183
+ for (idx = j + 1; idx < arg.length; idx++) {
184
+ if (arg.charCodeAt(idx) === 61) {
185
+ break;
186
+ }
187
+ }
188
+ name = arg.substring(j, idx);
189
+ val = arg.slice(Math.max(0, ++idx)) || i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i];
190
+ arr = j === 2 ? [name] : name;
191
+ for (idx = 0; idx < arr.length; idx++) {
192
+ name = arr[idx];
193
+ if (strict && !~keys.indexOf(name)) {
194
+ return opts.unknown("-".repeat(j) + name);
195
+ }
196
+ toVal(out, name, idx + 1 < arr.length || val, opts);
197
+ }
198
+ }
199
+ }
200
+ if (defaults) {
201
+ for (k in opts.default) {
202
+ if (out[k] === void 0) {
203
+ out[k] = opts.default[k];
204
+ }
205
+ }
206
+ }
207
+ if (alibi) {
208
+ for (k in out) {
209
+ arr = opts.alias[k] || [];
210
+ while (arr.length > 0) {
211
+ out[arr.shift()] = out[k];
212
+ }
213
+ }
214
+ }
215
+ return out;
216
+ }
217
+
218
+ function parseArgs(rawArgs, argsDef) {
219
+ const parseOptions = {
220
+ boolean: [],
221
+ string: [],
222
+ mixed: [],
223
+ alias: {},
224
+ default: {}
225
+ };
226
+ const args = resolveArgs(argsDef);
227
+ for (const arg of args) {
228
+ if (arg.type === "positional") {
229
+ continue;
230
+ }
231
+ if (arg.type === "string") {
232
+ parseOptions.string.push(arg.name);
233
+ } else if (arg.type === "boolean") {
234
+ parseOptions.boolean.push(arg.name);
235
+ }
236
+ if (arg.default !== void 0) {
237
+ parseOptions.default[arg.name] = arg.default;
238
+ }
239
+ if (arg.alias) {
240
+ parseOptions.alias[arg.name] = arg.alias;
241
+ }
242
+ }
243
+ const parsed = parseRawArgs(rawArgs, parseOptions);
244
+ const [...positionalArguments] = parsed._;
245
+ const parsedArgsProxy = new Proxy(parsed, {
246
+ get(target, prop) {
247
+ return target[prop] ?? target[camelCase(prop)] ?? target[kebabCase(prop)];
248
+ }
249
+ });
250
+ for (const [, arg] of args.entries()) {
251
+ if (arg.type === "positional") {
252
+ const nextPositionalArgument = positionalArguments.shift();
253
+ if (nextPositionalArgument !== void 0) {
254
+ parsedArgsProxy[arg.name] = nextPositionalArgument;
255
+ } else if (arg.default === void 0 && arg.required !== false) {
256
+ throw new CLIError(
257
+ `Missing required positional argument: ${arg.name.toUpperCase()}`,
258
+ "EARG"
259
+ );
260
+ } else {
261
+ parsedArgsProxy[arg.name] = arg.default;
262
+ }
263
+ } else if (arg.required && parsedArgsProxy[arg.name] === void 0) {
264
+ throw new CLIError(`Missing required argument: --${arg.name}`, "EARG");
265
+ }
266
+ }
267
+ return parsedArgsProxy;
268
+ }
269
+ function resolveArgs(argsDef) {
270
+ const args = [];
271
+ for (const [name, argDef] of Object.entries(argsDef || {})) {
272
+ args.push({
273
+ ...argDef,
274
+ name,
275
+ alias: toArray(argDef.alias)
276
+ });
277
+ }
278
+ return args;
279
+ }
280
+
281
+ function defineCommand(def) {
282
+ return def;
283
+ }
284
+ async function runCommand(cmd, opts) {
285
+ const cmdArgs = await resolveValue(cmd.args || {});
286
+ const parsedArgs = parseArgs(opts.rawArgs, cmdArgs);
287
+ const context = {
288
+ rawArgs: opts.rawArgs,
289
+ args: parsedArgs,
290
+ data: opts.data,
291
+ cmd
292
+ };
293
+ if (typeof cmd.setup === "function") {
294
+ await cmd.setup(context);
295
+ }
296
+ let result;
297
+ try {
298
+ const subCommands = await resolveValue(cmd.subCommands);
299
+ if (subCommands && Object.keys(subCommands).length > 0) {
300
+ const subCommandArgIndex = opts.rawArgs.findIndex(
301
+ (arg) => !arg.startsWith("-")
302
+ );
303
+ const subCommandName = opts.rawArgs[subCommandArgIndex];
304
+ if (subCommandName) {
305
+ if (!subCommands[subCommandName]) {
306
+ throw new CLIError(
307
+ `Unknown command \`${subCommandName}\``,
308
+ "E_UNKNOWN_COMMAND"
309
+ );
310
+ }
311
+ const subCommand = await resolveValue(subCommands[subCommandName]);
312
+ if (subCommand) {
313
+ await runCommand(subCommand, {
314
+ rawArgs: opts.rawArgs.slice(subCommandArgIndex + 1)
315
+ });
316
+ }
317
+ } else if (!cmd.run) {
318
+ throw new CLIError(`No command specified.`, "E_NO_COMMAND");
319
+ }
320
+ }
321
+ if (typeof cmd.run === "function") {
322
+ result = await cmd.run(context);
323
+ }
324
+ } finally {
325
+ if (typeof cmd.cleanup === "function") {
326
+ await cmd.cleanup(context);
327
+ }
328
+ }
329
+ return { result };
330
+ }
331
+ async function resolveSubCommand(cmd, rawArgs, parent) {
332
+ const subCommands = await resolveValue(cmd.subCommands);
333
+ if (subCommands && Object.keys(subCommands).length > 0) {
334
+ const subCommandArgIndex = rawArgs.findIndex((arg) => !arg.startsWith("-"));
335
+ const subCommandName = rawArgs[subCommandArgIndex];
336
+ const subCommand = await resolveValue(subCommands[subCommandName]);
337
+ if (subCommand) {
338
+ return resolveSubCommand(
339
+ subCommand,
340
+ rawArgs.slice(subCommandArgIndex + 1),
341
+ cmd
342
+ );
343
+ }
344
+ }
345
+ return [cmd, parent];
346
+ }
347
+
348
+ async function showUsage(cmd, parent) {
349
+ try {
350
+ consola__default.log(await renderUsage(cmd, parent) + "\n");
351
+ } catch (error) {
352
+ consola__default.error(error);
353
+ }
354
+ }
355
+ async function renderUsage(cmd, parent) {
356
+ const cmdMeta = await resolveValue(cmd.meta || {});
357
+ const cmdArgs = resolveArgs(await resolveValue(cmd.args || {}));
358
+ const parentMeta = await resolveValue(parent?.meta || {});
359
+ const commandName = `${parentMeta.name ? `${parentMeta.name} ` : ""}` + (cmdMeta.name || process.argv[1]);
360
+ const argLines = [];
361
+ const posLines = [];
362
+ const commandsLines = [];
363
+ const usageLine = [];
364
+ for (const arg of cmdArgs) {
365
+ if (arg.type === "positional") {
366
+ const name = arg.name.toUpperCase();
367
+ const isRequired = arg.required !== false && arg.default === void 0;
368
+ const defaultHint = arg.default ? `="${arg.default}"` : "";
369
+ posLines.push([
370
+ "`" + name + defaultHint + "`",
371
+ arg.description || "",
372
+ arg.valueHint ? `<${arg.valueHint}>` : ""
373
+ ]);
374
+ usageLine.push(isRequired ? `<${name}>` : `[${name}]`);
375
+ } else {
376
+ const isRequired = arg.required === true && arg.default === void 0;
377
+ const argStr = (arg.type === "boolean" && arg.default === true ? [
378
+ ...(arg.alias || []).map((a) => `--no-${a}`),
379
+ `--no-${arg.name}`
380
+ ].join(", ") : [...(arg.alias || []).map((a) => `-${a}`), `--${arg.name}`].join(
381
+ ", "
382
+ )) + (arg.type === "string" && (arg.valueHint || arg.default) ? `=${arg.valueHint ? `<${arg.valueHint}>` : `"${arg.default || ""}"`}` : "");
383
+ argLines.push([
384
+ "`" + argStr + (isRequired ? " (required)" : "") + "`",
385
+ arg.description || ""
386
+ ]);
387
+ if (isRequired) {
388
+ usageLine.push(argStr);
389
+ }
390
+ }
391
+ }
392
+ if (cmd.subCommands) {
393
+ const commandNames = [];
394
+ const subCommands = await resolveValue(cmd.subCommands);
395
+ for (const [name, sub] of Object.entries(subCommands)) {
396
+ const subCmd = await resolveValue(sub);
397
+ const meta = await resolveValue(subCmd?.meta);
398
+ commandsLines.push([`\`${name}\``, meta?.description || ""]);
399
+ commandNames.push(name);
400
+ }
401
+ usageLine.push(commandNames.join("|"));
402
+ }
403
+ const usageLines = [];
404
+ const version = cmdMeta.version || parentMeta.version;
405
+ usageLines.push(
406
+ utils.colors.gray(
407
+ `${cmdMeta.description} (${commandName + (version ? ` v${version}` : "")})`
408
+ ),
409
+ ""
410
+ );
411
+ const hasOptions = argLines.length > 0 || posLines.length > 0;
412
+ usageLines.push(
413
+ `${utils.colors.underline(utils.colors.bold("USAGE"))} \`${commandName}${hasOptions ? " [OPTIONS]" : ""} ${usageLine.join(" ")}\``,
414
+ ""
415
+ );
416
+ if (posLines.length > 0) {
417
+ usageLines.push(utils.colors.underline(utils.colors.bold("ARGUMENTS")), "");
418
+ usageLines.push(formatLineColumns(posLines, " "));
419
+ usageLines.push("");
420
+ }
421
+ if (argLines.length > 0) {
422
+ usageLines.push(utils.colors.underline(utils.colors.bold("OPTIONS")), "");
423
+ usageLines.push(formatLineColumns(argLines, " "));
424
+ usageLines.push("");
425
+ }
426
+ if (commandsLines.length > 0) {
427
+ usageLines.push(utils.colors.underline(utils.colors.bold("COMMANDS")), "");
428
+ usageLines.push(formatLineColumns(commandsLines, " "));
429
+ usageLines.push(
430
+ "",
431
+ `Use \`${commandName} <command> --help\` for more information about a command.`
432
+ );
433
+ }
434
+ return usageLines.filter((l) => typeof l === "string").join("\n");
435
+ }
436
+
437
+ async function runMain(cmd, opts = {}) {
438
+ const rawArgs = opts.rawArgs || process.argv.slice(2);
439
+ const showUsage$1 = opts.showUsage || showUsage;
440
+ try {
441
+ if (rawArgs.includes("--help") || rawArgs.includes("-h")) {
442
+ await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
443
+ process.exit(0);
444
+ } else if (rawArgs.length === 1 && rawArgs[0] === "--version") {
445
+ const meta = typeof cmd.meta === "function" ? await cmd.meta() : await cmd.meta;
446
+ if (!meta?.version) {
447
+ throw new CLIError("No version specified", "E_NO_VERSION");
448
+ }
449
+ consola__default.log(meta.version);
450
+ } else {
451
+ await runCommand(cmd, { rawArgs });
452
+ }
453
+ } catch (error) {
454
+ const isCLIError = error instanceof CLIError;
455
+ if (!isCLIError) {
456
+ consola__default.error(error, "\n");
457
+ }
458
+ if (isCLIError) {
459
+ await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
460
+ }
461
+ consola__default.error(error.message);
462
+ process.exit(1);
463
+ }
464
+ }
465
+ function createMain(cmd) {
466
+ return (opts = {}) => runMain(cmd, opts);
467
+ }
468
+
469
+ exports.createMain = createMain;
470
+ exports.defineCommand = defineCommand;
471
+ exports.parseArgs = parseArgs;
472
+ exports.renderUsage = renderUsage;
473
+ exports.runCommand = runCommand;
474
+ exports.runMain = runMain;
475
+ exports.showUsage = showUsage;