@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
@@ -0,0 +1,80 @@
1
+ type ArgType = "boolean" | "string" | "positional" | undefined;
2
+ type _ArgDef<T extends ArgType, VT extends boolean | string> = {
3
+ type?: T;
4
+ description?: string;
5
+ valueHint?: string;
6
+ alias?: string | string[];
7
+ default?: VT;
8
+ required?: boolean;
9
+ };
10
+ type BooleanArgDef = _ArgDef<"boolean", boolean>;
11
+ type StringArgDef = _ArgDef<"string", string>;
12
+ type PositionalArgDef = Omit<_ArgDef<"positional", string>, "alias">;
13
+ type ArgDef = BooleanArgDef | StringArgDef | PositionalArgDef;
14
+ type ArgsDef = Record<string, ArgDef>;
15
+ type Arg = ArgDef & {
16
+ name: string;
17
+ alias: string[];
18
+ };
19
+ type ParsedArgs<T extends ArgsDef = ArgsDef> = {
20
+ _: string[];
21
+ } & Record<{
22
+ [K in keyof T]: T[K] extends {
23
+ type: "positional";
24
+ } ? K : never;
25
+ }[keyof T], string> & Record<{
26
+ [K in keyof T]: T[K] extends {
27
+ type: "string";
28
+ } ? K : never;
29
+ }[keyof T], string> & Record<{
30
+ [K in keyof T]: T[K] extends {
31
+ type: "boolean";
32
+ } ? K : never;
33
+ }[keyof T], boolean> & Record<string, string | boolean | string[]>;
34
+ interface CommandMeta {
35
+ name?: string;
36
+ version?: string;
37
+ description?: string;
38
+ }
39
+ type SubCommandsDef = Record<string, Resolvable<CommandDef<any>>>;
40
+ type CommandDef<T extends ArgsDef = ArgsDef> = {
41
+ meta?: Resolvable<CommandMeta>;
42
+ args?: Resolvable<T>;
43
+ subCommands?: Resolvable<SubCommandsDef>;
44
+ setup?: (context: CommandContext<T>) => any | Promise<any>;
45
+ cleanup?: (context: CommandContext<T>) => any | Promise<any>;
46
+ run?: (context: CommandContext<T>) => any | Promise<any>;
47
+ };
48
+ type CommandContext<T extends ArgsDef = ArgsDef> = {
49
+ rawArgs: string[];
50
+ args: ParsedArgs<T>;
51
+ cmd: CommandDef<T>;
52
+ subCommand?: CommandDef<T>;
53
+ data?: any;
54
+ };
55
+ type Awaitable<T> = () => T | Promise<T>;
56
+ type Resolvable<T> = T | Promise<T> | (() => T) | (() => Promise<T>);
57
+
58
+ declare function defineCommand<T extends ArgsDef = ArgsDef>(def: CommandDef<T>): CommandDef<T>;
59
+ interface RunCommandOptions {
60
+ rawArgs: string[];
61
+ data?: any;
62
+ showUsage?: boolean;
63
+ }
64
+ declare function runCommand<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts: RunCommandOptions): Promise<{
65
+ result: unknown;
66
+ }>;
67
+
68
+ declare function showUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<void>;
69
+ declare function renderUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<string>;
70
+
71
+ interface RunMainOptions {
72
+ rawArgs?: string[];
73
+ showUsage?: typeof showUsage;
74
+ }
75
+ declare function runMain<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts?: RunMainOptions): Promise<void>;
76
+ declare function createMain<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>): (opts?: RunMainOptions) => Promise<void>;
77
+
78
+ declare function parseArgs<T extends ArgsDef = ArgsDef>(rawArgs: string[], argsDef: ArgsDef): ParsedArgs<T>;
79
+
80
+ export { type Arg, type ArgDef, type ArgType, type ArgsDef, type Awaitable, type BooleanArgDef, type CommandContext, type CommandDef, type CommandMeta, type ParsedArgs, type PositionalArgDef, type Resolvable, type RunCommandOptions, type RunMainOptions, type StringArgDef, type SubCommandsDef, type _ArgDef, createMain, defineCommand, parseArgs, renderUsage, runCommand, runMain, showUsage };
@@ -0,0 +1,80 @@
1
+ type ArgType = "boolean" | "string" | "positional" | undefined;
2
+ type _ArgDef<T extends ArgType, VT extends boolean | string> = {
3
+ type?: T;
4
+ description?: string;
5
+ valueHint?: string;
6
+ alias?: string | string[];
7
+ default?: VT;
8
+ required?: boolean;
9
+ };
10
+ type BooleanArgDef = _ArgDef<"boolean", boolean>;
11
+ type StringArgDef = _ArgDef<"string", string>;
12
+ type PositionalArgDef = Omit<_ArgDef<"positional", string>, "alias">;
13
+ type ArgDef = BooleanArgDef | StringArgDef | PositionalArgDef;
14
+ type ArgsDef = Record<string, ArgDef>;
15
+ type Arg = ArgDef & {
16
+ name: string;
17
+ alias: string[];
18
+ };
19
+ type ParsedArgs<T extends ArgsDef = ArgsDef> = {
20
+ _: string[];
21
+ } & Record<{
22
+ [K in keyof T]: T[K] extends {
23
+ type: "positional";
24
+ } ? K : never;
25
+ }[keyof T], string> & Record<{
26
+ [K in keyof T]: T[K] extends {
27
+ type: "string";
28
+ } ? K : never;
29
+ }[keyof T], string> & Record<{
30
+ [K in keyof T]: T[K] extends {
31
+ type: "boolean";
32
+ } ? K : never;
33
+ }[keyof T], boolean> & Record<string, string | boolean | string[]>;
34
+ interface CommandMeta {
35
+ name?: string;
36
+ version?: string;
37
+ description?: string;
38
+ }
39
+ type SubCommandsDef = Record<string, Resolvable<CommandDef<any>>>;
40
+ type CommandDef<T extends ArgsDef = ArgsDef> = {
41
+ meta?: Resolvable<CommandMeta>;
42
+ args?: Resolvable<T>;
43
+ subCommands?: Resolvable<SubCommandsDef>;
44
+ setup?: (context: CommandContext<T>) => any | Promise<any>;
45
+ cleanup?: (context: CommandContext<T>) => any | Promise<any>;
46
+ run?: (context: CommandContext<T>) => any | Promise<any>;
47
+ };
48
+ type CommandContext<T extends ArgsDef = ArgsDef> = {
49
+ rawArgs: string[];
50
+ args: ParsedArgs<T>;
51
+ cmd: CommandDef<T>;
52
+ subCommand?: CommandDef<T>;
53
+ data?: any;
54
+ };
55
+ type Awaitable<T> = () => T | Promise<T>;
56
+ type Resolvable<T> = T | Promise<T> | (() => T) | (() => Promise<T>);
57
+
58
+ declare function defineCommand<T extends ArgsDef = ArgsDef>(def: CommandDef<T>): CommandDef<T>;
59
+ interface RunCommandOptions {
60
+ rawArgs: string[];
61
+ data?: any;
62
+ showUsage?: boolean;
63
+ }
64
+ declare function runCommand<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts: RunCommandOptions): Promise<{
65
+ result: unknown;
66
+ }>;
67
+
68
+ declare function showUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<void>;
69
+ declare function renderUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<string>;
70
+
71
+ interface RunMainOptions {
72
+ rawArgs?: string[];
73
+ showUsage?: typeof showUsage;
74
+ }
75
+ declare function runMain<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts?: RunMainOptions): Promise<void>;
76
+ declare function createMain<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>): (opts?: RunMainOptions) => Promise<void>;
77
+
78
+ declare function parseArgs<T extends ArgsDef = ArgsDef>(rawArgs: string[], argsDef: ArgsDef): ParsedArgs<T>;
79
+
80
+ export { type Arg, type ArgDef, type ArgType, type ArgsDef, type Awaitable, type BooleanArgDef, type CommandContext, type CommandDef, type CommandMeta, type ParsedArgs, type PositionalArgDef, type Resolvable, type RunCommandOptions, type RunMainOptions, type StringArgDef, type SubCommandsDef, type _ArgDef, createMain, defineCommand, parseArgs, renderUsage, runCommand, runMain, showUsage };
@@ -0,0 +1,80 @@
1
+ type ArgType = "boolean" | "string" | "positional" | undefined;
2
+ type _ArgDef<T extends ArgType, VT extends boolean | string> = {
3
+ type?: T;
4
+ description?: string;
5
+ valueHint?: string;
6
+ alias?: string | string[];
7
+ default?: VT;
8
+ required?: boolean;
9
+ };
10
+ type BooleanArgDef = _ArgDef<"boolean", boolean>;
11
+ type StringArgDef = _ArgDef<"string", string>;
12
+ type PositionalArgDef = Omit<_ArgDef<"positional", string>, "alias">;
13
+ type ArgDef = BooleanArgDef | StringArgDef | PositionalArgDef;
14
+ type ArgsDef = Record<string, ArgDef>;
15
+ type Arg = ArgDef & {
16
+ name: string;
17
+ alias: string[];
18
+ };
19
+ type ParsedArgs<T extends ArgsDef = ArgsDef> = {
20
+ _: string[];
21
+ } & Record<{
22
+ [K in keyof T]: T[K] extends {
23
+ type: "positional";
24
+ } ? K : never;
25
+ }[keyof T], string> & Record<{
26
+ [K in keyof T]: T[K] extends {
27
+ type: "string";
28
+ } ? K : never;
29
+ }[keyof T], string> & Record<{
30
+ [K in keyof T]: T[K] extends {
31
+ type: "boolean";
32
+ } ? K : never;
33
+ }[keyof T], boolean> & Record<string, string | boolean | string[]>;
34
+ interface CommandMeta {
35
+ name?: string;
36
+ version?: string;
37
+ description?: string;
38
+ }
39
+ type SubCommandsDef = Record<string, Resolvable<CommandDef<any>>>;
40
+ type CommandDef<T extends ArgsDef = ArgsDef> = {
41
+ meta?: Resolvable<CommandMeta>;
42
+ args?: Resolvable<T>;
43
+ subCommands?: Resolvable<SubCommandsDef>;
44
+ setup?: (context: CommandContext<T>) => any | Promise<any>;
45
+ cleanup?: (context: CommandContext<T>) => any | Promise<any>;
46
+ run?: (context: CommandContext<T>) => any | Promise<any>;
47
+ };
48
+ type CommandContext<T extends ArgsDef = ArgsDef> = {
49
+ rawArgs: string[];
50
+ args: ParsedArgs<T>;
51
+ cmd: CommandDef<T>;
52
+ subCommand?: CommandDef<T>;
53
+ data?: any;
54
+ };
55
+ type Awaitable<T> = () => T | Promise<T>;
56
+ type Resolvable<T> = T | Promise<T> | (() => T) | (() => Promise<T>);
57
+
58
+ declare function defineCommand<T extends ArgsDef = ArgsDef>(def: CommandDef<T>): CommandDef<T>;
59
+ interface RunCommandOptions {
60
+ rawArgs: string[];
61
+ data?: any;
62
+ showUsage?: boolean;
63
+ }
64
+ declare function runCommand<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts: RunCommandOptions): Promise<{
65
+ result: unknown;
66
+ }>;
67
+
68
+ declare function showUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<void>;
69
+ declare function renderUsage<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, parent?: CommandDef<T>): Promise<string>;
70
+
71
+ interface RunMainOptions {
72
+ rawArgs?: string[];
73
+ showUsage?: typeof showUsage;
74
+ }
75
+ declare function runMain<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>, opts?: RunMainOptions): Promise<void>;
76
+ declare function createMain<T extends ArgsDef = ArgsDef>(cmd: CommandDef<T>): (opts?: RunMainOptions) => Promise<void>;
77
+
78
+ declare function parseArgs<T extends ArgsDef = ArgsDef>(rawArgs: string[], argsDef: ArgsDef): ParsedArgs<T>;
79
+
80
+ export { type Arg, type ArgDef, type ArgType, type ArgsDef, type Awaitable, type BooleanArgDef, type CommandContext, type CommandDef, type CommandMeta, type ParsedArgs, type PositionalArgDef, type Resolvable, type RunCommandOptions, type RunMainOptions, type StringArgDef, type SubCommandsDef, type _ArgDef, createMain, defineCommand, parseArgs, renderUsage, runCommand, runMain, showUsage };
@@ -0,0 +1,463 @@
1
+ import consola from 'consola';
2
+ import { colors } from 'consola/utils';
3
+
4
+ function toArray(val) {
5
+ if (Array.isArray(val)) {
6
+ return val;
7
+ }
8
+ return val === void 0 ? [] : [val];
9
+ }
10
+ function formatLineColumns(lines, linePrefix = "") {
11
+ const maxLengh = [];
12
+ for (const line of lines) {
13
+ for (const [i, element] of line.entries()) {
14
+ maxLengh[i] = Math.max(maxLengh[i] || 0, element.length);
15
+ }
16
+ }
17
+ return lines.map(
18
+ (l) => l.map(
19
+ (c, i) => linePrefix + c[i === 0 ? "padStart" : "padEnd"](maxLengh[i])
20
+ ).join(" ")
21
+ ).join("\n");
22
+ }
23
+ function resolveValue(input) {
24
+ return typeof input === "function" ? input() : input;
25
+ }
26
+ class CLIError extends Error {
27
+ constructor(message, code) {
28
+ super(message);
29
+ this.code = code;
30
+ this.name = "CLIError";
31
+ }
32
+ }
33
+
34
+ const NUMBER_CHAR_RE = /\d/;
35
+ const STR_SPLITTERS = ["-", "_", "/", "."];
36
+ function isUppercase(char = "") {
37
+ if (NUMBER_CHAR_RE.test(char)) {
38
+ return void 0;
39
+ }
40
+ return char !== char.toLowerCase();
41
+ }
42
+ function splitByCase(str, separators) {
43
+ const splitters = separators ?? STR_SPLITTERS;
44
+ const parts = [];
45
+ if (!str || typeof str !== "string") {
46
+ return parts;
47
+ }
48
+ let buff = "";
49
+ let previousUpper;
50
+ let previousSplitter;
51
+ for (const char of str) {
52
+ const isSplitter = splitters.includes(char);
53
+ if (isSplitter === true) {
54
+ parts.push(buff);
55
+ buff = "";
56
+ previousUpper = void 0;
57
+ continue;
58
+ }
59
+ const isUpper = isUppercase(char);
60
+ if (previousSplitter === false) {
61
+ if (previousUpper === false && isUpper === true) {
62
+ parts.push(buff);
63
+ buff = char;
64
+ previousUpper = isUpper;
65
+ continue;
66
+ }
67
+ if (previousUpper === true && isUpper === false && buff.length > 1) {
68
+ const lastChar = buff.at(-1);
69
+ parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
70
+ buff = lastChar + char;
71
+ previousUpper = isUpper;
72
+ continue;
73
+ }
74
+ }
75
+ buff += char;
76
+ previousUpper = isUpper;
77
+ previousSplitter = isSplitter;
78
+ }
79
+ parts.push(buff);
80
+ return parts;
81
+ }
82
+ function upperFirst(str) {
83
+ return str ? str[0].toUpperCase() + str.slice(1) : "";
84
+ }
85
+ function lowerFirst(str) {
86
+ return str ? str[0].toLowerCase() + str.slice(1) : "";
87
+ }
88
+ function pascalCase(str, opts) {
89
+ return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
90
+ }
91
+ function camelCase(str, opts) {
92
+ return lowerFirst(pascalCase(str || "", opts));
93
+ }
94
+ function kebabCase(str, joiner) {
95
+ return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
96
+ }
97
+
98
+ function toArr(any) {
99
+ return any == void 0 ? [] : Array.isArray(any) ? any : [any];
100
+ }
101
+ function toVal(out, key, val, opts) {
102
+ let x;
103
+ const old = out[key];
104
+ 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;
105
+ out[key] = old == void 0 ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
106
+ }
107
+ function parseRawArgs(args = [], opts = {}) {
108
+ let k;
109
+ let arr;
110
+ let arg;
111
+ let name;
112
+ let val;
113
+ const out = { _: [] };
114
+ let i = 0;
115
+ let j = 0;
116
+ let idx = 0;
117
+ const len = args.length;
118
+ const alibi = opts.alias !== void 0;
119
+ const strict = opts.unknown !== void 0;
120
+ const defaults = opts.default !== void 0;
121
+ opts.alias = opts.alias || {};
122
+ opts.string = toArr(opts.string);
123
+ opts.boolean = toArr(opts.boolean);
124
+ if (alibi) {
125
+ for (k in opts.alias) {
126
+ arr = opts.alias[k] = toArr(opts.alias[k]);
127
+ for (i = 0; i < arr.length; i++) {
128
+ (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
129
+ }
130
+ }
131
+ }
132
+ for (i = opts.boolean.length; i-- > 0; ) {
133
+ arr = opts.alias[opts.boolean[i]] || [];
134
+ for (j = arr.length; j-- > 0; ) {
135
+ opts.boolean.push(arr[j]);
136
+ }
137
+ }
138
+ for (i = opts.string.length; i-- > 0; ) {
139
+ arr = opts.alias[opts.string[i]] || [];
140
+ for (j = arr.length; j-- > 0; ) {
141
+ opts.string.push(arr[j]);
142
+ }
143
+ }
144
+ if (defaults) {
145
+ for (k in opts.default) {
146
+ name = typeof opts.default[k];
147
+ arr = opts.alias[k] = opts.alias[k] || [];
148
+ if (opts[name] !== void 0) {
149
+ opts[name].push(k);
150
+ for (i = 0; i < arr.length; i++) {
151
+ opts[name].push(arr[i]);
152
+ }
153
+ }
154
+ }
155
+ }
156
+ const keys = strict ? Object.keys(opts.alias) : [];
157
+ for (i = 0; i < len; i++) {
158
+ arg = args[i];
159
+ if (arg === "--") {
160
+ out._ = out._.concat(args.slice(++i));
161
+ break;
162
+ }
163
+ for (j = 0; j < arg.length; j++) {
164
+ if (arg.charCodeAt(j) !== 45) {
165
+ break;
166
+ }
167
+ }
168
+ if (j === 0) {
169
+ out._.push(arg);
170
+ } else if (arg.substring(j, j + 3) === "no-") {
171
+ name = arg.slice(Math.max(0, j + 3));
172
+ if (strict && !~keys.indexOf(name)) {
173
+ return opts.unknown(arg);
174
+ }
175
+ out[name] = false;
176
+ } else {
177
+ for (idx = j + 1; idx < arg.length; idx++) {
178
+ if (arg.charCodeAt(idx) === 61) {
179
+ break;
180
+ }
181
+ }
182
+ name = arg.substring(j, idx);
183
+ val = arg.slice(Math.max(0, ++idx)) || i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i];
184
+ arr = j === 2 ? [name] : name;
185
+ for (idx = 0; idx < arr.length; idx++) {
186
+ name = arr[idx];
187
+ if (strict && !~keys.indexOf(name)) {
188
+ return opts.unknown("-".repeat(j) + name);
189
+ }
190
+ toVal(out, name, idx + 1 < arr.length || val, opts);
191
+ }
192
+ }
193
+ }
194
+ if (defaults) {
195
+ for (k in opts.default) {
196
+ if (out[k] === void 0) {
197
+ out[k] = opts.default[k];
198
+ }
199
+ }
200
+ }
201
+ if (alibi) {
202
+ for (k in out) {
203
+ arr = opts.alias[k] || [];
204
+ while (arr.length > 0) {
205
+ out[arr.shift()] = out[k];
206
+ }
207
+ }
208
+ }
209
+ return out;
210
+ }
211
+
212
+ function parseArgs(rawArgs, argsDef) {
213
+ const parseOptions = {
214
+ boolean: [],
215
+ string: [],
216
+ mixed: [],
217
+ alias: {},
218
+ default: {}
219
+ };
220
+ const args = resolveArgs(argsDef);
221
+ for (const arg of args) {
222
+ if (arg.type === "positional") {
223
+ continue;
224
+ }
225
+ if (arg.type === "string") {
226
+ parseOptions.string.push(arg.name);
227
+ } else if (arg.type === "boolean") {
228
+ parseOptions.boolean.push(arg.name);
229
+ }
230
+ if (arg.default !== void 0) {
231
+ parseOptions.default[arg.name] = arg.default;
232
+ }
233
+ if (arg.alias) {
234
+ parseOptions.alias[arg.name] = arg.alias;
235
+ }
236
+ }
237
+ const parsed = parseRawArgs(rawArgs, parseOptions);
238
+ const [...positionalArguments] = parsed._;
239
+ const parsedArgsProxy = new Proxy(parsed, {
240
+ get(target, prop) {
241
+ return target[prop] ?? target[camelCase(prop)] ?? target[kebabCase(prop)];
242
+ }
243
+ });
244
+ for (const [, arg] of args.entries()) {
245
+ if (arg.type === "positional") {
246
+ const nextPositionalArgument = positionalArguments.shift();
247
+ if (nextPositionalArgument !== void 0) {
248
+ parsedArgsProxy[arg.name] = nextPositionalArgument;
249
+ } else if (arg.default === void 0 && arg.required !== false) {
250
+ throw new CLIError(
251
+ `Missing required positional argument: ${arg.name.toUpperCase()}`,
252
+ "EARG"
253
+ );
254
+ } else {
255
+ parsedArgsProxy[arg.name] = arg.default;
256
+ }
257
+ } else if (arg.required && parsedArgsProxy[arg.name] === void 0) {
258
+ throw new CLIError(`Missing required argument: --${arg.name}`, "EARG");
259
+ }
260
+ }
261
+ return parsedArgsProxy;
262
+ }
263
+ function resolveArgs(argsDef) {
264
+ const args = [];
265
+ for (const [name, argDef] of Object.entries(argsDef || {})) {
266
+ args.push({
267
+ ...argDef,
268
+ name,
269
+ alias: toArray(argDef.alias)
270
+ });
271
+ }
272
+ return args;
273
+ }
274
+
275
+ function defineCommand(def) {
276
+ return def;
277
+ }
278
+ async function runCommand(cmd, opts) {
279
+ const cmdArgs = await resolveValue(cmd.args || {});
280
+ const parsedArgs = parseArgs(opts.rawArgs, cmdArgs);
281
+ const context = {
282
+ rawArgs: opts.rawArgs,
283
+ args: parsedArgs,
284
+ data: opts.data,
285
+ cmd
286
+ };
287
+ if (typeof cmd.setup === "function") {
288
+ await cmd.setup(context);
289
+ }
290
+ let result;
291
+ try {
292
+ const subCommands = await resolveValue(cmd.subCommands);
293
+ if (subCommands && Object.keys(subCommands).length > 0) {
294
+ const subCommandArgIndex = opts.rawArgs.findIndex(
295
+ (arg) => !arg.startsWith("-")
296
+ );
297
+ const subCommandName = opts.rawArgs[subCommandArgIndex];
298
+ if (subCommandName) {
299
+ if (!subCommands[subCommandName]) {
300
+ throw new CLIError(
301
+ `Unknown command \`${subCommandName}\``,
302
+ "E_UNKNOWN_COMMAND"
303
+ );
304
+ }
305
+ const subCommand = await resolveValue(subCommands[subCommandName]);
306
+ if (subCommand) {
307
+ await runCommand(subCommand, {
308
+ rawArgs: opts.rawArgs.slice(subCommandArgIndex + 1)
309
+ });
310
+ }
311
+ } else if (!cmd.run) {
312
+ throw new CLIError(`No command specified.`, "E_NO_COMMAND");
313
+ }
314
+ }
315
+ if (typeof cmd.run === "function") {
316
+ result = await cmd.run(context);
317
+ }
318
+ } finally {
319
+ if (typeof cmd.cleanup === "function") {
320
+ await cmd.cleanup(context);
321
+ }
322
+ }
323
+ return { result };
324
+ }
325
+ async function resolveSubCommand(cmd, rawArgs, parent) {
326
+ const subCommands = await resolveValue(cmd.subCommands);
327
+ if (subCommands && Object.keys(subCommands).length > 0) {
328
+ const subCommandArgIndex = rawArgs.findIndex((arg) => !arg.startsWith("-"));
329
+ const subCommandName = rawArgs[subCommandArgIndex];
330
+ const subCommand = await resolveValue(subCommands[subCommandName]);
331
+ if (subCommand) {
332
+ return resolveSubCommand(
333
+ subCommand,
334
+ rawArgs.slice(subCommandArgIndex + 1),
335
+ cmd
336
+ );
337
+ }
338
+ }
339
+ return [cmd, parent];
340
+ }
341
+
342
+ async function showUsage(cmd, parent) {
343
+ try {
344
+ consola.log(await renderUsage(cmd, parent) + "\n");
345
+ } catch (error) {
346
+ consola.error(error);
347
+ }
348
+ }
349
+ async function renderUsage(cmd, parent) {
350
+ const cmdMeta = await resolveValue(cmd.meta || {});
351
+ const cmdArgs = resolveArgs(await resolveValue(cmd.args || {}));
352
+ const parentMeta = await resolveValue(parent?.meta || {});
353
+ const commandName = `${parentMeta.name ? `${parentMeta.name} ` : ""}` + (cmdMeta.name || process.argv[1]);
354
+ const argLines = [];
355
+ const posLines = [];
356
+ const commandsLines = [];
357
+ const usageLine = [];
358
+ for (const arg of cmdArgs) {
359
+ if (arg.type === "positional") {
360
+ const name = arg.name.toUpperCase();
361
+ const isRequired = arg.required !== false && arg.default === void 0;
362
+ const defaultHint = arg.default ? `="${arg.default}"` : "";
363
+ posLines.push([
364
+ "`" + name + defaultHint + "`",
365
+ arg.description || "",
366
+ arg.valueHint ? `<${arg.valueHint}>` : ""
367
+ ]);
368
+ usageLine.push(isRequired ? `<${name}>` : `[${name}]`);
369
+ } else {
370
+ const isRequired = arg.required === true && arg.default === void 0;
371
+ const argStr = (arg.type === "boolean" && arg.default === true ? [
372
+ ...(arg.alias || []).map((a) => `--no-${a}`),
373
+ `--no-${arg.name}`
374
+ ].join(", ") : [...(arg.alias || []).map((a) => `-${a}`), `--${arg.name}`].join(
375
+ ", "
376
+ )) + (arg.type === "string" && (arg.valueHint || arg.default) ? `=${arg.valueHint ? `<${arg.valueHint}>` : `"${arg.default || ""}"`}` : "");
377
+ argLines.push([
378
+ "`" + argStr + (isRequired ? " (required)" : "") + "`",
379
+ arg.description || ""
380
+ ]);
381
+ if (isRequired) {
382
+ usageLine.push(argStr);
383
+ }
384
+ }
385
+ }
386
+ if (cmd.subCommands) {
387
+ const commandNames = [];
388
+ const subCommands = await resolveValue(cmd.subCommands);
389
+ for (const [name, sub] of Object.entries(subCommands)) {
390
+ const subCmd = await resolveValue(sub);
391
+ const meta = await resolveValue(subCmd?.meta);
392
+ commandsLines.push([`\`${name}\``, meta?.description || ""]);
393
+ commandNames.push(name);
394
+ }
395
+ usageLine.push(commandNames.join("|"));
396
+ }
397
+ const usageLines = [];
398
+ const version = cmdMeta.version || parentMeta.version;
399
+ usageLines.push(
400
+ colors.gray(
401
+ `${cmdMeta.description} (${commandName + (version ? ` v${version}` : "")})`
402
+ ),
403
+ ""
404
+ );
405
+ const hasOptions = argLines.length > 0 || posLines.length > 0;
406
+ usageLines.push(
407
+ `${colors.underline(colors.bold("USAGE"))} \`${commandName}${hasOptions ? " [OPTIONS]" : ""} ${usageLine.join(" ")}\``,
408
+ ""
409
+ );
410
+ if (posLines.length > 0) {
411
+ usageLines.push(colors.underline(colors.bold("ARGUMENTS")), "");
412
+ usageLines.push(formatLineColumns(posLines, " "));
413
+ usageLines.push("");
414
+ }
415
+ if (argLines.length > 0) {
416
+ usageLines.push(colors.underline(colors.bold("OPTIONS")), "");
417
+ usageLines.push(formatLineColumns(argLines, " "));
418
+ usageLines.push("");
419
+ }
420
+ if (commandsLines.length > 0) {
421
+ usageLines.push(colors.underline(colors.bold("COMMANDS")), "");
422
+ usageLines.push(formatLineColumns(commandsLines, " "));
423
+ usageLines.push(
424
+ "",
425
+ `Use \`${commandName} <command> --help\` for more information about a command.`
426
+ );
427
+ }
428
+ return usageLines.filter((l) => typeof l === "string").join("\n");
429
+ }
430
+
431
+ async function runMain(cmd, opts = {}) {
432
+ const rawArgs = opts.rawArgs || process.argv.slice(2);
433
+ const showUsage$1 = opts.showUsage || showUsage;
434
+ try {
435
+ if (rawArgs.includes("--help") || rawArgs.includes("-h")) {
436
+ await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
437
+ process.exit(0);
438
+ } else if (rawArgs.length === 1 && rawArgs[0] === "--version") {
439
+ const meta = typeof cmd.meta === "function" ? await cmd.meta() : await cmd.meta;
440
+ if (!meta?.version) {
441
+ throw new CLIError("No version specified", "E_NO_VERSION");
442
+ }
443
+ consola.log(meta.version);
444
+ } else {
445
+ await runCommand(cmd, { rawArgs });
446
+ }
447
+ } catch (error) {
448
+ const isCLIError = error instanceof CLIError;
449
+ if (!isCLIError) {
450
+ consola.error(error, "\n");
451
+ }
452
+ if (isCLIError) {
453
+ await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
454
+ }
455
+ consola.error(error.message);
456
+ process.exit(1);
457
+ }
458
+ }
459
+ function createMain(cmd) {
460
+ return (opts = {}) => runMain(cmd, opts);
461
+ }
462
+
463
+ export { createMain, defineCommand, parseArgs, renderUsage, runCommand, runMain, showUsage };