storybook 9.0.0-alpha.1 → 9.0.0-alpha.10

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 (259) hide show
  1. package/README.md +31 -29
  2. package/assets/browser/favicon.svg +1 -0
  3. package/assets/browser/nunito-sans-bold-italic.woff2 +0 -0
  4. package/assets/browser/nunito-sans-bold.woff2 +0 -0
  5. package/assets/browser/nunito-sans-italic.woff2 +0 -0
  6. package/assets/browser/nunito-sans-regular.woff2 +0 -0
  7. package/assets/docs/addon-controls-args-annotated.png +0 -0
  8. package/assets/docs/addon-controls-args-background-color.png +0 -0
  9. package/assets/docs/addon-controls-args-background-string.png +0 -0
  10. package/assets/docs/addon-controls-args-docs.png +0 -0
  11. package/assets/docs/addon-controls-args-logging.png +0 -0
  12. package/assets/docs/addon-controls-args-no-annotation.png +0 -0
  13. package/assets/docs/addon-controls-args-reflow-slider.png +0 -0
  14. package/assets/docs/addon-controls-args-reflow.png +0 -0
  15. package/assets/docs/addon-controls-args-template.png +0 -0
  16. package/assets/docs/addon-controls-expanded.png +0 -0
  17. package/assets/docs/addon-controls-hero.gif +0 -0
  18. package/assets/docs/addon-controls-install.png +0 -0
  19. package/assets/docs/hero.gif +0 -0
  20. package/assets/docs/message-reference.png +0 -0
  21. package/assets/docs/viewport.png +0 -0
  22. package/assets/server/addon.tsconfig.json +6 -0
  23. package/assets/server/base-preview-body.html +119 -0
  24. package/assets/server/base-preview-head.html +451 -0
  25. package/assets/server/template.ejs +87 -0
  26. package/bin/index.cjs +1 -1
  27. package/dist/actions/decorator.d.ts +6 -0
  28. package/dist/actions/decorator.js +139 -0
  29. package/dist/actions/index.cjs +127 -0
  30. package/dist/actions/index.d.ts +105 -0
  31. package/dist/actions/index.js +112 -0
  32. package/dist/actions/manager.js +1196 -0
  33. package/dist/actions/preview.cjs +165 -0
  34. package/dist/actions/preview.d.ts +55 -0
  35. package/dist/actions/preview.js +156 -0
  36. package/dist/babel/index.cjs +54034 -0
  37. package/dist/babel/index.d.ts +7488 -0
  38. package/dist/babel/index.js +54044 -0
  39. package/dist/bin/index.cjs +119 -0
  40. package/dist/bin/index.js +113 -0
  41. package/dist/builder-manager/index.cjs +2140 -0
  42. package/dist/builder-manager/index.d.ts +19 -0
  43. package/dist/builder-manager/index.js +2162 -0
  44. package/dist/channels/index.cjs +1913 -0
  45. package/dist/channels/index.d.ts +108 -0
  46. package/dist/channels/index.js +1881 -0
  47. package/dist/cli/bin/index.cjs +2687 -0
  48. package/dist/cli/bin/index.d.ts +2 -0
  49. package/dist/cli/bin/index.js +2707 -0
  50. package/dist/cli/index.cjs +17327 -0
  51. package/dist/cli/index.d.ts +209 -0
  52. package/dist/cli/index.js +17349 -0
  53. package/dist/client-logger/index.cjs +80 -0
  54. package/dist/client-logger/index.d.ts +29 -0
  55. package/dist/client-logger/index.js +64 -0
  56. package/dist/common/index.cjs +20569 -0
  57. package/dist/common/index.d.ts +949 -0
  58. package/dist/common/index.js +20654 -0
  59. package/dist/components/index.cjs +27924 -0
  60. package/dist/components/index.d.ts +1423 -0
  61. package/dist/components/index.js +24673 -0
  62. package/dist/controls/decorator.d.ts +5 -0
  63. package/dist/controls/decorator.js +8 -0
  64. package/dist/controls/index.cjs +26 -0
  65. package/dist/controls/index.d.ts +39 -0
  66. package/dist/controls/index.js +6 -0
  67. package/dist/controls/manager.js +5545 -0
  68. package/dist/controls/preview.cjs +26 -0
  69. package/dist/controls/preview.d.ts +55 -0
  70. package/dist/controls/preview.js +9 -0
  71. package/dist/core-events/index.cjs +167 -0
  72. package/dist/core-events/index.d.ts +426 -0
  73. package/dist/core-events/index.js +149 -0
  74. package/dist/core-server/index.cjs +38183 -0
  75. package/dist/core-server/index.d.ts +720 -0
  76. package/dist/core-server/index.js +38272 -0
  77. package/dist/core-server/presets/common-manager.js +20 -0
  78. package/dist/core-server/presets/common-override-preset.cjs +4824 -0
  79. package/dist/core-server/presets/common-override-preset.js +4829 -0
  80. package/dist/core-server/presets/common-preset.cjs +10231 -0
  81. package/dist/core-server/presets/common-preset.js +10309 -0
  82. package/dist/csf/index.cjs +179 -0
  83. package/dist/csf/index.d.ts +750 -0
  84. package/dist/csf/index.js +172 -0
  85. package/dist/csf-tools/index.cjs +1422 -0
  86. package/dist/csf-tools/index.d.ts +250 -0
  87. package/dist/csf-tools/index.js +1439 -0
  88. package/dist/docs-tools/index.cjs +2891 -0
  89. package/dist/docs-tools/index.d.ts +162 -0
  90. package/dist/docs-tools/index.js +2876 -0
  91. package/dist/index.cjs +17 -1
  92. package/dist/index.d.ts +1 -1
  93. package/dist/index.js +2 -7
  94. package/dist/instrumenter/index.cjs +3485 -0
  95. package/dist/instrumenter/index.d.ts +104 -0
  96. package/dist/instrumenter/index.js +4965 -0
  97. package/dist/manager/globals-module-info.cjs +817 -0
  98. package/dist/manager/globals-module-info.d.ts +36 -0
  99. package/dist/manager/globals-module-info.js +804 -0
  100. package/dist/manager/globals-runtime.js +77536 -0
  101. package/dist/manager/globals.cjs +47 -0
  102. package/dist/manager/globals.d.ts +24 -0
  103. package/dist/manager/globals.js +34 -0
  104. package/dist/manager/runtime.js +12323 -0
  105. package/dist/manager-api/index.cjs +11074 -0
  106. package/dist/manager-api/index.d.ts +1512 -0
  107. package/dist/manager-api/index.js +4835 -0
  108. package/dist/manager-errors.d.ts +89 -0
  109. package/dist/manager-errors.js +99 -0
  110. package/dist/node-logger/index.cjs +1642 -0
  111. package/dist/node-logger/index.d.ts +117 -0
  112. package/dist/node-logger/index.js +1652 -0
  113. package/dist/preview/globals.cjs +38 -0
  114. package/dist/preview/globals.d.ts +15 -0
  115. package/dist/preview/globals.js +25 -0
  116. package/dist/preview/runtime.js +43629 -0
  117. package/dist/preview-api/index.cjs +5224 -0
  118. package/dist/preview-api/index.d.ts +1093 -0
  119. package/dist/preview-api/index.js +5292 -0
  120. package/dist/preview-errors.cjs +503 -0
  121. package/dist/preview-errors.d.ts +212 -0
  122. package/dist/preview-errors.js +449 -0
  123. package/dist/router/index.cjs +3296 -0
  124. package/dist/router/index.d.ts +385 -0
  125. package/dist/router/index.js +1843 -0
  126. package/dist/server-errors.cjs +727 -0
  127. package/dist/server-errors.d.ts +296 -0
  128. package/dist/server-errors.js +728 -0
  129. package/dist/telemetry/index.cjs +2756 -0
  130. package/dist/telemetry/index.d.ts +133 -0
  131. package/dist/telemetry/index.js +2797 -0
  132. package/dist/test/index.cjs +35685 -0
  133. package/dist/test/index.d.ts +186 -0
  134. package/dist/test/index.js +33751 -0
  135. package/dist/test/preview.cjs +15869 -0
  136. package/dist/test/preview.d.ts +54 -0
  137. package/dist/test/preview.js +14440 -0
  138. package/dist/test/spy.cjs +257 -0
  139. package/dist/test/spy.d.ts +66 -0
  140. package/dist/test/spy.js +239 -0
  141. package/dist/theming/create.cjs +232 -0
  142. package/dist/theming/create.d.ts +50 -0
  143. package/dist/theming/create.js +216 -0
  144. package/dist/theming/index.cjs +2665 -0
  145. package/dist/theming/index.d.ts +11939 -0
  146. package/dist/theming/index.js +2485 -0
  147. package/dist/types/index.cjs +27 -0
  148. package/dist/types/index.d.ts +2795 -0
  149. package/dist/types/index.js +7 -0
  150. package/dist/viewport/index.cjs +310 -0
  151. package/dist/viewport/index.d.ts +320 -0
  152. package/dist/viewport/index.js +290 -0
  153. package/dist/viewport/manager.js +400 -0
  154. package/dist/viewport/preview.cjs +35 -0
  155. package/dist/viewport/preview.d.ts +69 -0
  156. package/dist/viewport/preview.js +19 -0
  157. package/package.json +518 -209
  158. package/.eslintrc.cjs +0 -31
  159. package/__mocks__/@aw-web-design/x-default-browser.js +0 -2
  160. package/core/babel/index.cjs +0 -1
  161. package/core/babel/index.d.ts +0 -2
  162. package/core/babel/index.js +0 -1
  163. package/core/builder-manager/index.cjs +0 -1
  164. package/core/builder-manager/index.d.ts +0 -2
  165. package/core/builder-manager/index.js +0 -1
  166. package/core/channels/index.cjs +0 -1
  167. package/core/channels/index.d.ts +0 -2
  168. package/core/channels/index.js +0 -1
  169. package/core/cli/bin/index.cjs +0 -1
  170. package/core/cli/bin/index.d.ts +0 -2
  171. package/core/cli/bin/index.js +0 -1
  172. package/core/cli/index.cjs +0 -1
  173. package/core/cli/index.d.ts +0 -2
  174. package/core/cli/index.js +0 -1
  175. package/core/client-logger/index.cjs +0 -1
  176. package/core/client-logger/index.d.ts +0 -2
  177. package/core/client-logger/index.js +0 -1
  178. package/core/common/index.cjs +0 -1
  179. package/core/common/index.d.ts +0 -2
  180. package/core/common/index.js +0 -1
  181. package/core/components/index.cjs +0 -1
  182. package/core/components/index.d.ts +0 -2
  183. package/core/components/index.js +0 -1
  184. package/core/core-events/index.cjs +0 -1
  185. package/core/core-events/index.d.ts +0 -2
  186. package/core/core-events/index.js +0 -1
  187. package/core/core-server/index.cjs +0 -1
  188. package/core/core-server/index.d.ts +0 -2
  189. package/core/core-server/index.js +0 -1
  190. package/core/core-server/presets/common-manager.js +0 -1
  191. package/core/core-server/presets/common-override-preset.cjs +0 -1
  192. package/core/core-server/presets/common-override-preset.js +0 -1
  193. package/core/core-server/presets/common-preset.cjs +0 -1
  194. package/core/core-server/presets/common-preset.js +0 -1
  195. package/core/csf/index.cjs +0 -1
  196. package/core/csf/index.d.ts +0 -2
  197. package/core/csf/index.js +0 -1
  198. package/core/csf-tools/index.cjs +0 -1
  199. package/core/csf-tools/index.d.ts +0 -2
  200. package/core/csf-tools/index.js +0 -1
  201. package/core/docs-tools/index.cjs +0 -1
  202. package/core/docs-tools/index.d.ts +0 -2
  203. package/core/docs-tools/index.js +0 -1
  204. package/core/index.cjs +0 -1
  205. package/core/index.d.ts +0 -2
  206. package/core/index.js +0 -1
  207. package/core/manager/globals-module-info.cjs +0 -1
  208. package/core/manager/globals-module-info.d.ts +0 -2
  209. package/core/manager/globals-module-info.js +0 -1
  210. package/core/manager/globals-runtime.js +0 -1
  211. package/core/manager/globals.cjs +0 -1
  212. package/core/manager/globals.d.ts +0 -2
  213. package/core/manager/globals.js +0 -1
  214. package/core/manager-api/index.cjs +0 -1
  215. package/core/manager-api/index.d.ts +0 -2
  216. package/core/manager-api/index.js +0 -1
  217. package/core/manager-errors.d.ts +0 -2
  218. package/core/manager-errors.js +0 -1
  219. package/core/node-logger/index.cjs +0 -1
  220. package/core/node-logger/index.d.ts +0 -2
  221. package/core/node-logger/index.js +0 -1
  222. package/core/preview/globals.cjs +0 -1
  223. package/core/preview/globals.d.ts +0 -2
  224. package/core/preview/globals.js +0 -1
  225. package/core/preview/runtime.js +0 -1
  226. package/core/preview-api/index.cjs +0 -1
  227. package/core/preview-api/index.d.ts +0 -2
  228. package/core/preview-api/index.js +0 -1
  229. package/core/preview-errors.cjs +0 -1
  230. package/core/preview-errors.d.ts +0 -2
  231. package/core/preview-errors.js +0 -1
  232. package/core/router/index.cjs +0 -1
  233. package/core/router/index.d.ts +0 -2
  234. package/core/router/index.js +0 -1
  235. package/core/server-errors.cjs +0 -1
  236. package/core/server-errors.d.ts +0 -2
  237. package/core/server-errors.js +0 -1
  238. package/core/telemetry/index.cjs +0 -1
  239. package/core/telemetry/index.d.ts +0 -2
  240. package/core/telemetry/index.js +0 -1
  241. package/core/theming/create.cjs +0 -1
  242. package/core/theming/create.d.ts +0 -2
  243. package/core/theming/create.js +0 -1
  244. package/core/theming/index.cjs +0 -1
  245. package/core/theming/index.d.ts +0 -2
  246. package/core/theming/index.js +0 -1
  247. package/core/types/index.cjs +0 -1
  248. package/core/types/index.d.ts +0 -2
  249. package/core/types/index.js +0 -1
  250. package/core.cjs +0 -0
  251. package/core.d.ts +0 -0
  252. package/core.js +0 -1
  253. package/dist/chunk-OWLSIX54.js +0 -8
  254. package/dist/core-path.cjs +0 -1
  255. package/dist/core-path.d.ts +0 -3
  256. package/dist/core-path.js +0 -9
  257. package/dist/proxy.cjs +0 -1
  258. package/dist/proxy.d.ts +0 -2
  259. package/dist/proxy.js +0 -9
@@ -0,0 +1,2687 @@
1
+ "use strict";
2
+ var Me = Object.create;
3
+ var L = Object.defineProperty;
4
+ var Le = Object.getOwnPropertyDescriptor;
5
+ var We = Object.getOwnPropertyNames;
6
+ var Re = Object.getPrototypeOf, Ge = Object.prototype.hasOwnProperty;
7
+ var d = (n, e) => L(n, "name", { value: e, configurable: !0 });
8
+ var b = (n, e) => () => (e || n((e = { exports: {} }).exports, e), e.exports);
9
+ var Ue = (n, e, t, i) => {
10
+ if (e && typeof e == "object" || typeof e == "function")
11
+ for (let s of We(e))
12
+ !Ge.call(n, s) && s !== t && L(n, s, { get: () => e[s], enumerable: !(i = Le(e, s)) || i.enumerable });
13
+ return n;
14
+ };
15
+ var $ = (n, e, t) => (t = n != null ? Me(Re(n)) : {}, Ue(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ e || !n || !n.__esModule ? L(t, "default", { value: n, enumerable: !0 }) : t,
21
+ n
22
+ ));
23
+
24
+ // ../node_modules/commander/lib/error.js
25
+ var k = b((R) => {
26
+ var q = class extends Error {
27
+ static {
28
+ d(this, "CommanderError");
29
+ }
30
+ /**
31
+ * Constructs the CommanderError class
32
+ * @param {number} exitCode suggested exit code which could be used with process.exit
33
+ * @param {string} code an id string representing the error
34
+ * @param {string} message human-readable description of the error
35
+ */
36
+ constructor(e, t, i) {
37
+ super(i), Error.captureStackTrace(this, this.constructor), this.name = this.constructor.name, this.code = t, this.exitCode = e, this.nestedError =
38
+ void 0;
39
+ }
40
+ }, W = class extends q {
41
+ static {
42
+ d(this, "InvalidArgumentError");
43
+ }
44
+ /**
45
+ * Constructs the InvalidArgumentError class
46
+ * @param {string} [message] explanation of why argument is invalid
47
+ */
48
+ constructor(e) {
49
+ super(1, "commander.invalidArgument", e), Error.captureStackTrace(this, this.constructor), this.name = this.constructor.name;
50
+ }
51
+ };
52
+ R.CommanderError = q;
53
+ R.InvalidArgumentError = W;
54
+ });
55
+
56
+ // ../node_modules/commander/lib/argument.js
57
+ var V = b((U) => {
58
+ var { InvalidArgumentError: Je } = k(), G = class {
59
+ static {
60
+ d(this, "Argument");
61
+ }
62
+ /**
63
+ * Initialize a new command argument with the given name and description.
64
+ * The default is that the argument is required, and you can explicitly
65
+ * indicate this with <> around the name. Put [] around the name for an optional argument.
66
+ *
67
+ * @param {string} name
68
+ * @param {string} [description]
69
+ */
70
+ constructor(e, t) {
71
+ switch (this.description = t || "", this.variadic = !1, this.parseArg = void 0, this.defaultValue = void 0, this.defaultValueDescription =
72
+ void 0, this.argChoices = void 0, e[0]) {
73
+ case "<":
74
+ this.required = !0, this._name = e.slice(1, -1);
75
+ break;
76
+ case "[":
77
+ this.required = !1, this._name = e.slice(1, -1);
78
+ break;
79
+ default:
80
+ this.required = !0, this._name = e;
81
+ break;
82
+ }
83
+ this._name.length > 3 && this._name.slice(-3) === "..." && (this.variadic = !0, this._name = this._name.slice(0, -3));
84
+ }
85
+ /**
86
+ * Return argument name.
87
+ *
88
+ * @return {string}
89
+ */
90
+ name() {
91
+ return this._name;
92
+ }
93
+ /**
94
+ * @package
95
+ */
96
+ _concatValue(e, t) {
97
+ return t === this.defaultValue || !Array.isArray(t) ? [e] : t.concat(e);
98
+ }
99
+ /**
100
+ * Set the default value, and optionally supply the description to be displayed in the help.
101
+ *
102
+ * @param {*} value
103
+ * @param {string} [description]
104
+ * @return {Argument}
105
+ */
106
+ default(e, t) {
107
+ return this.defaultValue = e, this.defaultValueDescription = t, this;
108
+ }
109
+ /**
110
+ * Set the custom handler for processing CLI command arguments into argument values.
111
+ *
112
+ * @param {Function} [fn]
113
+ * @return {Argument}
114
+ */
115
+ argParser(e) {
116
+ return this.parseArg = e, this;
117
+ }
118
+ /**
119
+ * Only allow argument value to be one of choices.
120
+ *
121
+ * @param {string[]} values
122
+ * @return {Argument}
123
+ */
124
+ choices(e) {
125
+ return this.argChoices = e.slice(), this.parseArg = (t, i) => {
126
+ if (!this.argChoices.includes(t))
127
+ throw new Je(
128
+ `Allowed choices are ${this.argChoices.join(", ")}.`
129
+ );
130
+ return this.variadic ? this._concatValue(t, i) : t;
131
+ }, this;
132
+ }
133
+ /**
134
+ * Make argument required.
135
+ *
136
+ * @returns {Argument}
137
+ */
138
+ argRequired() {
139
+ return this.required = !0, this;
140
+ }
141
+ /**
142
+ * Make argument optional.
143
+ *
144
+ * @returns {Argument}
145
+ */
146
+ argOptional() {
147
+ return this.required = !1, this;
148
+ }
149
+ };
150
+ function Ye(n) {
151
+ let e = n.name() + (n.variadic === !0 ? "..." : "");
152
+ return n.required ? "<" + e + ">" : "[" + e + "]";
153
+ }
154
+ d(Ye, "humanReadableArgName");
155
+ U.Argument = G;
156
+ U.humanReadableArgName = Ye;
157
+ });
158
+
159
+ // ../node_modules/commander/lib/help.js
160
+ var Y = b((ce) => {
161
+ var { humanReadableArgName: ze } = V(), J = class {
162
+ static {
163
+ d(this, "Help");
164
+ }
165
+ constructor() {
166
+ this.helpWidth = void 0, this.sortSubcommands = !1, this.sortOptions = !1, this.showGlobalOptions = !1;
167
+ }
168
+ /**
169
+ * Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
170
+ *
171
+ * @param {Command} cmd
172
+ * @returns {Command[]}
173
+ */
174
+ visibleCommands(e) {
175
+ let t = e.commands.filter((s) => !s._hidden), i = e._getHelpCommand();
176
+ return i && !i._hidden && t.push(i), this.sortSubcommands && t.sort((s, r) => s.name().localeCompare(r.name())), t;
177
+ }
178
+ /**
179
+ * Compare options for sort.
180
+ *
181
+ * @param {Option} a
182
+ * @param {Option} b
183
+ * @returns {number}
184
+ */
185
+ compareOptions(e, t) {
186
+ let i = /* @__PURE__ */ d((s) => s.short ? s.short.replace(/^-/, "") : s.long.replace(/^--/, ""), "getSortKey");
187
+ return i(e).localeCompare(i(t));
188
+ }
189
+ /**
190
+ * Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
191
+ *
192
+ * @param {Command} cmd
193
+ * @returns {Option[]}
194
+ */
195
+ visibleOptions(e) {
196
+ let t = e.options.filter((s) => !s.hidden), i = e._getHelpOption();
197
+ if (i && !i.hidden) {
198
+ let s = i.short && e._findOption(i.short), r = i.long && e._findOption(i.long);
199
+ !s && !r ? t.push(i) : i.long && !r ? t.push(
200
+ e.createOption(i.long, i.description)
201
+ ) : i.short && !s && t.push(
202
+ e.createOption(i.short, i.description)
203
+ );
204
+ }
205
+ return this.sortOptions && t.sort(this.compareOptions), t;
206
+ }
207
+ /**
208
+ * Get an array of the visible global options. (Not including help.)
209
+ *
210
+ * @param {Command} cmd
211
+ * @returns {Option[]}
212
+ */
213
+ visibleGlobalOptions(e) {
214
+ if (!this.showGlobalOptions) return [];
215
+ let t = [];
216
+ for (let i = e.parent; i; i = i.parent) {
217
+ let s = i.options.filter(
218
+ (r) => !r.hidden
219
+ );
220
+ t.push(...s);
221
+ }
222
+ return this.sortOptions && t.sort(this.compareOptions), t;
223
+ }
224
+ /**
225
+ * Get an array of the arguments if any have a description.
226
+ *
227
+ * @param {Command} cmd
228
+ * @returns {Argument[]}
229
+ */
230
+ visibleArguments(e) {
231
+ return e._argsDescription && e.registeredArguments.forEach((t) => {
232
+ t.description = t.description || e._argsDescription[t.name()] || "";
233
+ }), e.registeredArguments.find((t) => t.description) ? e.registeredArguments : [];
234
+ }
235
+ /**
236
+ * Get the command term to show in the list of subcommands.
237
+ *
238
+ * @param {Command} cmd
239
+ * @returns {string}
240
+ */
241
+ subcommandTerm(e) {
242
+ let t = e.registeredArguments.map((i) => ze(i)).join(" ");
243
+ return e._name + (e._aliases[0] ? "|" + e._aliases[0] : "") + (e.options.length ? " [options]" : "") + // simplistic check for non-help option
244
+ (t ? " " + t : "");
245
+ }
246
+ /**
247
+ * Get the option term to show in the list of options.
248
+ *
249
+ * @param {Option} option
250
+ * @returns {string}
251
+ */
252
+ optionTerm(e) {
253
+ return e.flags;
254
+ }
255
+ /**
256
+ * Get the argument term to show in the list of arguments.
257
+ *
258
+ * @param {Argument} argument
259
+ * @returns {string}
260
+ */
261
+ argumentTerm(e) {
262
+ return e.name();
263
+ }
264
+ /**
265
+ * Get the longest command term length.
266
+ *
267
+ * @param {Command} cmd
268
+ * @param {Help} helper
269
+ * @returns {number}
270
+ */
271
+ longestSubcommandTermLength(e, t) {
272
+ return t.visibleCommands(e).reduce((i, s) => Math.max(i, t.subcommandTerm(s).length), 0);
273
+ }
274
+ /**
275
+ * Get the longest option term length.
276
+ *
277
+ * @param {Command} cmd
278
+ * @param {Help} helper
279
+ * @returns {number}
280
+ */
281
+ longestOptionTermLength(e, t) {
282
+ return t.visibleOptions(e).reduce((i, s) => Math.max(i, t.optionTerm(s).length), 0);
283
+ }
284
+ /**
285
+ * Get the longest global option term length.
286
+ *
287
+ * @param {Command} cmd
288
+ * @param {Help} helper
289
+ * @returns {number}
290
+ */
291
+ longestGlobalOptionTermLength(e, t) {
292
+ return t.visibleGlobalOptions(e).reduce((i, s) => Math.max(i, t.optionTerm(s).length), 0);
293
+ }
294
+ /**
295
+ * Get the longest argument term length.
296
+ *
297
+ * @param {Command} cmd
298
+ * @param {Help} helper
299
+ * @returns {number}
300
+ */
301
+ longestArgumentTermLength(e, t) {
302
+ return t.visibleArguments(e).reduce((i, s) => Math.max(i, t.argumentTerm(s).length), 0);
303
+ }
304
+ /**
305
+ * Get the command usage to be displayed at the top of the built-in help.
306
+ *
307
+ * @param {Command} cmd
308
+ * @returns {string}
309
+ */
310
+ commandUsage(e) {
311
+ let t = e._name;
312
+ e._aliases[0] && (t = t + "|" + e._aliases[0]);
313
+ let i = "";
314
+ for (let s = e.parent; s; s = s.parent)
315
+ i = s.name() + " " + i;
316
+ return i + t + " " + e.usage();
317
+ }
318
+ /**
319
+ * Get the description for the command.
320
+ *
321
+ * @param {Command} cmd
322
+ * @returns {string}
323
+ */
324
+ commandDescription(e) {
325
+ return e.description();
326
+ }
327
+ /**
328
+ * Get the subcommand summary to show in the list of subcommands.
329
+ * (Fallback to description for backwards compatibility.)
330
+ *
331
+ * @param {Command} cmd
332
+ * @returns {string}
333
+ */
334
+ subcommandDescription(e) {
335
+ return e.summary() || e.description();
336
+ }
337
+ /**
338
+ * Get the option description to show in the list of options.
339
+ *
340
+ * @param {Option} option
341
+ * @return {string}
342
+ */
343
+ optionDescription(e) {
344
+ let t = [];
345
+ return e.argChoices && t.push(
346
+ // use stringify to match the display of the default value
347
+ `choices: ${e.argChoices.map((i) => JSON.stringify(i)).join(", ")}`
348
+ ), e.defaultValue !== void 0 && (e.required || e.optional || e.isBoolean() && typeof e.defaultValue == "boolean") && t.push(
349
+ `default: ${e.defaultValueDescription || JSON.stringify(e.defaultValue)}`
350
+ ), e.presetArg !== void 0 && e.optional && t.push(`preset: ${JSON.stringify(e.presetArg)}`), e.envVar !== void 0 && t.push(`env: ${e.envVar}`),
351
+ t.length > 0 ? `${e.description} (${t.join(", ")})` : e.description;
352
+ }
353
+ /**
354
+ * Get the argument description to show in the list of arguments.
355
+ *
356
+ * @param {Argument} argument
357
+ * @return {string}
358
+ */
359
+ argumentDescription(e) {
360
+ let t = [];
361
+ if (e.argChoices && t.push(
362
+ // use stringify to match the display of the default value
363
+ `choices: ${e.argChoices.map((i) => JSON.stringify(i)).join(", ")}`
364
+ ), e.defaultValue !== void 0 && t.push(
365
+ `default: ${e.defaultValueDescription || JSON.stringify(e.defaultValue)}`
366
+ ), t.length > 0) {
367
+ let i = `(${t.join(", ")})`;
368
+ return e.description ? `${e.description} ${i}` : i;
369
+ }
370
+ return e.description;
371
+ }
372
+ /**
373
+ * Generate the built-in help text.
374
+ *
375
+ * @param {Command} cmd
376
+ * @param {Help} helper
377
+ * @returns {string}
378
+ */
379
+ formatHelp(e, t) {
380
+ let i = t.padWidth(e, t), s = t.helpWidth || 80, r = 2, o = 2;
381
+ function l(f, v) {
382
+ if (v) {
383
+ let M = `${f.padEnd(i + o)}${v}`;
384
+ return t.wrap(
385
+ M,
386
+ s - r,
387
+ i + o
388
+ );
389
+ }
390
+ return f;
391
+ }
392
+ d(l, "formatItem");
393
+ function a(f) {
394
+ return f.join(`
395
+ `).replace(/^/gm, " ".repeat(r));
396
+ }
397
+ d(a, "formatList");
398
+ let c = [`Usage: ${t.commandUsage(e)}`, ""], u = t.commandDescription(e);
399
+ u.length > 0 && (c = c.concat([
400
+ t.wrap(u, s, 0),
401
+ ""
402
+ ]));
403
+ let p = t.visibleArguments(e).map((f) => l(
404
+ t.argumentTerm(f),
405
+ t.argumentDescription(f)
406
+ ));
407
+ p.length > 0 && (c = c.concat(["Arguments:", a(p), ""]));
408
+ let m = t.visibleOptions(e).map((f) => l(
409
+ t.optionTerm(f),
410
+ t.optionDescription(f)
411
+ ));
412
+ if (m.length > 0 && (c = c.concat(["Options:", a(m), ""])), this.showGlobalOptions) {
413
+ let f = t.visibleGlobalOptions(e).map((v) => l(
414
+ t.optionTerm(v),
415
+ t.optionDescription(v)
416
+ ));
417
+ f.length > 0 && (c = c.concat([
418
+ "Global Options:",
419
+ a(f),
420
+ ""
421
+ ]));
422
+ }
423
+ let _ = t.visibleCommands(e).map((f) => l(
424
+ t.subcommandTerm(f),
425
+ t.subcommandDescription(f)
426
+ ));
427
+ return _.length > 0 && (c = c.concat(["Commands:", a(_), ""])), c.join(`
428
+ `);
429
+ }
430
+ /**
431
+ * Calculate the pad width from the maximum term length.
432
+ *
433
+ * @param {Command} cmd
434
+ * @param {Help} helper
435
+ * @returns {number}
436
+ */
437
+ padWidth(e, t) {
438
+ return Math.max(
439
+ t.longestOptionTermLength(e, t),
440
+ t.longestGlobalOptionTermLength(e, t),
441
+ t.longestSubcommandTermLength(e, t),
442
+ t.longestArgumentTermLength(e, t)
443
+ );
444
+ }
445
+ /**
446
+ * Wrap the given string to width characters per line, with lines after the first indented.
447
+ * Do not wrap if insufficient room for wrapping (minColumnWidth), or string is manually formatted.
448
+ *
449
+ * @param {string} str
450
+ * @param {number} width
451
+ * @param {number} indent
452
+ * @param {number} [minColumnWidth=40]
453
+ * @return {string}
454
+ *
455
+ */
456
+ wrap(e, t, i, s = 40) {
457
+ let r = " \\f\\t\\v\xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF", o = new RegExp(`[\\n][${r}]+`);
458
+ if (e.match(o)) return e;
459
+ let l = t - i;
460
+ if (l < s) return e;
461
+ let a = e.slice(0, i), c = e.slice(i).replace(`\r
462
+ `, `
463
+ `), u = " ".repeat(i), m = "\\s\u200B", _ = new RegExp(
464
+ `
465
+ |.{1,${l - 1}}([${m}]|$)|[^${m}]+?([${m}]|$)`,
466
+ "g"
467
+ ), f = c.match(_) || [];
468
+ return a + f.map((v, M) => v === `
469
+ ` ? "" : (M > 0 ? u : "") + v.trimEnd()).join(`
470
+ `);
471
+ }
472
+ };
473
+ ce.Help = J;
474
+ });
475
+
476
+ // ../node_modules/commander/lib/option.js
477
+ var X = b((Q) => {
478
+ var { InvalidArgumentError: Ke } = k(), z = class {
479
+ static {
480
+ d(this, "Option");
481
+ }
482
+ /**
483
+ * Initialize a new `Option` with the given `flags` and `description`.
484
+ *
485
+ * @param {string} flags
486
+ * @param {string} [description]
487
+ */
488
+ constructor(e, t) {
489
+ this.flags = e, this.description = t || "", this.required = e.includes("<"), this.optional = e.includes("["), this.variadic = /\w\.\.\.[>\]]$/.
490
+ test(e), this.mandatory = !1;
491
+ let i = Xe(e);
492
+ this.short = i.shortFlag, this.long = i.longFlag, this.negate = !1, this.long && (this.negate = this.long.startsWith("--no-")), this.defaultValue =
493
+ void 0, this.defaultValueDescription = void 0, this.presetArg = void 0, this.envVar = void 0, this.parseArg = void 0, this.hidden = !1,
494
+ this.argChoices = void 0, this.conflictsWith = [], this.implied = void 0;
495
+ }
496
+ /**
497
+ * Set the default value, and optionally supply the description to be displayed in the help.
498
+ *
499
+ * @param {*} value
500
+ * @param {string} [description]
501
+ * @return {Option}
502
+ */
503
+ default(e, t) {
504
+ return this.defaultValue = e, this.defaultValueDescription = t, this;
505
+ }
506
+ /**
507
+ * Preset to use when option used without option-argument, especially optional but also boolean and negated.
508
+ * The custom processing (parseArg) is called.
509
+ *
510
+ * @example
511
+ * new Option('--color').default('GREYSCALE').preset('RGB');
512
+ * new Option('--donate [amount]').preset('20').argParser(parseFloat);
513
+ *
514
+ * @param {*} arg
515
+ * @return {Option}
516
+ */
517
+ preset(e) {
518
+ return this.presetArg = e, this;
519
+ }
520
+ /**
521
+ * Add option name(s) that conflict with this option.
522
+ * An error will be displayed if conflicting options are found during parsing.
523
+ *
524
+ * @example
525
+ * new Option('--rgb').conflicts('cmyk');
526
+ * new Option('--js').conflicts(['ts', 'jsx']);
527
+ *
528
+ * @param {(string | string[])} names
529
+ * @return {Option}
530
+ */
531
+ conflicts(e) {
532
+ return this.conflictsWith = this.conflictsWith.concat(e), this;
533
+ }
534
+ /**
535
+ * Specify implied option values for when this option is set and the implied options are not.
536
+ *
537
+ * The custom processing (parseArg) is not called on the implied values.
538
+ *
539
+ * @example
540
+ * program
541
+ * .addOption(new Option('--log', 'write logging information to file'))
542
+ * .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));
543
+ *
544
+ * @param {object} impliedOptionValues
545
+ * @return {Option}
546
+ */
547
+ implies(e) {
548
+ let t = e;
549
+ return typeof e == "string" && (t = { [e]: !0 }), this.implied = Object.assign(this.implied || {}, t), this;
550
+ }
551
+ /**
552
+ * Set environment variable to check for option value.
553
+ *
554
+ * An environment variable is only used if when processed the current option value is
555
+ * undefined, or the source of the current value is 'default' or 'config' or 'env'.
556
+ *
557
+ * @param {string} name
558
+ * @return {Option}
559
+ */
560
+ env(e) {
561
+ return this.envVar = e, this;
562
+ }
563
+ /**
564
+ * Set the custom handler for processing CLI option arguments into option values.
565
+ *
566
+ * @param {Function} [fn]
567
+ * @return {Option}
568
+ */
569
+ argParser(e) {
570
+ return this.parseArg = e, this;
571
+ }
572
+ /**
573
+ * Whether the option is mandatory and must have a value after parsing.
574
+ *
575
+ * @param {boolean} [mandatory=true]
576
+ * @return {Option}
577
+ */
578
+ makeOptionMandatory(e = !0) {
579
+ return this.mandatory = !!e, this;
580
+ }
581
+ /**
582
+ * Hide option in help.
583
+ *
584
+ * @param {boolean} [hide=true]
585
+ * @return {Option}
586
+ */
587
+ hideHelp(e = !0) {
588
+ return this.hidden = !!e, this;
589
+ }
590
+ /**
591
+ * @package
592
+ */
593
+ _concatValue(e, t) {
594
+ return t === this.defaultValue || !Array.isArray(t) ? [e] : t.concat(e);
595
+ }
596
+ /**
597
+ * Only allow option value to be one of choices.
598
+ *
599
+ * @param {string[]} values
600
+ * @return {Option}
601
+ */
602
+ choices(e) {
603
+ return this.argChoices = e.slice(), this.parseArg = (t, i) => {
604
+ if (!this.argChoices.includes(t))
605
+ throw new Ke(
606
+ `Allowed choices are ${this.argChoices.join(", ")}.`
607
+ );
608
+ return this.variadic ? this._concatValue(t, i) : t;
609
+ }, this;
610
+ }
611
+ /**
612
+ * Return option name.
613
+ *
614
+ * @return {string}
615
+ */
616
+ name() {
617
+ return this.long ? this.long.replace(/^--/, "") : this.short.replace(/^-/, "");
618
+ }
619
+ /**
620
+ * Return option name, in a camelcase format that can be used
621
+ * as a object attribute key.
622
+ *
623
+ * @return {string}
624
+ */
625
+ attributeName() {
626
+ return Qe(this.name().replace(/^no-/, ""));
627
+ }
628
+ /**
629
+ * Check if `arg` matches the short or long flag.
630
+ *
631
+ * @param {string} arg
632
+ * @return {boolean}
633
+ * @package
634
+ */
635
+ is(e) {
636
+ return this.short === e || this.long === e;
637
+ }
638
+ /**
639
+ * Return whether a boolean option.
640
+ *
641
+ * Options are one of boolean, negated, required argument, or optional argument.
642
+ *
643
+ * @return {boolean}
644
+ * @package
645
+ */
646
+ isBoolean() {
647
+ return !this.required && !this.optional && !this.negate;
648
+ }
649
+ }, K = class {
650
+ static {
651
+ d(this, "DualOptions");
652
+ }
653
+ /**
654
+ * @param {Option[]} options
655
+ */
656
+ constructor(e) {
657
+ this.positiveOptions = /* @__PURE__ */ new Map(), this.negativeOptions = /* @__PURE__ */ new Map(), this.dualOptions = /* @__PURE__ */ new Set(),
658
+ e.forEach((t) => {
659
+ t.negate ? this.negativeOptions.set(t.attributeName(), t) : this.positiveOptions.set(t.attributeName(), t);
660
+ }), this.negativeOptions.forEach((t, i) => {
661
+ this.positiveOptions.has(i) && this.dualOptions.add(i);
662
+ });
663
+ }
664
+ /**
665
+ * Did the value come from the option, and not from possible matching dual option?
666
+ *
667
+ * @param {*} value
668
+ * @param {Option} option
669
+ * @returns {boolean}
670
+ */
671
+ valueFromOption(e, t) {
672
+ let i = t.attributeName();
673
+ if (!this.dualOptions.has(i)) return !0;
674
+ let s = this.negativeOptions.get(i).presetArg, r = s !== void 0 ? s : !1;
675
+ return t.negate === (r === e);
676
+ }
677
+ };
678
+ function Qe(n) {
679
+ return n.split("-").reduce((e, t) => e + t[0].toUpperCase() + t.slice(1));
680
+ }
681
+ d(Qe, "camelcase");
682
+ function Xe(n) {
683
+ let e, t, i = n.split(/[ |,]+/);
684
+ return i.length > 1 && !/^[[<]/.test(i[1]) && (e = i.shift()), t = i.shift(), !e && /^-[^-]$/.test(t) && (e = t, t = void 0), { shortFlag: e,
685
+ longFlag: t };
686
+ }
687
+ d(Xe, "splitOptionFlags");
688
+ Q.Option = z;
689
+ Q.DualOptions = K;
690
+ });
691
+
692
+ // ../node_modules/commander/lib/suggestSimilar.js
693
+ var pe = b((ue) => {
694
+ function Ze(n, e) {
695
+ if (Math.abs(n.length - e.length) > 3)
696
+ return Math.max(n.length, e.length);
697
+ let t = [];
698
+ for (let i = 0; i <= n.length; i++)
699
+ t[i] = [i];
700
+ for (let i = 0; i <= e.length; i++)
701
+ t[0][i] = i;
702
+ for (let i = 1; i <= e.length; i++)
703
+ for (let s = 1; s <= n.length; s++) {
704
+ let r = 1;
705
+ n[s - 1] === e[i - 1] ? r = 0 : r = 1, t[s][i] = Math.min(
706
+ t[s - 1][i] + 1,
707
+ // deletion
708
+ t[s][i - 1] + 1,
709
+ // insertion
710
+ t[s - 1][i - 1] + r
711
+ // substitution
712
+ ), s > 1 && i > 1 && n[s - 1] === e[i - 2] && n[s - 2] === e[i - 1] && (t[s][i] = Math.min(t[s][i], t[s - 2][i - 2] + 1));
713
+ }
714
+ return t[n.length][e.length];
715
+ }
716
+ d(Ze, "editDistance");
717
+ function et(n, e) {
718
+ if (!e || e.length === 0) return "";
719
+ e = Array.from(new Set(e));
720
+ let t = n.startsWith("--");
721
+ t && (n = n.slice(2), e = e.map((o) => o.slice(2)));
722
+ let i = [], s = 3, r = 0.4;
723
+ return e.forEach((o) => {
724
+ if (o.length <= 1) return;
725
+ let l = Ze(n, o), a = Math.max(n.length, o.length);
726
+ (a - l) / a > r && (l < s ? (s = l, i = [o]) : l === s && i.push(o));
727
+ }), i.sort((o, l) => o.localeCompare(l)), t && (i = i.map((o) => `--${o}`)), i.length > 1 ? `
728
+ (Did you mean one of ${i.join(", ")}?)` : i.length === 1 ? `
729
+ (Did you mean ${i[0]}?)` : "";
730
+ }
731
+ d(et, "suggestSimilar");
732
+ ue.suggestSimilar = et;
733
+ });
734
+
735
+ // ../node_modules/commander/lib/command.js
736
+ var be = b((ge) => {
737
+ var tt = require("node:events").EventEmitter, Z = require("node:child_process"), y = require("node:path"), ee = require("node:fs"), h = require("node:process"),
738
+ { Argument: it, humanReadableArgName: st } = V(), { CommanderError: te } = k(), { Help: rt } = Y(), { Option: he, DualOptions: nt } = X(),
739
+ { suggestSimilar: me } = pe(), ie = class n extends tt {
740
+ static {
741
+ d(this, "Command");
742
+ }
743
+ /**
744
+ * Initialize a new `Command`.
745
+ *
746
+ * @param {string} [name]
747
+ */
748
+ constructor(e) {
749
+ super(), this.commands = [], this.options = [], this.parent = null, this._allowUnknownOption = !1, this._allowExcessArguments = !0, this.
750
+ registeredArguments = [], this._args = this.registeredArguments, this.args = [], this.rawArgs = [], this.processedArgs = [], this._scriptPath =
751
+ null, this._name = e || "", this._optionValues = {}, this._optionValueSources = {}, this._storeOptionsAsProperties = !1, this._actionHandler =
752
+ null, this._executableHandler = !1, this._executableFile = null, this._executableDir = null, this._defaultCommandName = null, this._exitCallback =
753
+ null, this._aliases = [], this._combineFlagAndOptionalValue = !0, this._description = "", this._summary = "", this._argsDescription = void 0,
754
+ this._enablePositionalOptions = !1, this._passThroughOptions = !1, this._lifeCycleHooks = {}, this._showHelpAfterError = !1, this._showSuggestionAfterError =
755
+ !0, this._outputConfiguration = {
756
+ writeOut: /* @__PURE__ */ d((t) => h.stdout.write(t), "writeOut"),
757
+ writeErr: /* @__PURE__ */ d((t) => h.stderr.write(t), "writeErr"),
758
+ getOutHelpWidth: /* @__PURE__ */ d(() => h.stdout.isTTY ? h.stdout.columns : void 0, "getOutHelpWidth"),
759
+ getErrHelpWidth: /* @__PURE__ */ d(() => h.stderr.isTTY ? h.stderr.columns : void 0, "getErrHelpWidth"),
760
+ outputError: /* @__PURE__ */ d((t, i) => i(t), "outputError")
761
+ }, this._hidden = !1, this._helpOption = void 0, this._addImplicitHelpCommand = void 0, this._helpCommand = void 0, this._helpConfiguration =
762
+ {};
763
+ }
764
+ /**
765
+ * Copy settings that are useful to have in common across root command and subcommands.
766
+ *
767
+ * (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)
768
+ *
769
+ * @param {Command} sourceCommand
770
+ * @return {Command} `this` command for chaining
771
+ */
772
+ copyInheritedSettings(e) {
773
+ return this._outputConfiguration = e._outputConfiguration, this._helpOption = e._helpOption, this._helpCommand = e._helpCommand, this.
774
+ _helpConfiguration = e._helpConfiguration, this._exitCallback = e._exitCallback, this._storeOptionsAsProperties = e._storeOptionsAsProperties,
775
+ this._combineFlagAndOptionalValue = e._combineFlagAndOptionalValue, this._allowExcessArguments = e._allowExcessArguments, this._enablePositionalOptions =
776
+ e._enablePositionalOptions, this._showHelpAfterError = e._showHelpAfterError, this._showSuggestionAfterError = e._showSuggestionAfterError,
777
+ this;
778
+ }
779
+ /**
780
+ * @returns {Command[]}
781
+ * @private
782
+ */
783
+ _getCommandAndAncestors() {
784
+ let e = [];
785
+ for (let t = this; t; t = t.parent)
786
+ e.push(t);
787
+ return e;
788
+ }
789
+ /**
790
+ * Define a command.
791
+ *
792
+ * There are two styles of command: pay attention to where to put the description.
793
+ *
794
+ * @example
795
+ * // Command implemented using action handler (description is supplied separately to `.command`)
796
+ * program
797
+ * .command('clone <source> [destination]')
798
+ * .description('clone a repository into a newly created directory')
799
+ * .action((source, destination) => {
800
+ * console.log('clone command called');
801
+ * });
802
+ *
803
+ * // Command implemented using separate executable file (description is second parameter to `.command`)
804
+ * program
805
+ * .command('start <service>', 'start named service')
806
+ * .command('stop [service]', 'stop named service, or all if no name supplied');
807
+ *
808
+ * @param {string} nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
809
+ * @param {(object | string)} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
810
+ * @param {object} [execOpts] - configuration options (for executable)
811
+ * @return {Command} returns new command for action handler, or `this` for executable command
812
+ */
813
+ command(e, t, i) {
814
+ let s = t, r = i;
815
+ typeof s == "object" && s !== null && (r = s, s = null), r = r || {};
816
+ let [, o, l] = e.match(/([^ ]+) *(.*)/), a = this.createCommand(o);
817
+ return s && (a.description(s), a._executableHandler = !0), r.isDefault && (this._defaultCommandName = a._name), a._hidden = !!(r.noHelp ||
818
+ r.hidden), a._executableFile = r.executableFile || null, l && a.arguments(l), this._registerCommand(a), a.parent = this, a.copyInheritedSettings(
819
+ this), s ? this : a;
820
+ }
821
+ /**
822
+ * Factory routine to create a new unattached command.
823
+ *
824
+ * See .command() for creating an attached subcommand, which uses this routine to
825
+ * create the command. You can override createCommand to customise subcommands.
826
+ *
827
+ * @param {string} [name]
828
+ * @return {Command} new command
829
+ */
830
+ createCommand(e) {
831
+ return new n(e);
832
+ }
833
+ /**
834
+ * You can customise the help with a subclass of Help by overriding createHelp,
835
+ * or by overriding Help properties using configureHelp().
836
+ *
837
+ * @return {Help}
838
+ */
839
+ createHelp() {
840
+ return Object.assign(new rt(), this.configureHelp());
841
+ }
842
+ /**
843
+ * You can customise the help by overriding Help properties using configureHelp(),
844
+ * or with a subclass of Help by overriding createHelp().
845
+ *
846
+ * @param {object} [configuration] - configuration options
847
+ * @return {(Command | object)} `this` command for chaining, or stored configuration
848
+ */
849
+ configureHelp(e) {
850
+ return e === void 0 ? this._helpConfiguration : (this._helpConfiguration = e, this);
851
+ }
852
+ /**
853
+ * The default output goes to stdout and stderr. You can customise this for special
854
+ * applications. You can also customise the display of errors by overriding outputError.
855
+ *
856
+ * The configuration properties are all functions:
857
+ *
858
+ * // functions to change where being written, stdout and stderr
859
+ * writeOut(str)
860
+ * writeErr(str)
861
+ * // matching functions to specify width for wrapping help
862
+ * getOutHelpWidth()
863
+ * getErrHelpWidth()
864
+ * // functions based on what is being written out
865
+ * outputError(str, write) // used for displaying errors, and not used for displaying help
866
+ *
867
+ * @param {object} [configuration] - configuration options
868
+ * @return {(Command | object)} `this` command for chaining, or stored configuration
869
+ */
870
+ configureOutput(e) {
871
+ return e === void 0 ? this._outputConfiguration : (Object.assign(this._outputConfiguration, e), this);
872
+ }
873
+ /**
874
+ * Display the help or a custom message after an error occurs.
875
+ *
876
+ * @param {(boolean|string)} [displayHelp]
877
+ * @return {Command} `this` command for chaining
878
+ */
879
+ showHelpAfterError(e = !0) {
880
+ return typeof e != "string" && (e = !!e), this._showHelpAfterError = e, this;
881
+ }
882
+ /**
883
+ * Display suggestion of similar commands for unknown commands, or options for unknown options.
884
+ *
885
+ * @param {boolean} [displaySuggestion]
886
+ * @return {Command} `this` command for chaining
887
+ */
888
+ showSuggestionAfterError(e = !0) {
889
+ return this._showSuggestionAfterError = !!e, this;
890
+ }
891
+ /**
892
+ * Add a prepared subcommand.
893
+ *
894
+ * See .command() for creating an attached subcommand which inherits settings from its parent.
895
+ *
896
+ * @param {Command} cmd - new subcommand
897
+ * @param {object} [opts] - configuration options
898
+ * @return {Command} `this` command for chaining
899
+ */
900
+ addCommand(e, t) {
901
+ if (!e._name)
902
+ throw new Error(`Command passed to .addCommand() must have a name
903
+ - specify the name in Command constructor or using .name()`);
904
+ return t = t || {}, t.isDefault && (this._defaultCommandName = e._name), (t.noHelp || t.hidden) && (e._hidden = !0), this._registerCommand(
905
+ e), e.parent = this, e._checkForBrokenPassThrough(), this;
906
+ }
907
+ /**
908
+ * Factory routine to create a new unattached argument.
909
+ *
910
+ * See .argument() for creating an attached argument, which uses this routine to
911
+ * create the argument. You can override createArgument to return a custom argument.
912
+ *
913
+ * @param {string} name
914
+ * @param {string} [description]
915
+ * @return {Argument} new argument
916
+ */
917
+ createArgument(e, t) {
918
+ return new it(e, t);
919
+ }
920
+ /**
921
+ * Define argument syntax for command.
922
+ *
923
+ * The default is that the argument is required, and you can explicitly
924
+ * indicate this with <> around the name. Put [] around the name for an optional argument.
925
+ *
926
+ * @example
927
+ * program.argument('<input-file>');
928
+ * program.argument('[output-file]');
929
+ *
930
+ * @param {string} name
931
+ * @param {string} [description]
932
+ * @param {(Function|*)} [fn] - custom argument processing function
933
+ * @param {*} [defaultValue]
934
+ * @return {Command} `this` command for chaining
935
+ */
936
+ argument(e, t, i, s) {
937
+ let r = this.createArgument(e, t);
938
+ return typeof i == "function" ? r.default(s).argParser(i) : r.default(i), this.addArgument(r), this;
939
+ }
940
+ /**
941
+ * Define argument syntax for command, adding multiple at once (without descriptions).
942
+ *
943
+ * See also .argument().
944
+ *
945
+ * @example
946
+ * program.arguments('<cmd> [env]');
947
+ *
948
+ * @param {string} names
949
+ * @return {Command} `this` command for chaining
950
+ */
951
+ arguments(e) {
952
+ return e.trim().split(/ +/).forEach((t) => {
953
+ this.argument(t);
954
+ }), this;
955
+ }
956
+ /**
957
+ * Define argument syntax for command, adding a prepared argument.
958
+ *
959
+ * @param {Argument} argument
960
+ * @return {Command} `this` command for chaining
961
+ */
962
+ addArgument(e) {
963
+ let t = this.registeredArguments.slice(-1)[0];
964
+ if (t && t.variadic)
965
+ throw new Error(
966
+ `only the last argument can be variadic '${t.name()}'`
967
+ );
968
+ if (e.required && e.defaultValue !== void 0 && e.parseArg === void 0)
969
+ throw new Error(
970
+ `a default value for a required argument is never used: '${e.name()}'`
971
+ );
972
+ return this.registeredArguments.push(e), this;
973
+ }
974
+ /**
975
+ * Customise or override default help command. By default a help command is automatically added if your command has subcommands.
976
+ *
977
+ * @example
978
+ * program.helpCommand('help [cmd]');
979
+ * program.helpCommand('help [cmd]', 'show help');
980
+ * program.helpCommand(false); // suppress default help command
981
+ * program.helpCommand(true); // add help command even if no subcommands
982
+ *
983
+ * @param {string|boolean} enableOrNameAndArgs - enable with custom name and/or arguments, or boolean to override whether added
984
+ * @param {string} [description] - custom description
985
+ * @return {Command} `this` command for chaining
986
+ */
987
+ helpCommand(e, t) {
988
+ if (typeof e == "boolean")
989
+ return this._addImplicitHelpCommand = e, this;
990
+ e = e ?? "help [command]";
991
+ let [, i, s] = e.match(/([^ ]+) *(.*)/), r = t ?? "display help for command", o = this.createCommand(i);
992
+ return o.helpOption(!1), s && o.arguments(s), r && o.description(r), this._addImplicitHelpCommand = !0, this._helpCommand = o, this;
993
+ }
994
+ /**
995
+ * Add prepared custom help command.
996
+ *
997
+ * @param {(Command|string|boolean)} helpCommand - custom help command, or deprecated enableOrNameAndArgs as for `.helpCommand()`
998
+ * @param {string} [deprecatedDescription] - deprecated custom description used with custom name only
999
+ * @return {Command} `this` command for chaining
1000
+ */
1001
+ addHelpCommand(e, t) {
1002
+ return typeof e != "object" ? (this.helpCommand(e, t), this) : (this._addImplicitHelpCommand = !0, this._helpCommand = e, this);
1003
+ }
1004
+ /**
1005
+ * Lazy create help command.
1006
+ *
1007
+ * @return {(Command|null)}
1008
+ * @package
1009
+ */
1010
+ _getHelpCommand() {
1011
+ return this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help")) ? (this._helpCommand ===
1012
+ void 0 && this.helpCommand(void 0, void 0), this._helpCommand) : null;
1013
+ }
1014
+ /**
1015
+ * Add hook for life cycle event.
1016
+ *
1017
+ * @param {string} event
1018
+ * @param {Function} listener
1019
+ * @return {Command} `this` command for chaining
1020
+ */
1021
+ hook(e, t) {
1022
+ let i = ["preSubcommand", "preAction", "postAction"];
1023
+ if (!i.includes(e))
1024
+ throw new Error(`Unexpected value for event passed to hook : '${e}'.
1025
+ Expecting one of '${i.join("', '")}'`);
1026
+ return this._lifeCycleHooks[e] ? this._lifeCycleHooks[e].push(t) : this._lifeCycleHooks[e] = [t], this;
1027
+ }
1028
+ /**
1029
+ * Register callback to use as replacement for calling process.exit.
1030
+ *
1031
+ * @param {Function} [fn] optional callback which will be passed a CommanderError, defaults to throwing
1032
+ * @return {Command} `this` command for chaining
1033
+ */
1034
+ exitOverride(e) {
1035
+ return e ? this._exitCallback = e : this._exitCallback = (t) => {
1036
+ if (t.code !== "commander.executeSubCommandAsync")
1037
+ throw t;
1038
+ }, this;
1039
+ }
1040
+ /**
1041
+ * Call process.exit, and _exitCallback if defined.
1042
+ *
1043
+ * @param {number} exitCode exit code for using with process.exit
1044
+ * @param {string} code an id string representing the error
1045
+ * @param {string} message human-readable description of the error
1046
+ * @return never
1047
+ * @private
1048
+ */
1049
+ _exit(e, t, i) {
1050
+ this._exitCallback && this._exitCallback(new te(e, t, i)), h.exit(e);
1051
+ }
1052
+ /**
1053
+ * Register callback `fn` for the command.
1054
+ *
1055
+ * @example
1056
+ * program
1057
+ * .command('serve')
1058
+ * .description('start service')
1059
+ * .action(function() {
1060
+ * // do work here
1061
+ * });
1062
+ *
1063
+ * @param {Function} fn
1064
+ * @return {Command} `this` command for chaining
1065
+ */
1066
+ action(e) {
1067
+ let t = /* @__PURE__ */ d((i) => {
1068
+ let s = this.registeredArguments.length, r = i.slice(0, s);
1069
+ return this._storeOptionsAsProperties ? r[s] = this : r[s] = this.opts(), r.push(this), e.apply(this, r);
1070
+ }, "listener");
1071
+ return this._actionHandler = t, this;
1072
+ }
1073
+ /**
1074
+ * Factory routine to create a new unattached option.
1075
+ *
1076
+ * See .option() for creating an attached option, which uses this routine to
1077
+ * create the option. You can override createOption to return a custom option.
1078
+ *
1079
+ * @param {string} flags
1080
+ * @param {string} [description]
1081
+ * @return {Option} new option
1082
+ */
1083
+ createOption(e, t) {
1084
+ return new he(e, t);
1085
+ }
1086
+ /**
1087
+ * Wrap parseArgs to catch 'commander.invalidArgument'.
1088
+ *
1089
+ * @param {(Option | Argument)} target
1090
+ * @param {string} value
1091
+ * @param {*} previous
1092
+ * @param {string} invalidArgumentMessage
1093
+ * @private
1094
+ */
1095
+ _callParseArg(e, t, i, s) {
1096
+ try {
1097
+ return e.parseArg(t, i);
1098
+ } catch (r) {
1099
+ if (r.code === "commander.invalidArgument") {
1100
+ let o = `${s} ${r.message}`;
1101
+ this.error(o, { exitCode: r.exitCode, code: r.code });
1102
+ }
1103
+ throw r;
1104
+ }
1105
+ }
1106
+ /**
1107
+ * Check for option flag conflicts.
1108
+ * Register option if no conflicts found, or throw on conflict.
1109
+ *
1110
+ * @param {Option} option
1111
+ * @private
1112
+ */
1113
+ _registerOption(e) {
1114
+ let t = e.short && this._findOption(e.short) || e.long && this._findOption(e.long);
1115
+ if (t) {
1116
+ let i = e.long && this._findOption(e.long) ? e.long : e.short;
1117
+ throw new Error(`Cannot add option '${e.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${i}'
1118
+ - already used by option '${t.flags}'`);
1119
+ }
1120
+ this.options.push(e);
1121
+ }
1122
+ /**
1123
+ * Check for command name and alias conflicts with existing commands.
1124
+ * Register command if no conflicts found, or throw on conflict.
1125
+ *
1126
+ * @param {Command} command
1127
+ * @private
1128
+ */
1129
+ _registerCommand(e) {
1130
+ let t = /* @__PURE__ */ d((s) => [s.name()].concat(s.aliases()), "knownBy"), i = t(e).find(
1131
+ (s) => this._findCommand(s)
1132
+ );
1133
+ if (i) {
1134
+ let s = t(this._findCommand(i)).join("|"), r = t(e).join("|");
1135
+ throw new Error(
1136
+ `cannot add command '${r}' as already have command '${s}'`
1137
+ );
1138
+ }
1139
+ this.commands.push(e);
1140
+ }
1141
+ /**
1142
+ * Add an option.
1143
+ *
1144
+ * @param {Option} option
1145
+ * @return {Command} `this` command for chaining
1146
+ */
1147
+ addOption(e) {
1148
+ this._registerOption(e);
1149
+ let t = e.name(), i = e.attributeName();
1150
+ if (e.negate) {
1151
+ let r = e.long.replace(/^--no-/, "--");
1152
+ this._findOption(r) || this.setOptionValueWithSource(
1153
+ i,
1154
+ e.defaultValue === void 0 ? !0 : e.defaultValue,
1155
+ "default"
1156
+ );
1157
+ } else e.defaultValue !== void 0 && this.setOptionValueWithSource(i, e.defaultValue, "default");
1158
+ let s = /* @__PURE__ */ d((r, o, l) => {
1159
+ r == null && e.presetArg !== void 0 && (r = e.presetArg);
1160
+ let a = this.getOptionValue(i);
1161
+ r !== null && e.parseArg ? r = this._callParseArg(e, r, a, o) : r !== null && e.variadic && (r = e._concatValue(r, a)), r == null &&
1162
+ (e.negate ? r = !1 : e.isBoolean() || e.optional ? r = !0 : r = ""), this.setOptionValueWithSource(i, r, l);
1163
+ }, "handleOptionValue");
1164
+ return this.on("option:" + t, (r) => {
1165
+ let o = `error: option '${e.flags}' argument '${r}' is invalid.`;
1166
+ s(r, o, "cli");
1167
+ }), e.envVar && this.on("optionEnv:" + t, (r) => {
1168
+ let o = `error: option '${e.flags}' value '${r}' from env '${e.envVar}' is invalid.`;
1169
+ s(r, o, "env");
1170
+ }), this;
1171
+ }
1172
+ /**
1173
+ * Internal implementation shared by .option() and .requiredOption()
1174
+ *
1175
+ * @return {Command} `this` command for chaining
1176
+ * @private
1177
+ */
1178
+ _optionEx(e, t, i, s, r) {
1179
+ if (typeof t == "object" && t instanceof he)
1180
+ throw new Error(
1181
+ "To add an Option object use addOption() instead of option() or requiredOption()"
1182
+ );
1183
+ let o = this.createOption(t, i);
1184
+ if (o.makeOptionMandatory(!!e.mandatory), typeof s == "function")
1185
+ o.default(r).argParser(s);
1186
+ else if (s instanceof RegExp) {
1187
+ let l = s;
1188
+ s = /* @__PURE__ */ d((a, c) => {
1189
+ let u = l.exec(a);
1190
+ return u ? u[0] : c;
1191
+ }, "fn"), o.default(r).argParser(s);
1192
+ } else
1193
+ o.default(s);
1194
+ return this.addOption(o);
1195
+ }
1196
+ /**
1197
+ * Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
1198
+ *
1199
+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required
1200
+ * option-argument is indicated by `<>` and an optional option-argument by `[]`.
1201
+ *
1202
+ * See the README for more details, and see also addOption() and requiredOption().
1203
+ *
1204
+ * @example
1205
+ * program
1206
+ * .option('-p, --pepper', 'add pepper')
1207
+ * .option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument
1208
+ * .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
1209
+ * .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
1210
+ *
1211
+ * @param {string} flags
1212
+ * @param {string} [description]
1213
+ * @param {(Function|*)} [parseArg] - custom option processing function or default value
1214
+ * @param {*} [defaultValue]
1215
+ * @return {Command} `this` command for chaining
1216
+ */
1217
+ option(e, t, i, s) {
1218
+ return this._optionEx({}, e, t, i, s);
1219
+ }
1220
+ /**
1221
+ * Add a required option which must have a value after parsing. This usually means
1222
+ * the option must be specified on the command line. (Otherwise the same as .option().)
1223
+ *
1224
+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
1225
+ *
1226
+ * @param {string} flags
1227
+ * @param {string} [description]
1228
+ * @param {(Function|*)} [parseArg] - custom option processing function or default value
1229
+ * @param {*} [defaultValue]
1230
+ * @return {Command} `this` command for chaining
1231
+ */
1232
+ requiredOption(e, t, i, s) {
1233
+ return this._optionEx(
1234
+ { mandatory: !0 },
1235
+ e,
1236
+ t,
1237
+ i,
1238
+ s
1239
+ );
1240
+ }
1241
+ /**
1242
+ * Alter parsing of short flags with optional values.
1243
+ *
1244
+ * @example
1245
+ * // for `.option('-f,--flag [value]'):
1246
+ * program.combineFlagAndOptionalValue(true); // `-f80` is treated like `--flag=80`, this is the default behaviour
1247
+ * program.combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
1248
+ *
1249
+ * @param {boolean} [combine] - if `true` or omitted, an optional value can be specified directly after the flag.
1250
+ * @return {Command} `this` command for chaining
1251
+ */
1252
+ combineFlagAndOptionalValue(e = !0) {
1253
+ return this._combineFlagAndOptionalValue = !!e, this;
1254
+ }
1255
+ /**
1256
+ * Allow unknown options on the command line.
1257
+ *
1258
+ * @param {boolean} [allowUnknown] - if `true` or omitted, no error will be thrown for unknown options.
1259
+ * @return {Command} `this` command for chaining
1260
+ */
1261
+ allowUnknownOption(e = !0) {
1262
+ return this._allowUnknownOption = !!e, this;
1263
+ }
1264
+ /**
1265
+ * Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
1266
+ *
1267
+ * @param {boolean} [allowExcess] - if `true` or omitted, no error will be thrown for excess arguments.
1268
+ * @return {Command} `this` command for chaining
1269
+ */
1270
+ allowExcessArguments(e = !0) {
1271
+ return this._allowExcessArguments = !!e, this;
1272
+ }
1273
+ /**
1274
+ * Enable positional options. Positional means global options are specified before subcommands which lets
1275
+ * subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
1276
+ * The default behaviour is non-positional and global options may appear anywhere on the command line.
1277
+ *
1278
+ * @param {boolean} [positional]
1279
+ * @return {Command} `this` command for chaining
1280
+ */
1281
+ enablePositionalOptions(e = !0) {
1282
+ return this._enablePositionalOptions = !!e, this;
1283
+ }
1284
+ /**
1285
+ * Pass through options that come after command-arguments rather than treat them as command-options,
1286
+ * so actual command-options come before command-arguments. Turning this on for a subcommand requires
1287
+ * positional options to have been enabled on the program (parent commands).
1288
+ * The default behaviour is non-positional and options may appear before or after command-arguments.
1289
+ *
1290
+ * @param {boolean} [passThrough] for unknown options.
1291
+ * @return {Command} `this` command for chaining
1292
+ */
1293
+ passThroughOptions(e = !0) {
1294
+ return this._passThroughOptions = !!e, this._checkForBrokenPassThrough(), this;
1295
+ }
1296
+ /**
1297
+ * @private
1298
+ */
1299
+ _checkForBrokenPassThrough() {
1300
+ if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions)
1301
+ throw new Error(
1302
+ `passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`
1303
+ );
1304
+ }
1305
+ /**
1306
+ * Whether to store option values as properties on command object,
1307
+ * or store separately (specify false). In both cases the option values can be accessed using .opts().
1308
+ *
1309
+ * @param {boolean} [storeAsProperties=true]
1310
+ * @return {Command} `this` command for chaining
1311
+ */
1312
+ storeOptionsAsProperties(e = !0) {
1313
+ if (this.options.length)
1314
+ throw new Error("call .storeOptionsAsProperties() before adding options");
1315
+ if (Object.keys(this._optionValues).length)
1316
+ throw new Error(
1317
+ "call .storeOptionsAsProperties() before setting option values"
1318
+ );
1319
+ return this._storeOptionsAsProperties = !!e, this;
1320
+ }
1321
+ /**
1322
+ * Retrieve option value.
1323
+ *
1324
+ * @param {string} key
1325
+ * @return {object} value
1326
+ */
1327
+ getOptionValue(e) {
1328
+ return this._storeOptionsAsProperties ? this[e] : this._optionValues[e];
1329
+ }
1330
+ /**
1331
+ * Store option value.
1332
+ *
1333
+ * @param {string} key
1334
+ * @param {object} value
1335
+ * @return {Command} `this` command for chaining
1336
+ */
1337
+ setOptionValue(e, t) {
1338
+ return this.setOptionValueWithSource(e, t, void 0);
1339
+ }
1340
+ /**
1341
+ * Store option value and where the value came from.
1342
+ *
1343
+ * @param {string} key
1344
+ * @param {object} value
1345
+ * @param {string} source - expected values are default/config/env/cli/implied
1346
+ * @return {Command} `this` command for chaining
1347
+ */
1348
+ setOptionValueWithSource(e, t, i) {
1349
+ return this._storeOptionsAsProperties ? this[e] = t : this._optionValues[e] = t, this._optionValueSources[e] = i, this;
1350
+ }
1351
+ /**
1352
+ * Get source of option value.
1353
+ * Expected values are default | config | env | cli | implied
1354
+ *
1355
+ * @param {string} key
1356
+ * @return {string}
1357
+ */
1358
+ getOptionValueSource(e) {
1359
+ return this._optionValueSources[e];
1360
+ }
1361
+ /**
1362
+ * Get source of option value. See also .optsWithGlobals().
1363
+ * Expected values are default | config | env | cli | implied
1364
+ *
1365
+ * @param {string} key
1366
+ * @return {string}
1367
+ */
1368
+ getOptionValueSourceWithGlobals(e) {
1369
+ let t;
1370
+ return this._getCommandAndAncestors().forEach((i) => {
1371
+ i.getOptionValueSource(e) !== void 0 && (t = i.getOptionValueSource(e));
1372
+ }), t;
1373
+ }
1374
+ /**
1375
+ * Get user arguments from implied or explicit arguments.
1376
+ * Side-effects: set _scriptPath if args included script. Used for default program name, and subcommand searches.
1377
+ *
1378
+ * @private
1379
+ */
1380
+ _prepareUserArgs(e, t) {
1381
+ if (e !== void 0 && !Array.isArray(e))
1382
+ throw new Error("first parameter to parse must be array or undefined");
1383
+ if (t = t || {}, e === void 0 && t.from === void 0) {
1384
+ h.versions?.electron && (t.from = "electron");
1385
+ let s = h.execArgv ?? [];
1386
+ (s.includes("-e") || s.includes("--eval") || s.includes("-p") || s.includes("--print")) && (t.from = "eval");
1387
+ }
1388
+ e === void 0 && (e = h.argv), this.rawArgs = e.slice();
1389
+ let i;
1390
+ switch (t.from) {
1391
+ case void 0:
1392
+ case "node":
1393
+ this._scriptPath = e[1], i = e.slice(2);
1394
+ break;
1395
+ case "electron":
1396
+ h.defaultApp ? (this._scriptPath = e[1], i = e.slice(2)) : i = e.slice(1);
1397
+ break;
1398
+ case "user":
1399
+ i = e.slice(0);
1400
+ break;
1401
+ case "eval":
1402
+ i = e.slice(1);
1403
+ break;
1404
+ default:
1405
+ throw new Error(
1406
+ `unexpected parse option { from: '${t.from}' }`
1407
+ );
1408
+ }
1409
+ return !this._name && this._scriptPath && this.nameFromFilename(this._scriptPath), this._name = this._name || "program", i;
1410
+ }
1411
+ /**
1412
+ * Parse `argv`, setting options and invoking commands when defined.
1413
+ *
1414
+ * Use parseAsync instead of parse if any of your action handlers are async.
1415
+ *
1416
+ * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
1417
+ *
1418
+ * Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
1419
+ * - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
1420
+ * - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
1421
+ * - `'user'`: just user arguments
1422
+ *
1423
+ * @example
1424
+ * program.parse(); // parse process.argv and auto-detect electron and special node flags
1425
+ * program.parse(process.argv); // assume argv[0] is app and argv[1] is script
1426
+ * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
1427
+ *
1428
+ * @param {string[]} [argv] - optional, defaults to process.argv
1429
+ * @param {object} [parseOptions] - optionally specify style of options with from: node/user/electron
1430
+ * @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron'
1431
+ * @return {Command} `this` command for chaining
1432
+ */
1433
+ parse(e, t) {
1434
+ let i = this._prepareUserArgs(e, t);
1435
+ return this._parseCommand([], i), this;
1436
+ }
1437
+ /**
1438
+ * Parse `argv`, setting options and invoking commands when defined.
1439
+ *
1440
+ * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
1441
+ *
1442
+ * Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
1443
+ * - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
1444
+ * - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
1445
+ * - `'user'`: just user arguments
1446
+ *
1447
+ * @example
1448
+ * await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
1449
+ * await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script
1450
+ * await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
1451
+ *
1452
+ * @param {string[]} [argv]
1453
+ * @param {object} [parseOptions]
1454
+ * @param {string} parseOptions.from - where the args are from: 'node', 'user', 'electron'
1455
+ * @return {Promise}
1456
+ */
1457
+ async parseAsync(e, t) {
1458
+ let i = this._prepareUserArgs(e, t);
1459
+ return await this._parseCommand([], i), this;
1460
+ }
1461
+ /**
1462
+ * Execute a sub-command executable.
1463
+ *
1464
+ * @private
1465
+ */
1466
+ _executeSubCommand(e, t) {
1467
+ t = t.slice();
1468
+ let i = !1, s = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
1469
+ function r(u, p) {
1470
+ let m = y.resolve(u, p);
1471
+ if (ee.existsSync(m)) return m;
1472
+ if (s.includes(y.extname(p))) return;
1473
+ let _ = s.find(
1474
+ (f) => ee.existsSync(`${m}${f}`)
1475
+ );
1476
+ if (_) return `${m}${_}`;
1477
+ }
1478
+ d(r, "findFile"), this._checkForMissingMandatoryOptions(), this._checkForConflictingOptions();
1479
+ let o = e._executableFile || `${this._name}-${e._name}`, l = this._executableDir || "";
1480
+ if (this._scriptPath) {
1481
+ let u;
1482
+ try {
1483
+ u = ee.realpathSync(this._scriptPath);
1484
+ } catch {
1485
+ u = this._scriptPath;
1486
+ }
1487
+ l = y.resolve(
1488
+ y.dirname(u),
1489
+ l
1490
+ );
1491
+ }
1492
+ if (l) {
1493
+ let u = r(l, o);
1494
+ if (!u && !e._executableFile && this._scriptPath) {
1495
+ let p = y.basename(
1496
+ this._scriptPath,
1497
+ y.extname(this._scriptPath)
1498
+ );
1499
+ p !== this._name && (u = r(
1500
+ l,
1501
+ `${p}-${e._name}`
1502
+ ));
1503
+ }
1504
+ o = u || o;
1505
+ }
1506
+ i = s.includes(y.extname(o));
1507
+ let a;
1508
+ h.platform !== "win32" ? i ? (t.unshift(o), t = fe(h.execArgv).concat(t), a = Z.spawn(h.argv[0], t, { stdio: "inherit" })) : a = Z.spawn(
1509
+ o, t, { stdio: "inherit" }) : (t.unshift(o), t = fe(h.execArgv).concat(t), a = Z.spawn(h.execPath, t, { stdio: "inherit" })), a.killed ||
1510
+ ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"].forEach((p) => {
1511
+ h.on(p, () => {
1512
+ a.killed === !1 && a.exitCode === null && a.kill(p);
1513
+ });
1514
+ });
1515
+ let c = this._exitCallback;
1516
+ a.on("close", (u) => {
1517
+ u = u ?? 1, c ? c(
1518
+ new te(
1519
+ u,
1520
+ "commander.executeSubCommandAsync",
1521
+ "(close)"
1522
+ )
1523
+ ) : h.exit(u);
1524
+ }), a.on("error", (u) => {
1525
+ if (u.code === "ENOENT") {
1526
+ let p = l ? `searched for local subcommand relative to directory '${l}'` : "no directory for search for local subcommand, use .exe\
1527
+ cutableDir() to supply a custom directory", m = `'${o}' does not exist
1528
+ - if '${e._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead\
1529
+
1530
+ - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
1531
+ - ${p}`;
1532
+ throw new Error(m);
1533
+ } else if (u.code === "EACCES")
1534
+ throw new Error(`'${o}' not executable`);
1535
+ if (!c)
1536
+ h.exit(1);
1537
+ else {
1538
+ let p = new te(
1539
+ 1,
1540
+ "commander.executeSubCommandAsync",
1541
+ "(error)"
1542
+ );
1543
+ p.nestedError = u, c(p);
1544
+ }
1545
+ }), this.runningCommand = a;
1546
+ }
1547
+ /**
1548
+ * @private
1549
+ */
1550
+ _dispatchSubcommand(e, t, i) {
1551
+ let s = this._findCommand(e);
1552
+ s || this.help({ error: !0 });
1553
+ let r;
1554
+ return r = this._chainOrCallSubCommandHook(
1555
+ r,
1556
+ s,
1557
+ "preSubcommand"
1558
+ ), r = this._chainOrCall(r, () => {
1559
+ if (s._executableHandler)
1560
+ this._executeSubCommand(s, t.concat(i));
1561
+ else
1562
+ return s._parseCommand(t, i);
1563
+ }), r;
1564
+ }
1565
+ /**
1566
+ * Invoke help directly if possible, or dispatch if necessary.
1567
+ * e.g. help foo
1568
+ *
1569
+ * @private
1570
+ */
1571
+ _dispatchHelpCommand(e) {
1572
+ e || this.help();
1573
+ let t = this._findCommand(e);
1574
+ return t && !t._executableHandler && t.help(), this._dispatchSubcommand(
1575
+ e,
1576
+ [],
1577
+ [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]
1578
+ );
1579
+ }
1580
+ /**
1581
+ * Check this.args against expected this.registeredArguments.
1582
+ *
1583
+ * @private
1584
+ */
1585
+ _checkNumberOfArguments() {
1586
+ this.registeredArguments.forEach((e, t) => {
1587
+ e.required && this.args[t] == null && this.missingArgument(e.name());
1588
+ }), !(this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) && this.args.length >
1589
+ this.registeredArguments.length && this._excessArguments(this.args);
1590
+ }
1591
+ /**
1592
+ * Process this.args using this.registeredArguments and save as this.processedArgs!
1593
+ *
1594
+ * @private
1595
+ */
1596
+ _processArguments() {
1597
+ let e = /* @__PURE__ */ d((i, s, r) => {
1598
+ let o = s;
1599
+ if (s !== null && i.parseArg) {
1600
+ let l = `error: command-argument value '${s}' is invalid for argument '${i.name()}'.`;
1601
+ o = this._callParseArg(
1602
+ i,
1603
+ s,
1604
+ r,
1605
+ l
1606
+ );
1607
+ }
1608
+ return o;
1609
+ }, "myParseArg");
1610
+ this._checkNumberOfArguments();
1611
+ let t = [];
1612
+ this.registeredArguments.forEach((i, s) => {
1613
+ let r = i.defaultValue;
1614
+ i.variadic ? s < this.args.length ? (r = this.args.slice(s), i.parseArg && (r = r.reduce((o, l) => e(i, l, o), i.defaultValue))) : r ===
1615
+ void 0 && (r = []) : s < this.args.length && (r = this.args[s], i.parseArg && (r = e(i, r, i.defaultValue))), t[s] = r;
1616
+ }), this.processedArgs = t;
1617
+ }
1618
+ /**
1619
+ * Once we have a promise we chain, but call synchronously until then.
1620
+ *
1621
+ * @param {(Promise|undefined)} promise
1622
+ * @param {Function} fn
1623
+ * @return {(Promise|undefined)}
1624
+ * @private
1625
+ */
1626
+ _chainOrCall(e, t) {
1627
+ return e && e.then && typeof e.then == "function" ? e.then(() => t()) : t();
1628
+ }
1629
+ /**
1630
+ *
1631
+ * @param {(Promise|undefined)} promise
1632
+ * @param {string} event
1633
+ * @return {(Promise|undefined)}
1634
+ * @private
1635
+ */
1636
+ _chainOrCallHooks(e, t) {
1637
+ let i = e, s = [];
1638
+ return this._getCommandAndAncestors().reverse().filter((r) => r._lifeCycleHooks[t] !== void 0).forEach((r) => {
1639
+ r._lifeCycleHooks[t].forEach((o) => {
1640
+ s.push({ hookedCommand: r, callback: o });
1641
+ });
1642
+ }), t === "postAction" && s.reverse(), s.forEach((r) => {
1643
+ i = this._chainOrCall(i, () => r.callback(r.hookedCommand, this));
1644
+ }), i;
1645
+ }
1646
+ /**
1647
+ *
1648
+ * @param {(Promise|undefined)} promise
1649
+ * @param {Command} subCommand
1650
+ * @param {string} event
1651
+ * @return {(Promise|undefined)}
1652
+ * @private
1653
+ */
1654
+ _chainOrCallSubCommandHook(e, t, i) {
1655
+ let s = e;
1656
+ return this._lifeCycleHooks[i] !== void 0 && this._lifeCycleHooks[i].forEach((r) => {
1657
+ s = this._chainOrCall(s, () => r(this, t));
1658
+ }), s;
1659
+ }
1660
+ /**
1661
+ * Process arguments in context of this command.
1662
+ * Returns action result, in case it is a promise.
1663
+ *
1664
+ * @private
1665
+ */
1666
+ _parseCommand(e, t) {
1667
+ let i = this.parseOptions(t);
1668
+ if (this._parseOptionsEnv(), this._parseOptionsImplied(), e = e.concat(i.operands), t = i.unknown, this.args = e.concat(t), e && this.
1669
+ _findCommand(e[0]))
1670
+ return this._dispatchSubcommand(e[0], e.slice(1), t);
1671
+ if (this._getHelpCommand() && e[0] === this._getHelpCommand().name())
1672
+ return this._dispatchHelpCommand(e[1]);
1673
+ if (this._defaultCommandName)
1674
+ return this._outputHelpIfRequested(t), this._dispatchSubcommand(
1675
+ this._defaultCommandName,
1676
+ e,
1677
+ t
1678
+ );
1679
+ this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName && this.help({ error: !0 }), this.
1680
+ _outputHelpIfRequested(i.unknown), this._checkForMissingMandatoryOptions(), this._checkForConflictingOptions();
1681
+ let s = /* @__PURE__ */ d(() => {
1682
+ i.unknown.length > 0 && this.unknownOption(i.unknown[0]);
1683
+ }, "checkForUnknownOptions"), r = `command:${this.name()}`;
1684
+ if (this._actionHandler) {
1685
+ s(), this._processArguments();
1686
+ let o;
1687
+ return o = this._chainOrCallHooks(o, "preAction"), o = this._chainOrCall(
1688
+ o,
1689
+ () => this._actionHandler(this.processedArgs)
1690
+ ), this.parent && (o = this._chainOrCall(o, () => {
1691
+ this.parent.emit(r, e, t);
1692
+ })), o = this._chainOrCallHooks(o, "postAction"), o;
1693
+ }
1694
+ if (this.parent && this.parent.listenerCount(r))
1695
+ s(), this._processArguments(), this.parent.emit(r, e, t);
1696
+ else if (e.length) {
1697
+ if (this._findCommand("*"))
1698
+ return this._dispatchSubcommand("*", e, t);
1699
+ this.listenerCount("command:*") ? this.emit("command:*", e, t) : this.commands.length ? this.unknownCommand() : (s(), this._processArguments());
1700
+ } else this.commands.length ? (s(), this.help({ error: !0 })) : (s(), this._processArguments());
1701
+ }
1702
+ /**
1703
+ * Find matching command.
1704
+ *
1705
+ * @private
1706
+ * @return {Command | undefined}
1707
+ */
1708
+ _findCommand(e) {
1709
+ if (e)
1710
+ return this.commands.find(
1711
+ (t) => t._name === e || t._aliases.includes(e)
1712
+ );
1713
+ }
1714
+ /**
1715
+ * Return an option matching `arg` if any.
1716
+ *
1717
+ * @param {string} arg
1718
+ * @return {Option}
1719
+ * @package
1720
+ */
1721
+ _findOption(e) {
1722
+ return this.options.find((t) => t.is(e));
1723
+ }
1724
+ /**
1725
+ * Display an error message if a mandatory option does not have a value.
1726
+ * Called after checking for help flags in leaf subcommand.
1727
+ *
1728
+ * @private
1729
+ */
1730
+ _checkForMissingMandatoryOptions() {
1731
+ this._getCommandAndAncestors().forEach((e) => {
1732
+ e.options.forEach((t) => {
1733
+ t.mandatory && e.getOptionValue(t.attributeName()) === void 0 && e.missingMandatoryOptionValue(t);
1734
+ });
1735
+ });
1736
+ }
1737
+ /**
1738
+ * Display an error message if conflicting options are used together in this.
1739
+ *
1740
+ * @private
1741
+ */
1742
+ _checkForConflictingLocalOptions() {
1743
+ let e = this.options.filter((i) => {
1744
+ let s = i.attributeName();
1745
+ return this.getOptionValue(s) === void 0 ? !1 : this.getOptionValueSource(s) !== "default";
1746
+ });
1747
+ e.filter(
1748
+ (i) => i.conflictsWith.length > 0
1749
+ ).forEach((i) => {
1750
+ let s = e.find(
1751
+ (r) => i.conflictsWith.includes(r.attributeName())
1752
+ );
1753
+ s && this._conflictingOption(i, s);
1754
+ });
1755
+ }
1756
+ /**
1757
+ * Display an error message if conflicting options are used together.
1758
+ * Called after checking for help flags in leaf subcommand.
1759
+ *
1760
+ * @private
1761
+ */
1762
+ _checkForConflictingOptions() {
1763
+ this._getCommandAndAncestors().forEach((e) => {
1764
+ e._checkForConflictingLocalOptions();
1765
+ });
1766
+ }
1767
+ /**
1768
+ * Parse options from `argv` removing known options,
1769
+ * and return argv split into operands and unknown arguments.
1770
+ *
1771
+ * Examples:
1772
+ *
1773
+ * argv => operands, unknown
1774
+ * --known kkk op => [op], []
1775
+ * op --known kkk => [op], []
1776
+ * sub --unknown uuu op => [sub], [--unknown uuu op]
1777
+ * sub -- --unknown uuu op => [sub --unknown uuu op], []
1778
+ *
1779
+ * @param {string[]} argv
1780
+ * @return {{operands: string[], unknown: string[]}}
1781
+ */
1782
+ parseOptions(e) {
1783
+ let t = [], i = [], s = t, r = e.slice();
1784
+ function o(a) {
1785
+ return a.length > 1 && a[0] === "-";
1786
+ }
1787
+ d(o, "maybeOption");
1788
+ let l = null;
1789
+ for (; r.length; ) {
1790
+ let a = r.shift();
1791
+ if (a === "--") {
1792
+ s === i && s.push(a), s.push(...r);
1793
+ break;
1794
+ }
1795
+ if (l && !o(a)) {
1796
+ this.emit(`option:${l.name()}`, a);
1797
+ continue;
1798
+ }
1799
+ if (l = null, o(a)) {
1800
+ let c = this._findOption(a);
1801
+ if (c) {
1802
+ if (c.required) {
1803
+ let u = r.shift();
1804
+ u === void 0 && this.optionMissingArgument(c), this.emit(`option:${c.name()}`, u);
1805
+ } else if (c.optional) {
1806
+ let u = null;
1807
+ r.length > 0 && !o(r[0]) && (u = r.shift()), this.emit(`option:${c.name()}`, u);
1808
+ } else
1809
+ this.emit(`option:${c.name()}`);
1810
+ l = c.variadic ? c : null;
1811
+ continue;
1812
+ }
1813
+ }
1814
+ if (a.length > 2 && a[0] === "-" && a[1] !== "-") {
1815
+ let c = this._findOption(`-${a[1]}`);
1816
+ if (c) {
1817
+ c.required || c.optional && this._combineFlagAndOptionalValue ? this.emit(`option:${c.name()}`, a.slice(2)) : (this.emit(`option\
1818
+ :${c.name()}`), r.unshift(`-${a.slice(2)}`));
1819
+ continue;
1820
+ }
1821
+ }
1822
+ if (/^--[^=]+=/.test(a)) {
1823
+ let c = a.indexOf("="), u = this._findOption(a.slice(0, c));
1824
+ if (u && (u.required || u.optional)) {
1825
+ this.emit(`option:${u.name()}`, a.slice(c + 1));
1826
+ continue;
1827
+ }
1828
+ }
1829
+ if (o(a) && (s = i), (this._enablePositionalOptions || this._passThroughOptions) && t.length === 0 && i.length === 0) {
1830
+ if (this._findCommand(a)) {
1831
+ t.push(a), r.length > 0 && i.push(...r);
1832
+ break;
1833
+ } else if (this._getHelpCommand() && a === this._getHelpCommand().name()) {
1834
+ t.push(a), r.length > 0 && t.push(...r);
1835
+ break;
1836
+ } else if (this._defaultCommandName) {
1837
+ i.push(a), r.length > 0 && i.push(...r);
1838
+ break;
1839
+ }
1840
+ }
1841
+ if (this._passThroughOptions) {
1842
+ s.push(a), r.length > 0 && s.push(...r);
1843
+ break;
1844
+ }
1845
+ s.push(a);
1846
+ }
1847
+ return { operands: t, unknown: i };
1848
+ }
1849
+ /**
1850
+ * Return an object containing local option values as key-value pairs.
1851
+ *
1852
+ * @return {object}
1853
+ */
1854
+ opts() {
1855
+ if (this._storeOptionsAsProperties) {
1856
+ let e = {}, t = this.options.length;
1857
+ for (let i = 0; i < t; i++) {
1858
+ let s = this.options[i].attributeName();
1859
+ e[s] = s === this._versionOptionName ? this._version : this[s];
1860
+ }
1861
+ return e;
1862
+ }
1863
+ return this._optionValues;
1864
+ }
1865
+ /**
1866
+ * Return an object containing merged local and global option values as key-value pairs.
1867
+ *
1868
+ * @return {object}
1869
+ */
1870
+ optsWithGlobals() {
1871
+ return this._getCommandAndAncestors().reduce(
1872
+ (e, t) => Object.assign(e, t.opts()),
1873
+ {}
1874
+ );
1875
+ }
1876
+ /**
1877
+ * Display error message and exit (or call exitOverride).
1878
+ *
1879
+ * @param {string} message
1880
+ * @param {object} [errorOptions]
1881
+ * @param {string} [errorOptions.code] - an id string representing the error
1882
+ * @param {number} [errorOptions.exitCode] - used with process.exit
1883
+ */
1884
+ error(e, t) {
1885
+ this._outputConfiguration.outputError(
1886
+ `${e}
1887
+ `,
1888
+ this._outputConfiguration.writeErr
1889
+ ), typeof this._showHelpAfterError == "string" ? this._outputConfiguration.writeErr(`${this._showHelpAfterError}
1890
+ `) : this._showHelpAfterError && (this._outputConfiguration.writeErr(`
1891
+ `), this.outputHelp({ error: !0 }));
1892
+ let i = t || {}, s = i.exitCode || 1, r = i.code || "commander.error";
1893
+ this._exit(s, r, e);
1894
+ }
1895
+ /**
1896
+ * Apply any option related environment variables, if option does
1897
+ * not have a value from cli or client code.
1898
+ *
1899
+ * @private
1900
+ */
1901
+ _parseOptionsEnv() {
1902
+ this.options.forEach((e) => {
1903
+ if (e.envVar && e.envVar in h.env) {
1904
+ let t = e.attributeName();
1905
+ (this.getOptionValue(t) === void 0 || ["default", "config", "env"].includes(
1906
+ this.getOptionValueSource(t)
1907
+ )) && (e.required || e.optional ? this.emit(`optionEnv:${e.name()}`, h.env[e.envVar]) : this.emit(`optionEnv:${e.name()}`));
1908
+ }
1909
+ });
1910
+ }
1911
+ /**
1912
+ * Apply any implied option values, if option is undefined or default value.
1913
+ *
1914
+ * @private
1915
+ */
1916
+ _parseOptionsImplied() {
1917
+ let e = new nt(this.options), t = /* @__PURE__ */ d((i) => this.getOptionValue(i) !== void 0 && !["default", "implied"].includes(this.
1918
+ getOptionValueSource(i)), "hasCustomOptionValue");
1919
+ this.options.filter(
1920
+ (i) => i.implied !== void 0 && t(i.attributeName()) && e.valueFromOption(
1921
+ this.getOptionValue(i.attributeName()),
1922
+ i
1923
+ )
1924
+ ).forEach((i) => {
1925
+ Object.keys(i.implied).filter((s) => !t(s)).forEach((s) => {
1926
+ this.setOptionValueWithSource(
1927
+ s,
1928
+ i.implied[s],
1929
+ "implied"
1930
+ );
1931
+ });
1932
+ });
1933
+ }
1934
+ /**
1935
+ * Argument `name` is missing.
1936
+ *
1937
+ * @param {string} name
1938
+ * @private
1939
+ */
1940
+ missingArgument(e) {
1941
+ let t = `error: missing required argument '${e}'`;
1942
+ this.error(t, { code: "commander.missingArgument" });
1943
+ }
1944
+ /**
1945
+ * `Option` is missing an argument.
1946
+ *
1947
+ * @param {Option} option
1948
+ * @private
1949
+ */
1950
+ optionMissingArgument(e) {
1951
+ let t = `error: option '${e.flags}' argument missing`;
1952
+ this.error(t, { code: "commander.optionMissingArgument" });
1953
+ }
1954
+ /**
1955
+ * `Option` does not have a value, and is a mandatory option.
1956
+ *
1957
+ * @param {Option} option
1958
+ * @private
1959
+ */
1960
+ missingMandatoryOptionValue(e) {
1961
+ let t = `error: required option '${e.flags}' not specified`;
1962
+ this.error(t, { code: "commander.missingMandatoryOptionValue" });
1963
+ }
1964
+ /**
1965
+ * `Option` conflicts with another option.
1966
+ *
1967
+ * @param {Option} option
1968
+ * @param {Option} conflictingOption
1969
+ * @private
1970
+ */
1971
+ _conflictingOption(e, t) {
1972
+ let i = /* @__PURE__ */ d((o) => {
1973
+ let l = o.attributeName(), a = this.getOptionValue(l), c = this.options.find(
1974
+ (p) => p.negate && l === p.attributeName()
1975
+ ), u = this.options.find(
1976
+ (p) => !p.negate && l === p.attributeName()
1977
+ );
1978
+ return c && (c.presetArg === void 0 && a === !1 || c.presetArg !== void 0 && a === c.presetArg) ? c : u || o;
1979
+ }, "findBestOptionFromValue"), s = /* @__PURE__ */ d((o) => {
1980
+ let l = i(o), a = l.attributeName();
1981
+ return this.getOptionValueSource(a) === "env" ? `environment variable '${l.envVar}'` : `option '${l.flags}'`;
1982
+ }, "getErrorMessage"), r = `error: ${s(e)} cannot be used with ${s(t)}`;
1983
+ this.error(r, { code: "commander.conflictingOption" });
1984
+ }
1985
+ /**
1986
+ * Unknown option `flag`.
1987
+ *
1988
+ * @param {string} flag
1989
+ * @private
1990
+ */
1991
+ unknownOption(e) {
1992
+ if (this._allowUnknownOption) return;
1993
+ let t = "";
1994
+ if (e.startsWith("--") && this._showSuggestionAfterError) {
1995
+ let s = [], r = this;
1996
+ do {
1997
+ let o = r.createHelp().visibleOptions(r).filter((l) => l.long).map((l) => l.long);
1998
+ s = s.concat(o), r = r.parent;
1999
+ } while (r && !r._enablePositionalOptions);
2000
+ t = me(e, s);
2001
+ }
2002
+ let i = `error: unknown option '${e}'${t}`;
2003
+ this.error(i, { code: "commander.unknownOption" });
2004
+ }
2005
+ /**
2006
+ * Excess arguments, more than expected.
2007
+ *
2008
+ * @param {string[]} receivedArgs
2009
+ * @private
2010
+ */
2011
+ _excessArguments(e) {
2012
+ if (this._allowExcessArguments) return;
2013
+ let t = this.registeredArguments.length, i = t === 1 ? "" : "s", r = `error: too many arguments${this.parent ? ` for '${this.name()}'` :
2014
+ ""}. Expected ${t} argument${i} but got ${e.length}.`;
2015
+ this.error(r, { code: "commander.excessArguments" });
2016
+ }
2017
+ /**
2018
+ * Unknown command.
2019
+ *
2020
+ * @private
2021
+ */
2022
+ unknownCommand() {
2023
+ let e = this.args[0], t = "";
2024
+ if (this._showSuggestionAfterError) {
2025
+ let s = [];
2026
+ this.createHelp().visibleCommands(this).forEach((r) => {
2027
+ s.push(r.name()), r.alias() && s.push(r.alias());
2028
+ }), t = me(e, s);
2029
+ }
2030
+ let i = `error: unknown command '${e}'${t}`;
2031
+ this.error(i, { code: "commander.unknownCommand" });
2032
+ }
2033
+ /**
2034
+ * Get or set the program version.
2035
+ *
2036
+ * This method auto-registers the "-V, --version" option which will print the version number.
2037
+ *
2038
+ * You can optionally supply the flags and description to override the defaults.
2039
+ *
2040
+ * @param {string} [str]
2041
+ * @param {string} [flags]
2042
+ * @param {string} [description]
2043
+ * @return {(this | string | undefined)} `this` command for chaining, or version string if no arguments
2044
+ */
2045
+ version(e, t, i) {
2046
+ if (e === void 0) return this._version;
2047
+ this._version = e, t = t || "-V, --version", i = i || "output the version number";
2048
+ let s = this.createOption(t, i);
2049
+ return this._versionOptionName = s.attributeName(), this._registerOption(s), this.on("option:" + s.name(), () => {
2050
+ this._outputConfiguration.writeOut(`${e}
2051
+ `), this._exit(0, "commander.version", e);
2052
+ }), this;
2053
+ }
2054
+ /**
2055
+ * Set the description.
2056
+ *
2057
+ * @param {string} [str]
2058
+ * @param {object} [argsDescription]
2059
+ * @return {(string|Command)}
2060
+ */
2061
+ description(e, t) {
2062
+ return e === void 0 && t === void 0 ? this._description : (this._description = e, t && (this._argsDescription = t), this);
2063
+ }
2064
+ /**
2065
+ * Set the summary. Used when listed as subcommand of parent.
2066
+ *
2067
+ * @param {string} [str]
2068
+ * @return {(string|Command)}
2069
+ */
2070
+ summary(e) {
2071
+ return e === void 0 ? this._summary : (this._summary = e, this);
2072
+ }
2073
+ /**
2074
+ * Set an alias for the command.
2075
+ *
2076
+ * You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
2077
+ *
2078
+ * @param {string} [alias]
2079
+ * @return {(string|Command)}
2080
+ */
2081
+ alias(e) {
2082
+ if (e === void 0) return this._aliases[0];
2083
+ let t = this;
2084
+ if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler && (t = this.commands[this.commands.length -
2085
+ 1]), e === t._name)
2086
+ throw new Error("Command alias can't be the same as its name");
2087
+ let i = this.parent?._findCommand(e);
2088
+ if (i) {
2089
+ let s = [i.name()].concat(i.aliases()).join("|");
2090
+ throw new Error(
2091
+ `cannot add alias '${e}' to command '${this.name()}' as already have command '${s}'`
2092
+ );
2093
+ }
2094
+ return t._aliases.push(e), this;
2095
+ }
2096
+ /**
2097
+ * Set aliases for the command.
2098
+ *
2099
+ * Only the first alias is shown in the auto-generated help.
2100
+ *
2101
+ * @param {string[]} [aliases]
2102
+ * @return {(string[]|Command)}
2103
+ */
2104
+ aliases(e) {
2105
+ return e === void 0 ? this._aliases : (e.forEach((t) => this.alias(t)), this);
2106
+ }
2107
+ /**
2108
+ * Set / get the command usage `str`.
2109
+ *
2110
+ * @param {string} [str]
2111
+ * @return {(string|Command)}
2112
+ */
2113
+ usage(e) {
2114
+ if (e === void 0) {
2115
+ if (this._usage) return this._usage;
2116
+ let t = this.registeredArguments.map((i) => st(i));
2117
+ return [].concat(
2118
+ this.options.length || this._helpOption !== null ? "[options]" : [],
2119
+ this.commands.length ? "[command]" : [],
2120
+ this.registeredArguments.length ? t : []
2121
+ ).join(" ");
2122
+ }
2123
+ return this._usage = e, this;
2124
+ }
2125
+ /**
2126
+ * Get or set the name of the command.
2127
+ *
2128
+ * @param {string} [str]
2129
+ * @return {(string|Command)}
2130
+ */
2131
+ name(e) {
2132
+ return e === void 0 ? this._name : (this._name = e, this);
2133
+ }
2134
+ /**
2135
+ * Set the name of the command from script filename, such as process.argv[1],
2136
+ * or require.main.filename, or __filename.
2137
+ *
2138
+ * (Used internally and public although not documented in README.)
2139
+ *
2140
+ * @example
2141
+ * program.nameFromFilename(require.main.filename);
2142
+ *
2143
+ * @param {string} filename
2144
+ * @return {Command}
2145
+ */
2146
+ nameFromFilename(e) {
2147
+ return this._name = y.basename(e, y.extname(e)), this;
2148
+ }
2149
+ /**
2150
+ * Get or set the directory for searching for executable subcommands of this command.
2151
+ *
2152
+ * @example
2153
+ * program.executableDir(__dirname);
2154
+ * // or
2155
+ * program.executableDir('subcommands');
2156
+ *
2157
+ * @param {string} [path]
2158
+ * @return {(string|null|Command)}
2159
+ */
2160
+ executableDir(e) {
2161
+ return e === void 0 ? this._executableDir : (this._executableDir = e, this);
2162
+ }
2163
+ /**
2164
+ * Return program help documentation.
2165
+ *
2166
+ * @param {{ error: boolean }} [contextOptions] - pass {error:true} to wrap for stderr instead of stdout
2167
+ * @return {string}
2168
+ */
2169
+ helpInformation(e) {
2170
+ let t = this.createHelp();
2171
+ return t.helpWidth === void 0 && (t.helpWidth = e && e.error ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.
2172
+ getOutHelpWidth()), t.formatHelp(this, t);
2173
+ }
2174
+ /**
2175
+ * @private
2176
+ */
2177
+ _getHelpContext(e) {
2178
+ e = e || {};
2179
+ let t = { error: !!e.error }, i;
2180
+ return t.error ? i = /* @__PURE__ */ d((s) => this._outputConfiguration.writeErr(s), "write") : i = /* @__PURE__ */ d((s) => this._outputConfiguration.
2181
+ writeOut(s), "write"), t.write = e.write || i, t.command = this, t;
2182
+ }
2183
+ /**
2184
+ * Output help information for this command.
2185
+ *
2186
+ * Outputs built-in help, and custom text added using `.addHelpText()`.
2187
+ *
2188
+ * @param {{ error: boolean } | Function} [contextOptions] - pass {error:true} to write to stderr instead of stdout
2189
+ */
2190
+ outputHelp(e) {
2191
+ let t;
2192
+ typeof e == "function" && (t = e, e = void 0);
2193
+ let i = this._getHelpContext(e);
2194
+ this._getCommandAndAncestors().reverse().forEach((r) => r.emit("beforeAllHelp", i)), this.emit("beforeHelp", i);
2195
+ let s = this.helpInformation(i);
2196
+ if (t && (s = t(s), typeof s != "string" && !Buffer.isBuffer(s)))
2197
+ throw new Error("outputHelp callback must return a string or a Buffer");
2198
+ i.write(s), this._getHelpOption()?.long && this.emit(this._getHelpOption().long), this.emit("afterHelp", i), this._getCommandAndAncestors().
2199
+ forEach(
2200
+ (r) => r.emit("afterAllHelp", i)
2201
+ );
2202
+ }
2203
+ /**
2204
+ * You can pass in flags and a description to customise the built-in help option.
2205
+ * Pass in false to disable the built-in help option.
2206
+ *
2207
+ * @example
2208
+ * program.helpOption('-?, --help' 'show help'); // customise
2209
+ * program.helpOption(false); // disable
2210
+ *
2211
+ * @param {(string | boolean)} flags
2212
+ * @param {string} [description]
2213
+ * @return {Command} `this` command for chaining
2214
+ */
2215
+ helpOption(e, t) {
2216
+ return typeof e == "boolean" ? (e ? this._helpOption = this._helpOption ?? void 0 : this._helpOption = null, this) : (e = e ?? "-h, --\
2217
+ help", t = t ?? "display help for command", this._helpOption = this.createOption(e, t), this);
2218
+ }
2219
+ /**
2220
+ * Lazy create help option.
2221
+ * Returns null if has been disabled with .helpOption(false).
2222
+ *
2223
+ * @returns {(Option | null)} the help option
2224
+ * @package
2225
+ */
2226
+ _getHelpOption() {
2227
+ return this._helpOption === void 0 && this.helpOption(void 0, void 0), this._helpOption;
2228
+ }
2229
+ /**
2230
+ * Supply your own option to use for the built-in help option.
2231
+ * This is an alternative to using helpOption() to customise the flags and description etc.
2232
+ *
2233
+ * @param {Option} option
2234
+ * @return {Command} `this` command for chaining
2235
+ */
2236
+ addHelpOption(e) {
2237
+ return this._helpOption = e, this;
2238
+ }
2239
+ /**
2240
+ * Output help information and exit.
2241
+ *
2242
+ * Outputs built-in help, and custom text added using `.addHelpText()`.
2243
+ *
2244
+ * @param {{ error: boolean }} [contextOptions] - pass {error:true} to write to stderr instead of stdout
2245
+ */
2246
+ help(e) {
2247
+ this.outputHelp(e);
2248
+ let t = h.exitCode || 0;
2249
+ t === 0 && e && typeof e != "function" && e.error && (t = 1), this._exit(t, "commander.help", "(outputHelp)");
2250
+ }
2251
+ /**
2252
+ * Add additional text to be displayed with the built-in help.
2253
+ *
2254
+ * Position is 'before' or 'after' to affect just this command,
2255
+ * and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
2256
+ *
2257
+ * @param {string} position - before or after built-in help
2258
+ * @param {(string | Function)} text - string to add, or a function returning a string
2259
+ * @return {Command} `this` command for chaining
2260
+ */
2261
+ addHelpText(e, t) {
2262
+ let i = ["beforeAll", "before", "after", "afterAll"];
2263
+ if (!i.includes(e))
2264
+ throw new Error(`Unexpected value for position to addHelpText.
2265
+ Expecting one of '${i.join("', '")}'`);
2266
+ let s = `${e}Help`;
2267
+ return this.on(s, (r) => {
2268
+ let o;
2269
+ typeof t == "function" ? o = t({ error: r.error, command: r.command }) : o = t, o && r.write(`${o}
2270
+ `);
2271
+ }), this;
2272
+ }
2273
+ /**
2274
+ * Output help information if help flags specified
2275
+ *
2276
+ * @param {Array} args - array of options to search for help flags
2277
+ * @private
2278
+ */
2279
+ _outputHelpIfRequested(e) {
2280
+ let t = this._getHelpOption();
2281
+ t && e.find((s) => t.is(s)) && (this.outputHelp(), this._exit(0, "commander.helpDisplayed", "(outputHelp)"));
2282
+ }
2283
+ };
2284
+ function fe(n) {
2285
+ return n.map((e) => {
2286
+ if (!e.startsWith("--inspect"))
2287
+ return e;
2288
+ let t, i = "127.0.0.1", s = "9229", r;
2289
+ return (r = e.match(/^(--inspect(-brk)?)$/)) !== null ? t = r[1] : (r = e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null ? (t =
2290
+ r[1], /^\d+$/.test(r[3]) ? s = r[3] : i = r[3]) : (r = e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null && (t = r[1], i =
2291
+ r[3], s = r[4]), t && s !== "0" ? `${t}=${i}:${parseInt(s) + 1}` : e;
2292
+ });
2293
+ }
2294
+ d(fe, "incrementNodeInspectorPort");
2295
+ ge.Command = ie;
2296
+ });
2297
+
2298
+ // ../node_modules/commander/index.js
2299
+ var ve = b((g) => {
2300
+ var { Argument: xe } = V(), { Command: se } = be(), { CommanderError: ot, InvalidArgumentError: _e } = k(), { Help: at } = Y(), { Option: ye } = X();
2301
+ g.program = new se();
2302
+ g.createCommand = (n) => new se(n);
2303
+ g.createOption = (n, e) => new ye(n, e);
2304
+ g.createArgument = (n, e) => new xe(n, e);
2305
+ g.Command = se;
2306
+ g.Option = ye;
2307
+ g.Argument = xe;
2308
+ g.Help = at;
2309
+ g.CommanderError = ot;
2310
+ g.InvalidArgumentError = _e;
2311
+ g.InvalidOptionArgumentError = _e;
2312
+ });
2313
+
2314
+ // ../node_modules/walk-up-path/dist/cjs/index.js
2315
+ var Oe = b((H) => {
2316
+ "use strict";
2317
+ Object.defineProperty(H, "__esModule", { value: !0 });
2318
+ H.walkUp = void 0;
2319
+ var we = require("path"), lt = /* @__PURE__ */ d(function* (n) {
2320
+ for (n = (0, we.resolve)(n); n; ) {
2321
+ yield n;
2322
+ let e = (0, we.dirname)(n);
2323
+ if (e === n)
2324
+ break;
2325
+ n = e;
2326
+ }
2327
+ }, "walkUp");
2328
+ H.walkUp = lt;
2329
+ });
2330
+
2331
+ // ../node_modules/picocolors/picocolors.js
2332
+ var $e = b((Nt, oe) => {
2333
+ var I = process || {}, Ee = I.argv || [], P = I.env || {}, ut = !(P.NO_COLOR || Ee.includes("--no-color")) && (!!P.FORCE_COLOR || Ee.includes(
2334
+ "--color") || I.platform === "win32" || (I.stdout || {}).isTTY && P.TERM !== "dumb" || !!P.CI), pt = /* @__PURE__ */ d((n, e, t = n) => (i) => {
2335
+ let s = "" + i, r = s.indexOf(e, n.length);
2336
+ return ~r ? n + ht(s, e, t, r) + e : n + s + e;
2337
+ }, "formatter"), ht = /* @__PURE__ */ d((n, e, t, i) => {
2338
+ let s = "", r = 0;
2339
+ do
2340
+ s += n.substring(r, i) + t, r = i + e.length, i = n.indexOf(e, r);
2341
+ while (~i);
2342
+ return s + n.substring(r);
2343
+ }, "replaceClose"), Se = /* @__PURE__ */ d((n = ut) => {
2344
+ let e = n ? pt : () => String;
2345
+ return {
2346
+ isColorSupported: n,
2347
+ reset: e("\x1B[0m", "\x1B[0m"),
2348
+ bold: e("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
2349
+ dim: e("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
2350
+ italic: e("\x1B[3m", "\x1B[23m"),
2351
+ underline: e("\x1B[4m", "\x1B[24m"),
2352
+ inverse: e("\x1B[7m", "\x1B[27m"),
2353
+ hidden: e("\x1B[8m", "\x1B[28m"),
2354
+ strikethrough: e("\x1B[9m", "\x1B[29m"),
2355
+ black: e("\x1B[30m", "\x1B[39m"),
2356
+ red: e("\x1B[31m", "\x1B[39m"),
2357
+ green: e("\x1B[32m", "\x1B[39m"),
2358
+ yellow: e("\x1B[33m", "\x1B[39m"),
2359
+ blue: e("\x1B[34m", "\x1B[39m"),
2360
+ magenta: e("\x1B[35m", "\x1B[39m"),
2361
+ cyan: e("\x1B[36m", "\x1B[39m"),
2362
+ white: e("\x1B[37m", "\x1B[39m"),
2363
+ gray: e("\x1B[90m", "\x1B[39m"),
2364
+ bgBlack: e("\x1B[40m", "\x1B[49m"),
2365
+ bgRed: e("\x1B[41m", "\x1B[49m"),
2366
+ bgGreen: e("\x1B[42m", "\x1B[49m"),
2367
+ bgYellow: e("\x1B[43m", "\x1B[49m"),
2368
+ bgBlue: e("\x1B[44m", "\x1B[49m"),
2369
+ bgMagenta: e("\x1B[45m", "\x1B[49m"),
2370
+ bgCyan: e("\x1B[46m", "\x1B[49m"),
2371
+ bgWhite: e("\x1B[47m", "\x1B[49m"),
2372
+ blackBright: e("\x1B[90m", "\x1B[39m"),
2373
+ redBright: e("\x1B[91m", "\x1B[39m"),
2374
+ greenBright: e("\x1B[92m", "\x1B[39m"),
2375
+ yellowBright: e("\x1B[93m", "\x1B[39m"),
2376
+ blueBright: e("\x1B[94m", "\x1B[39m"),
2377
+ magentaBright: e("\x1B[95m", "\x1B[39m"),
2378
+ cyanBright: e("\x1B[96m", "\x1B[39m"),
2379
+ whiteBright: e("\x1B[97m", "\x1B[39m"),
2380
+ bgBlackBright: e("\x1B[100m", "\x1B[49m"),
2381
+ bgRedBright: e("\x1B[101m", "\x1B[49m"),
2382
+ bgGreenBright: e("\x1B[102m", "\x1B[49m"),
2383
+ bgYellowBright: e("\x1B[103m", "\x1B[49m"),
2384
+ bgBlueBright: e("\x1B[104m", "\x1B[49m"),
2385
+ bgMagentaBright: e("\x1B[105m", "\x1B[49m"),
2386
+ bgCyanBright: e("\x1B[106m", "\x1B[49m"),
2387
+ bgWhiteBright: e("\x1B[107m", "\x1B[49m")
2388
+ };
2389
+ }, "createColors");
2390
+ oe.exports = Se();
2391
+ oe.exports.createColors = Se;
2392
+ });
2393
+
2394
+ // ../node_modules/ts-dedent/dist/index.js
2395
+ var Ne = b((j) => {
2396
+ "use strict";
2397
+ Object.defineProperty(j, "__esModule", { value: !0 });
2398
+ j.dedent = void 0;
2399
+ function Ie(n) {
2400
+ for (var e = [], t = 1; t < arguments.length; t++)
2401
+ e[t - 1] = arguments[t];
2402
+ var i = Array.from(typeof n == "string" ? [n] : n);
2403
+ i[i.length - 1] = i[i.length - 1].replace(/\r?\n([\t ]*)$/, "");
2404
+ var s = i.reduce(function(l, a) {
2405
+ var c = a.match(/\n([\t ]+|(?!\s).)/g);
2406
+ return c ? l.concat(c.map(function(u) {
2407
+ var p, m;
2408
+ return (m = (p = u.match(/[\t ]/g)) === null || p === void 0 ? void 0 : p.length) !== null && m !== void 0 ? m : 0;
2409
+ })) : l;
2410
+ }, []);
2411
+ if (s.length) {
2412
+ var r = new RegExp(`
2413
+ [ ]{` + Math.min.apply(Math, s) + "}", "g");
2414
+ i = i.map(function(l) {
2415
+ return l.replace(r, `
2416
+ `);
2417
+ });
2418
+ }
2419
+ i[0] = i[0].replace(/^\r?\n/, "");
2420
+ var o = i[0];
2421
+ return e.forEach(function(l, a) {
2422
+ var c = o.match(/(?:^|\n)( *)$/), u = c ? c[1] : "", p = l;
2423
+ typeof l == "string" && l.includes(`
2424
+ `) && (p = String(l).split(`
2425
+ `).map(function(m, _) {
2426
+ return _ === 0 ? m : "" + u + m;
2427
+ }).join(`
2428
+ `)), o += p + i[a + 1];
2429
+ }), o;
2430
+ }
2431
+ d(Ie, "dedent");
2432
+ j.dedent = Ie;
2433
+ j.default = Ie;
2434
+ });
2435
+
2436
+ // src/cli/bin/index.ts
2437
+ var C = require("storybook/internal/common"), B = require("storybook/internal/node-logger"), Be = require("storybook/internal/telemetry"), A = $(ve(), 1);
2438
+
2439
+ // ../node_modules/fd-package-json/dist/esm/main.js
2440
+ var Ce = $(Oe(), 1), ke = require("node:path"), D = require("node:fs/promises"), je = require("node:fs");
2441
+ async function dt(n) {
2442
+ try {
2443
+ return (await (0, D.stat)(n)).isFile();
2444
+ } catch {
2445
+ return !1;
2446
+ }
2447
+ }
2448
+ d(dt, "fileExists");
2449
+ async function ct(n) {
2450
+ for (let e of (0, Ce.walkUp)(n)) {
2451
+ let t = (0, ke.resolve)(e, "package.json");
2452
+ if (await dt(t))
2453
+ return t;
2454
+ }
2455
+ return null;
2456
+ }
2457
+ d(ct, "findPackagePath");
2458
+ async function w(n) {
2459
+ let e = await ct(n);
2460
+ if (!e)
2461
+ return null;
2462
+ try {
2463
+ let t = await (0, D.readFile)(e, { encoding: "utf8" });
2464
+ return JSON.parse(t);
2465
+ } catch {
2466
+ return null;
2467
+ }
2468
+ }
2469
+ d(w, "findPackage");
2470
+
2471
+ // node_modules/leven/index.js
2472
+ var re = [], Ae = [];
2473
+ function ne(n, e) {
2474
+ if (n === e)
2475
+ return 0;
2476
+ let t = n;
2477
+ n.length > e.length && (n = e, e = t);
2478
+ let i = n.length, s = e.length;
2479
+ for (; i > 0 && n.charCodeAt(~-i) === e.charCodeAt(~-s); )
2480
+ i--, s--;
2481
+ let r = 0;
2482
+ for (; r < i && n.charCodeAt(r) === e.charCodeAt(r); )
2483
+ r++;
2484
+ if (i -= r, s -= r, i === 0)
2485
+ return s;
2486
+ let o, l, a, c, u = 0, p = 0;
2487
+ for (; u < i; )
2488
+ Ae[u] = n.charCodeAt(r + u), re[u] = ++u;
2489
+ for (; p < s; )
2490
+ for (o = e.charCodeAt(r + p), a = p++, l = p, u = 0; u < i; u++)
2491
+ c = o === Ae[u] ? a : a + 1, a = re[u], l = re[u] = a > l ? c > l ? l + 1 : c : c > a ? a + 1 : c;
2492
+ return l;
2493
+ }
2494
+ d(ne, "leven");
2495
+
2496
+ // src/cli/bin/index.ts
2497
+ var E = $($e(), 1);
2498
+
2499
+ // ../node_modules/tiny-invariant/dist/esm/tiny-invariant.js
2500
+ var mt = process.env.NODE_ENV === "production", ae = "Invariant failed";
2501
+ function O(n, e) {
2502
+ if (!n) {
2503
+ if (mt)
2504
+ throw new Error(ae);
2505
+ var t = typeof e == "function" ? e() : e, i = t ? "".concat(ae, ": ").concat(t) : ae;
2506
+ throw new Error(i);
2507
+ }
2508
+ }
2509
+ d(O, "invariant");
2510
+
2511
+ // package.json
2512
+ var qe = "9.0.0-alpha.10";
2513
+
2514
+ // src/cli/build.ts
2515
+ var Ve = require("storybook/internal/common"), N = require("storybook/internal/core-server");
2516
+ var He = /* @__PURE__ */ d(async (n) => {
2517
+ let e = await w(__dirname);
2518
+ O(e, "Failed to find the closest package.json file.");
2519
+ let t = {
2520
+ ...n,
2521
+ configDir: n.configDir || "./.storybook",
2522
+ outputDir: n.outputDir || "./storybook-static",
2523
+ ignorePreview: !!n.previewUrl && !n.forceBuildPreview,
2524
+ configType: "PRODUCTION",
2525
+ cache: Ve.cache,
2526
+ packageJson: e
2527
+ };
2528
+ await (0, N.withTelemetry)(
2529
+ "build",
2530
+ { cliOptions: n, presetOptions: t },
2531
+ () => (0, N.buildStaticStandalone)(t)
2532
+ );
2533
+ }, "build");
2534
+
2535
+ // src/cli/buildIndex.ts
2536
+ var De = require("storybook/internal/common"), T = require("storybook/internal/core-server");
2537
+ var Pe = /* @__PURE__ */ d(async (n) => {
2538
+ let e = {
2539
+ ...n,
2540
+ configDir: n.configDir || ".storybook",
2541
+ outputFile: n.outputFile || "index.json",
2542
+ ignorePreview: !0,
2543
+ configType: "PRODUCTION",
2544
+ cache: De.cache,
2545
+ packageJson: n.packageJson
2546
+ }, t = {
2547
+ ...e,
2548
+ corePresets: [],
2549
+ overridePresets: []
2550
+ };
2551
+ await (0, T.withTelemetry)("index", { cliOptions: n, presetOptions: t }, () => (0, T.buildIndexStandalone)(e));
2552
+ }, "buildIndex");
2553
+
2554
+ // src/cli/dev.ts
2555
+ var Te = require("storybook/internal/common"), F = require("storybook/internal/core-server"), x = require("storybook/internal/node-logger");
2556
+ var le = $(Ne(), 1);
2557
+ function gt(n) {
2558
+ x.instance.heading = "", n instanceof Error ? n.error ? x.logger.error(n.error) : n.stats && n.stats.compilation.errors ? n.stats.compilation.
2559
+ errors.forEach((e) => x.logger.plain(e)) : x.logger.error(n) : n.compilation?.errors && n.compilation.errors.forEach((e) => x.logger.plain(
2560
+ e)), x.logger.line(), x.logger.warn(
2561
+ n.close ? le.dedent`
2562
+ FATAL broken build!, will close the process,
2563
+ Fix the error below and restart storybook.
2564
+ ` : le.dedent`
2565
+ Broken build, fix the error above.
2566
+ You may need to refresh the browser.
2567
+ `
2568
+ ), x.logger.line();
2569
+ }
2570
+ d(gt, "printError");
2571
+ var Fe = /* @__PURE__ */ d(async (n) => {
2572
+ let { env: e } = process;
2573
+ e.NODE_ENV = e.NODE_ENV || "development";
2574
+ let t = await w(__dirname);
2575
+ O(t, "Failed to find the closest package.json file.");
2576
+ let i = {
2577
+ ...n,
2578
+ configDir: n.configDir || "./.storybook",
2579
+ configType: "DEVELOPMENT",
2580
+ ignorePreview: !!n.previewUrl && !n.forceBuildPreview,
2581
+ cache: Te.cache,
2582
+ packageJson: t
2583
+ };
2584
+ await (0, F.withTelemetry)(
2585
+ "dev",
2586
+ {
2587
+ cliOptions: n,
2588
+ presetOptions: i,
2589
+ printError: gt
2590
+ },
2591
+ () => (0, F.buildDevStandalone)(i)
2592
+ );
2593
+ }, "dev");
2594
+
2595
+ // src/cli/bin/index.ts
2596
+ (0, Be.addToGlobalContext)("cliVersion", C.versions.storybook);
2597
+ var S = console, de = /* @__PURE__ */ d((n) => A.program.command(n).option(
2598
+ "--disable-telemetry",
2599
+ "Disable sending telemetry data",
2600
+ // default value is false, but if the user sets STORYBOOK_DISABLE_TELEMETRY, it can be true
2601
+ process.env.STORYBOOK_DISABLE_TELEMETRY && process.env.STORYBOOK_DISABLE_TELEMETRY !== "false"
2602
+ ).option("--debug", "Get more logs in debug mode", !1).option("--enable-crash-reports", "Enable sending crash reports to telemetry data"), "\
2603
+ command");
2604
+ de("dev").option("-p, --port <number>", "Port to run Storybook", (n) => parseInt(n, 10)).option("-h, --host <string>", "Host to run Storyboo\
2605
+ k").option("-c, --config-dir <dir-name>", "Directory where to load Storybook configurations from").option(
2606
+ "--https",
2607
+ "Serve Storybook over HTTPS. Note: You must provide your own certificate information."
2608
+ ).option(
2609
+ "--ssl-ca <ca>",
2610
+ "Provide an SSL certificate authority. (Optional with --https, required if using a self-signed certificate)",
2611
+ C.parseList
2612
+ ).option("--ssl-cert <cert>", "Provide an SSL certificate. (Required with --https)").option("--ssl-key <key>", "Provide an SSL key. (Require\
2613
+ d with --https)").option("--smoke-test", "Exit after successful start").option("--ci", "CI mode (skip interactive prompts, don't open browse\
2614
+ r)").option("--no-open", "Do not open Storybook automatically in the browser").option("--loglevel <level>", "Control level of logging during\
2615
+ build").option("--quiet", "Suppress verbose build output").option("--no-version-updates", "Suppress update check", !0).option("--debug-webp\
2616
+ ack", "Display final webpack configurations for debugging purposes").option(
2617
+ "--webpack-stats-json [directory]",
2618
+ "Write Webpack stats JSON to disk (synonym for `--stats-json`)"
2619
+ ).option("--stats-json [directory]", "Write stats JSON to disk").option(
2620
+ "--preview-url <string>",
2621
+ "Disables the default storybook preview and lets your use your own"
2622
+ ).option("--force-build-preview", "Build the preview iframe even if you are using --preview-url").option("--docs", "Build a documentation-on\
2623
+ ly site using addon-docs").option("--exact-port", "Exit early if the desired port is not available").option(
2624
+ "--initial-path [path]",
2625
+ "URL path to be appended when visiting Storybook for the first time"
2626
+ ).action(async (n) => {
2627
+ B.logger.setLevel(n.loglevel);
2628
+ let e = await w(__dirname);
2629
+ O(e, "Failed to find the closest package.json file."), S.log(E.default.bold(`${e.name} v${e.version}`) + E.default.reset(`
2630
+ `)), (0, C.getEnvConfig)(n, {
2631
+ port: "SBCONFIG_PORT",
2632
+ host: "SBCONFIG_HOSTNAME",
2633
+ staticDir: "SBCONFIG_STATIC_DIR",
2634
+ configDir: "SBCONFIG_CONFIG_DIR",
2635
+ ci: "CI"
2636
+ }), parseInt(`${n.port}`, 10) && (n.port = parseInt(`${n.port}`, 10)), await Fe({ ...n, packageJson: e }).catch(() => process.exit(1));
2637
+ });
2638
+ de("build").option("-o, --output-dir <dir-name>", "Directory where to store built files").option("-c, --config-dir <dir-name>", "Directory w\
2639
+ here to load Storybook configurations from").option("--quiet", "Suppress verbose build output").option("--loglevel <level>", "Control level \
2640
+ of logging during build").option("--debug-webpack", "Display final webpack configurations for debugging purposes").option(
2641
+ "--webpack-stats-json [directory]",
2642
+ "Write Webpack stats JSON to disk (synonym for `--stats-json`)"
2643
+ ).option("--stats-json [directory]", "Write stats JSON to disk").option(
2644
+ "--preview-url <string>",
2645
+ "Disables the default storybook preview and lets your use your own"
2646
+ ).option("--force-build-preview", "Build the preview iframe even if you are using --preview-url").option("--docs", "Build a documentation-on\
2647
+ ly site using addon-docs").option("--test", "Build stories optimized for testing purposes.").action(async (n) => {
2648
+ let { env: e } = process;
2649
+ e.NODE_ENV = e.NODE_ENV || "production";
2650
+ let t = await w(__dirname);
2651
+ O(t, "Failed to find the closest package.json file."), B.logger.setLevel(n.loglevel), S.log(E.default.bold(`${t.name} v${t.version}
2652
+ `)), (0, C.getEnvConfig)(n, {
2653
+ staticDir: "SBCONFIG_STATIC_DIR",
2654
+ outputDir: "SBCONFIG_OUTPUT_DIR",
2655
+ configDir: "SBCONFIG_CONFIG_DIR"
2656
+ }), await He({
2657
+ ...n,
2658
+ packageJson: t,
2659
+ test: !!n.test || process.env.SB_TESTBUILD === "true"
2660
+ }).catch(() => process.exit(1));
2661
+ });
2662
+ de("index").option("-o, --output-file <file-name>", "JSON file to output index").option("-c, --config-dir <dir-name>", "Directory where to l\
2663
+ oad Storybook configurations from").option("--quiet", "Suppress verbose build output").option("--loglevel <level>", "Control level of loggin\
2664
+ g during build").action(async (n) => {
2665
+ let { env: e } = process;
2666
+ e.NODE_ENV = e.NODE_ENV || "production";
2667
+ let t = await w(__dirname);
2668
+ O(t, "Failed to find the closest package.json file."), B.logger.setLevel(n.loglevel), S.log(E.default.bold(`${t.name} v${t.version}
2669
+ `)), (0, C.getEnvConfig)(n, {
2670
+ configDir: "SBCONFIG_CONFIG_DIR",
2671
+ outputFile: "SBCONFIG_OUTPUT_FILE"
2672
+ }), await Pe({
2673
+ ...n,
2674
+ packageJson: t
2675
+ }).catch(() => process.exit(1));
2676
+ });
2677
+ A.program.on("command:*", ([n]) => {
2678
+ S.error(
2679
+ ` Invalid command: %s.
2680
+ See --help for a list of available commands.`,
2681
+ n
2682
+ );
2683
+ let t = A.program.commands.map((i) => i.name()).find((i) => ne(i, n) < 3);
2684
+ t && S.info(`
2685
+ Did you mean ${t}?`), process.exit(1);
2686
+ });
2687
+ A.program.usage("<command> [options]").version(String(qe)).parse(process.argv);