@ollie-shop/cli 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/.turbo/turbo-build.log +2 -11
  2. package/CHANGELOG.md +13 -7
  3. package/CLAUDE_CLI.md +265 -0
  4. package/README.md +704 -8
  5. package/__tests__/mocks/console.ts +22 -0
  6. package/__tests__/mocks/core.ts +137 -0
  7. package/__tests__/mocks/index.ts +4 -0
  8. package/__tests__/mocks/inquirer.ts +16 -0
  9. package/__tests__/mocks/progress.ts +19 -0
  10. package/dist/__tests__/helpers/cli-test-helper.d.ts +89 -0
  11. package/dist/__tests__/helpers/cli-test-helper.d.ts.map +1 -0
  12. package/dist/__tests__/helpers/cli-test-helper.js +220 -0
  13. package/dist/__tests__/mocks/index.d.ts +69 -0
  14. package/dist/__tests__/mocks/index.d.ts.map +1 -0
  15. package/dist/__tests__/mocks/index.js +77 -0
  16. package/dist/actions/component.actions.d.ts +14 -0
  17. package/dist/actions/component.actions.d.ts.map +1 -0
  18. package/dist/actions/component.actions.js +273 -0
  19. package/dist/actions/function.actions.d.ts +15 -0
  20. package/dist/actions/function.actions.d.ts.map +1 -0
  21. package/dist/actions/function.actions.js +254 -0
  22. package/dist/actions/project.actions.d.ts +17 -0
  23. package/dist/actions/project.actions.d.ts.map +1 -0
  24. package/dist/actions/project.actions.js +97 -0
  25. package/dist/actions/version.actions.d.ts +19 -0
  26. package/dist/actions/version.actions.d.ts.map +1 -0
  27. package/dist/actions/version.actions.js +216 -0
  28. package/dist/commands/component.d.ts +3 -0
  29. package/dist/commands/component.d.ts.map +1 -0
  30. package/dist/commands/component.js +192 -0
  31. package/dist/commands/docs.d.ts +3 -0
  32. package/dist/commands/docs.d.ts.map +1 -0
  33. package/dist/commands/docs.js +16 -0
  34. package/dist/commands/function.d.ts +3 -0
  35. package/dist/commands/function.d.ts.map +1 -0
  36. package/dist/commands/function.js +243 -0
  37. package/dist/commands/help.d.ts +3 -0
  38. package/dist/commands/help.d.ts.map +1 -0
  39. package/dist/commands/help.js +20 -0
  40. package/dist/commands/index.d.ts +3 -0
  41. package/dist/commands/index.d.ts.map +1 -0
  42. package/dist/commands/index.js +26 -0
  43. package/dist/commands/login.d.ts +3 -0
  44. package/dist/commands/login.d.ts.map +1 -0
  45. package/dist/commands/login.js +175 -0
  46. package/dist/commands/project.d.ts +3 -0
  47. package/dist/commands/project.d.ts.map +1 -0
  48. package/dist/commands/project.js +78 -0
  49. package/dist/commands/store-version.d.ts +3 -0
  50. package/dist/commands/store-version.d.ts.map +1 -0
  51. package/dist/commands/store-version.js +241 -0
  52. package/dist/commands/version.d.ts +3 -0
  53. package/dist/commands/version.d.ts.map +1 -0
  54. package/dist/commands/version.js +46 -0
  55. package/dist/commands/whoami.d.ts +3 -0
  56. package/dist/commands/whoami.d.ts.map +1 -0
  57. package/dist/commands/whoami.js +41 -0
  58. package/dist/index.d.ts +3 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +88 -478
  61. package/dist/prompts/component.prompts.d.ts +14 -0
  62. package/dist/prompts/component.prompts.d.ts.map +1 -0
  63. package/dist/prompts/component.prompts.js +75 -0
  64. package/dist/prompts/function.prompts.d.ts +21 -0
  65. package/dist/prompts/function.prompts.d.ts.map +1 -0
  66. package/dist/prompts/function.prompts.js +127 -0
  67. package/dist/schemas/command.schema.d.ts +516 -0
  68. package/dist/schemas/command.schema.d.ts.map +1 -0
  69. package/dist/schemas/command.schema.js +267 -0
  70. package/dist/types/index.d.ts +147 -0
  71. package/dist/types/index.d.ts.map +1 -0
  72. package/dist/types/index.js +18 -0
  73. package/dist/utils/auth.d.ts +4 -0
  74. package/dist/utils/auth.d.ts.map +1 -0
  75. package/dist/utils/auth.js +26 -0
  76. package/dist/utils/cli-progress-reporter.d.ts +12 -0
  77. package/dist/utils/cli-progress-reporter.d.ts.map +1 -0
  78. package/dist/utils/cli-progress-reporter.js +77 -0
  79. package/dist/utils/command-builder.d.ts +22 -0
  80. package/dist/utils/command-builder.d.ts.map +1 -0
  81. package/dist/utils/command-builder.js +268 -0
  82. package/dist/utils/command-helpers.d.ts +19 -0
  83. package/dist/utils/command-helpers.d.ts.map +1 -0
  84. package/dist/utils/command-helpers.js +79 -0
  85. package/dist/utils/command-parser.d.ts +146 -0
  86. package/dist/utils/command-parser.d.ts.map +1 -0
  87. package/dist/utils/command-parser.js +179 -0
  88. package/dist/utils/command-suggestions.d.ts +35 -0
  89. package/dist/utils/command-suggestions.d.ts.map +1 -0
  90. package/dist/utils/command-suggestions.js +152 -0
  91. package/dist/utils/console.d.ts +44 -0
  92. package/dist/utils/console.d.ts.map +1 -0
  93. package/dist/utils/console.js +233 -0
  94. package/dist/utils/constants.d.ts +8 -0
  95. package/dist/utils/constants.d.ts.map +1 -0
  96. package/dist/utils/constants.js +10 -0
  97. package/dist/utils/context-detector.d.ts +12 -0
  98. package/dist/utils/context-detector.d.ts.map +1 -0
  99. package/dist/utils/context-detector.js +155 -0
  100. package/dist/utils/enhanced-error-handler.d.ts +47 -0
  101. package/dist/utils/enhanced-error-handler.d.ts.map +1 -0
  102. package/dist/utils/enhanced-error-handler.js +221 -0
  103. package/dist/utils/error-handler.d.ts +3 -0
  104. package/dist/utils/error-handler.d.ts.map +1 -0
  105. package/dist/utils/error-handler.js +55 -0
  106. package/dist/utils/errors.d.ts +44 -0
  107. package/dist/utils/errors.d.ts.map +1 -0
  108. package/dist/utils/errors.js +76 -0
  109. package/dist/utils/interactive-builder.d.ts +22 -0
  110. package/dist/utils/interactive-builder.d.ts.map +1 -0
  111. package/dist/utils/interactive-builder.js +246 -0
  112. package/dist/utils/rich-progress.d.ts +59 -0
  113. package/dist/utils/rich-progress.d.ts.map +1 -0
  114. package/dist/utils/rich-progress.js +234 -0
  115. package/dist/utils/store.d.ts +11 -0
  116. package/dist/utils/store.d.ts.map +1 -0
  117. package/dist/utils/store.js +19 -0
  118. package/dist/utils/validation-error-formatter.d.ts +25 -0
  119. package/dist/utils/validation-error-formatter.d.ts.map +1 -0
  120. package/dist/utils/validation-error-formatter.js +258 -0
  121. package/dist/utils/validation-helpers.d.ts +60 -0
  122. package/dist/utils/validation-helpers.d.ts.map +1 -0
  123. package/dist/utils/validation-helpers.js +152 -0
  124. package/package.json +43 -11
  125. package/src/__tests__/helpers/cli-test-helper.ts +281 -0
  126. package/src/__tests__/mocks/index.ts +142 -0
  127. package/src/actions/component.actions.ts +334 -0
  128. package/src/actions/function.actions.ts +313 -0
  129. package/src/actions/project.actions.ts +126 -0
  130. package/src/actions/version.actions.ts +233 -0
  131. package/src/commands/__tests__/component-validation.test.ts +250 -0
  132. package/src/commands/__tests__/component.test.ts +321 -0
  133. package/src/commands/__tests__/function-validation.test.ts +220 -0
  134. package/src/commands/__tests__/function.test.ts +286 -0
  135. package/src/commands/__tests__/store-version-validation.test.ts +414 -0
  136. package/src/commands/__tests__/store-version.test.ts +405 -0
  137. package/src/commands/__tests__/version.test.ts +71 -0
  138. package/src/commands/component.ts +188 -0
  139. package/src/commands/docs.ts +11 -11
  140. package/src/commands/function.ts +252 -0
  141. package/src/commands/help.ts +8 -18
  142. package/src/commands/index.ts +14 -7
  143. package/src/commands/login.ts +19 -79
  144. package/src/commands/project.ts +107 -0
  145. package/src/commands/store-version.ts +242 -0
  146. package/src/commands/version.ts +45 -8
  147. package/src/commands/whoami.ts +8 -13
  148. package/src/index.ts +108 -34
  149. package/src/prompts/component.prompts.ts +94 -0
  150. package/src/prompts/function.prompts.ts +168 -0
  151. package/src/schemas/command.schema.ts +354 -0
  152. package/src/types/index.ts +183 -0
  153. package/src/utils/__tests__/command-parser.test.ts +159 -0
  154. package/src/utils/__tests__/command-suggestions.test.ts +185 -0
  155. package/src/utils/__tests__/console.test.ts +192 -0
  156. package/src/utils/__tests__/context-detector.test.ts +258 -0
  157. package/src/utils/__tests__/enhanced-error-handler.test.ts +137 -0
  158. package/src/utils/__tests__/error-handler.test.ts +107 -0
  159. package/src/utils/__tests__/rich-progress.test.ts +170 -0
  160. package/src/utils/__tests__/validation-error-formatter.test.ts +175 -0
  161. package/src/utils/__tests__/validation-helpers.test.ts +125 -0
  162. package/src/utils/auth.ts +0 -1
  163. package/src/utils/cli-progress-reporter.ts +84 -0
  164. package/src/utils/command-builder.ts +390 -0
  165. package/src/utils/command-helpers.ts +83 -0
  166. package/src/utils/command-parser.ts +250 -0
  167. package/src/utils/command-suggestions.ts +176 -0
  168. package/src/utils/console.ts +291 -0
  169. package/src/utils/context-detector.ts +177 -0
  170. package/src/utils/enhanced-error-handler.ts +264 -0
  171. package/src/utils/error-handler.ts +60 -0
  172. package/src/utils/errors.ts +125 -0
  173. package/src/utils/interactive-builder.ts +271 -0
  174. package/src/utils/rich-progress.ts +320 -0
  175. package/src/utils/validation-error-formatter.ts +337 -0
  176. package/src/utils/validation-helpers.ts +192 -0
  177. package/tsconfig.json +13 -7
  178. package/vitest.config.ts +28 -0
  179. package/vitest.setup.ts +29 -0
  180. package/src/commands/validate.ts +0 -62
  181. package/src/utils/core.ts +0 -105
  182. package/tsup.config.ts +0 -15
@@ -0,0 +1,268 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildCommand = buildCommand;
4
+ exports.buildCommandGroup = buildCommandGroup;
5
+ const zod_1 = require("zod");
6
+ const console_1 = require("./console");
7
+ const validation_error_formatter_1 = require("./validation-error-formatter");
8
+ /**
9
+ * Build an enhanced command with validation and error handling
10
+ */
11
+ function setupCommandAliases(cmd, aliases) {
12
+ if (!aliases)
13
+ return;
14
+ for (const alias of aliases) {
15
+ cmd.alias(alias);
16
+ }
17
+ }
18
+ function isValidDefaultValue(value) {
19
+ return (typeof value === "string" ||
20
+ typeof value === "boolean" ||
21
+ Array.isArray(value));
22
+ }
23
+ function addOption(cmd, option) {
24
+ if (option.required) {
25
+ cmd.requiredOption(option.flags, option.description);
26
+ return;
27
+ }
28
+ const hasParser = option.parser !== undefined;
29
+ const hasDefault = option.defaultValue !== undefined && option.defaultValue !== null;
30
+ if (hasParser && hasDefault && option.parser) {
31
+ cmd.option(option.flags, option.description, option.parser, option.defaultValue);
32
+ }
33
+ else if (hasParser && option.parser) {
34
+ cmd.option(option.flags, option.description, option.parser);
35
+ }
36
+ else if (hasDefault) {
37
+ // Commander.js doesn't accept number as defaultValue, convert to string
38
+ const defaultValue = typeof option.defaultValue === "number"
39
+ ? String(option.defaultValue)
40
+ : option.defaultValue;
41
+ if (isValidDefaultValue(defaultValue)) {
42
+ cmd.option(option.flags, option.description, defaultValue);
43
+ }
44
+ else {
45
+ cmd.option(option.flags, option.description);
46
+ }
47
+ }
48
+ else {
49
+ cmd.option(option.flags, option.description);
50
+ }
51
+ }
52
+ function setupCommandOptions(cmd, options) {
53
+ if (!options)
54
+ return;
55
+ for (const option of options) {
56
+ addOption(cmd, option);
57
+ }
58
+ }
59
+ function setupCommandExamples(cmd, examples) {
60
+ if (!examples || examples.length === 0)
61
+ return;
62
+ cmd.addHelpText("after", "\nExamples:");
63
+ for (const example of examples) {
64
+ cmd.addHelpText("after", ` ${example.description}:`);
65
+ cmd.addHelpText("after", ` $ ${example.command}\n`);
66
+ }
67
+ }
68
+ function buildCommand(parent, config) {
69
+ const cmd = parent.command(config.name).description(config.description);
70
+ setupCommandAliases(cmd, config.aliases);
71
+ setupCommandOptions(cmd, config.options);
72
+ setupCommandExamples(cmd, config.examples);
73
+ // Add enhanced action handler with validation
74
+ cmd.action(async (options) => {
75
+ try {
76
+ const validatedOptions = await validateOptions(options, config, parent);
77
+ await config.handler(validatedOptions, console_1.console);
78
+ }
79
+ catch (error) {
80
+ handleCommandError(error, config, parent);
81
+ }
82
+ });
83
+ // Override error handling
84
+ cmd.exitOverride();
85
+ cmd.configureOutput({
86
+ writeErr: (str) => handleCommanderError(str, parent, cmd, config),
87
+ });
88
+ return cmd;
89
+ }
90
+ /**
91
+ * Extract option name from flags string
92
+ */
93
+ function getOptionName(flags) {
94
+ // Extract long option name from flags like "-n, --name <value>"
95
+ const match = flags.match(/--([a-z-]+)/i);
96
+ return match?.[1] ?? flags;
97
+ }
98
+ /**
99
+ * Validate command options
100
+ */
101
+ async function validateOptions(options, config, parent) {
102
+ let validatedOptions = options;
103
+ // Validate with schema if provided
104
+ if (config.schema) {
105
+ const result = config.schema.safeParse(options);
106
+ if (!result.success) {
107
+ const errors = (0, validation_error_formatter_1.formatZodError)(result.error, parent.name());
108
+ (0, validation_error_formatter_1.displayErrors)(console_1.console, errors, `${parent.name()} ${config.name}`);
109
+ // Throw an error that will be caught by the command handler
110
+ const error = new Error("Validation failed");
111
+ error.exitCode = 1;
112
+ error.isValidationError = true;
113
+ throw error;
114
+ }
115
+ validatedOptions = result.data;
116
+ }
117
+ // Check for required options
118
+ checkRequiredOptions(options, config, parent);
119
+ return validatedOptions;
120
+ }
121
+ /**
122
+ * Check required options
123
+ */
124
+ function checkRequiredOptions(options, config, parent) {
125
+ if (!config.options)
126
+ return;
127
+ const missingRequired = config.options
128
+ .filter((opt) => opt.required &&
129
+ !options[getOptionName(opt.flags)])
130
+ .map((opt) => getOptionName(opt.flags));
131
+ if (missingRequired.length > 0) {
132
+ displayMissingOptions(missingRequired, config, parent);
133
+ // Throw an error that will be caught by the command handler
134
+ const error = new Error("Missing required options");
135
+ error.exitCode = 1;
136
+ error.isValidationError = true;
137
+ throw error;
138
+ }
139
+ }
140
+ /**
141
+ * Display missing required options
142
+ */
143
+ function displayMissingOptions(missingRequired, config, parent) {
144
+ console_1.console.error("❌ Missing required options:");
145
+ for (const optName of missingRequired) {
146
+ const opt = config.options?.find((o) => getOptionName(o.flags) === optName);
147
+ if (opt) {
148
+ console_1.console.error(` • --${optName}: ${opt.description}`);
149
+ }
150
+ }
151
+ console_1.console.log("");
152
+ console_1.console.info(`💡 For more help, run: ollieshop ${parent.name()} ${config.name} --help`);
153
+ }
154
+ /**
155
+ * Handle command errors
156
+ */
157
+ function handleCommandError(error, config, parent) {
158
+ // Check if this is a validation error that was already displayed
159
+ if (error instanceof Error) {
160
+ const cliError = error;
161
+ if (cliError.isValidationError) {
162
+ // Error messages already displayed, just exit
163
+ process.exit(cliError.exitCode || 1);
164
+ }
165
+ }
166
+ else if (error instanceof zod_1.z.ZodError) {
167
+ const errors = (0, validation_error_formatter_1.formatZodError)(error, config.name);
168
+ (0, validation_error_formatter_1.displayErrors)(console_1.console, errors, `${parent.name()} ${config.name}`);
169
+ }
170
+ else {
171
+ console_1.console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
172
+ }
173
+ process.exit(1);
174
+ }
175
+ /**
176
+ * Handle Commander.js errors
177
+ */
178
+ function handleCommanderError(str, parent, cmd, config) {
179
+ if (str.includes("error: unknown option")) {
180
+ handleUnknownOption(str, parent, cmd, config);
181
+ }
182
+ else if (str.includes("error: missing required argument")) {
183
+ handleMissingArgument(str, parent, config);
184
+ }
185
+ else {
186
+ console_1.console.error(str.trim());
187
+ }
188
+ }
189
+ /**
190
+ * Handle unknown option error
191
+ */
192
+ function handleUnknownOption(str, parent, cmd, config) {
193
+ const match = str.match(/unknown option '(.+)'/);
194
+ if (!match)
195
+ return;
196
+ const unknownOption = match[1] ?? "";
197
+ console_1.console.error(`❌ Unknown option: ${unknownOption}`);
198
+ // Suggest similar options
199
+ const validOptions = config.options?.map((opt) => `--${getOptionName(opt.flags)}`) || [];
200
+ const suggestion = (0, validation_error_formatter_1.suggestCommand)(unknownOption.replace(/^-+/, ""), validOptions.map((opt) => opt.replace(/^-+/, "")));
201
+ if (suggestion) {
202
+ console_1.console.log("");
203
+ console_1.console.info(`💡 Did you mean: --${suggestion}?`);
204
+ }
205
+ console_1.console.log("");
206
+ console_1.console.info(`💡 For available options, run: ollieshop ${parent.name()} ${cmd.name()} --help`);
207
+ }
208
+ /**
209
+ * Handle missing argument error
210
+ */
211
+ function handleMissingArgument(str, parent, config) {
212
+ const match = str.match(/missing required argument '(.+)'/);
213
+ if (!match)
214
+ return;
215
+ console_1.console.error(`❌ Missing required argument: ${match[1]}`);
216
+ console_1.console.log("");
217
+ console_1.console.info(`💡 For usage help, run: ollieshop ${parent.name()} ${config.name} --help`);
218
+ }
219
+ /**
220
+ * Build a command group (like "component" or "function")
221
+ */
222
+ function buildCommandGroup(program, name, description, aliases) {
223
+ const cmd = program.command(name).description(description);
224
+ if (aliases) {
225
+ for (const alias of aliases) {
226
+ cmd.alias(alias);
227
+ }
228
+ }
229
+ // Add custom error handling
230
+ cmd.exitOverride();
231
+ cmd.configureOutput({
232
+ writeErr: (str) => handleGroupCommandError(str, cmd, name),
233
+ });
234
+ return cmd;
235
+ }
236
+ /**
237
+ * Handle command group errors
238
+ */
239
+ function handleGroupCommandError(str, cmd, groupName) {
240
+ if (str.includes("is not a") && str.includes("command")) {
241
+ handleUnknownSubcommand(str, cmd, groupName);
242
+ }
243
+ else {
244
+ console_1.console.error(str.trim());
245
+ }
246
+ }
247
+ /**
248
+ * Handle unknown subcommand error
249
+ */
250
+ function handleUnknownSubcommand(str, cmd, groupName) {
251
+ const match = str.match(/'([^']+)' is not a/);
252
+ if (!match)
253
+ return;
254
+ const unknownCmd = match[1] ?? "";
255
+ console_1.console.error(`❌ Unknown command: ${unknownCmd}`);
256
+ // Get subcommands
257
+ const subcommands = cmd.commands.map((c) => c.name());
258
+ const suggestion = (0, validation_error_formatter_1.suggestCommand)(unknownCmd, subcommands);
259
+ if (suggestion) {
260
+ console_1.console.log("");
261
+ console_1.console.info(`💡 Did you mean: ollieshop ${groupName} ${suggestion}?`);
262
+ }
263
+ console_1.console.log("");
264
+ console_1.console.info("💡 Available commands:");
265
+ for (const subcmd of subcommands) {
266
+ console_1.console.log(` • ${subcmd}`);
267
+ }
268
+ }
@@ -0,0 +1,19 @@
1
+ import { z } from "zod";
2
+ import type { CliConsole } from "./console";
3
+ /**
4
+ * Handle errors in a consistent way across all commands
5
+ */
6
+ export declare function handleCommandError(error: unknown, console: CliConsole): void;
7
+ /**
8
+ * Parse and validate command options using a Zod schema
9
+ */
10
+ export declare function parseOptions<T>(schema: z.ZodSchema<T>, options: Record<string, unknown>): T;
11
+ /**
12
+ * Create an action handler with schema validation and error handling
13
+ */
14
+ export declare function createAction<T>(schema: z.ZodSchema<T>, action: (options: T, cliConsole: CliConsole) => Promise<void>): (firstArg: unknown, options: Record<string, unknown>) => Promise<void>;
15
+ /**
16
+ * Create a simple action handler without schema validation
17
+ */
18
+ export declare function createSimpleAction(action: (cliConsole: CliConsole) => Promise<void>): () => Promise<void>;
19
+ //# sourceMappingURL=command-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-helpers.d.ts","sourceRoot":"","sources":["../../src/utils/command-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,GAAG,IAAI,CAU5E;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EACtB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,CAAC,CAYH;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EACtB,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,IAE/C,UAAU,OAAO,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,mBAqBlE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,uBASlD"}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleCommandError = handleCommandError;
4
+ exports.parseOptions = parseOptions;
5
+ exports.createAction = createAction;
6
+ exports.createSimpleAction = createSimpleAction;
7
+ const zod_1 = require("zod");
8
+ const console_1 = require("./console");
9
+ /**
10
+ * Handle errors in a consistent way across all commands
11
+ */
12
+ function handleCommandError(error, console) {
13
+ if (error instanceof Error) {
14
+ console.error(error.message);
15
+ if (process.env.DEBUG) {
16
+ console.debug(error.stack || "");
17
+ }
18
+ }
19
+ else {
20
+ console.error("An unexpected error occurred");
21
+ }
22
+ process.exit(1);
23
+ }
24
+ /**
25
+ * Parse and validate command options using a Zod schema
26
+ */
27
+ function parseOptions(schema, options) {
28
+ try {
29
+ return schema.parse(options);
30
+ }
31
+ catch (error) {
32
+ if (error instanceof zod_1.z.ZodError) {
33
+ const formattedErrors = error.errors
34
+ .map((err) => `${err.path.join(".")}: ${err.message}`)
35
+ .join("\n");
36
+ throw new Error(`Invalid options:\n${formattedErrors}`);
37
+ }
38
+ throw error;
39
+ }
40
+ }
41
+ /**
42
+ * Create an action handler with schema validation and error handling
43
+ */
44
+ function createAction(schema, action) {
45
+ return async (firstArg, options) => {
46
+ try {
47
+ // Handle both positional args and options
48
+ const combinedOptions = { ...options };
49
+ if (firstArg !== undefined) {
50
+ // Try to determine the first property name from common patterns
51
+ const possibleKeys = ["name", "path", "target"];
52
+ for (const key of possibleKeys) {
53
+ if (!combinedOptions[key]) {
54
+ combinedOptions[key] = firstArg;
55
+ break;
56
+ }
57
+ }
58
+ }
59
+ const parsedOptions = parseOptions(schema, combinedOptions);
60
+ await action(parsedOptions, console_1.console);
61
+ }
62
+ catch (error) {
63
+ handleCommandError(error, console_1.console);
64
+ }
65
+ };
66
+ }
67
+ /**
68
+ * Create a simple action handler without schema validation
69
+ */
70
+ function createSimpleAction(action) {
71
+ return async () => {
72
+ try {
73
+ await action(console_1.console);
74
+ }
75
+ catch (error) {
76
+ handleCommandError(error, console_1.console);
77
+ }
78
+ };
79
+ }
@@ -0,0 +1,146 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Create a Commander option parser that validates with Zod schema
4
+ */
5
+ export declare function createOptionParser<T>(schema: z.ZodSchema<T>, fieldName: string, helpText?: string): (value: string) => T;
6
+ /**
7
+ * Parse component name with validation
8
+ */
9
+ export declare const parseComponentName: (value: string) => string;
10
+ /**
11
+ * Parse function name with validation
12
+ */
13
+ export declare const parseFunctionName: (value: string) => string;
14
+ /**
15
+ * Parse component slot with validation
16
+ */
17
+ export declare const parseComponentSlot: (value: string) => "header" | "footer" | "sidebar" | "main" | "checkout-summary" | "payment-method" | "shipping-method" | "customer-info" | "order-confirmation";
18
+ /**
19
+ * Parse function invocation with validation
20
+ */
21
+ export declare const parseFunctionInvocation: (value: string) => "request" | "response";
22
+ /**
23
+ * Parse boolean option with better error handling
24
+ */
25
+ export declare function parseBooleanOption(value: string): boolean;
26
+ /**
27
+ * Parse path option with validation
28
+ */
29
+ export declare const parsePath: (value: string) => string;
30
+ /**
31
+ * Parse UUID with validation
32
+ */
33
+ export declare const parseUUID: (value: string) => string;
34
+ /**
35
+ * Parse store ID with validation
36
+ */
37
+ export declare const parseStoreId: (value: string) => string;
38
+ /**
39
+ * Parse version name with validation
40
+ */
41
+ export declare const parseVersionName: (value: string) => string;
42
+ /**
43
+ * Parse priority with validation
44
+ */
45
+ export declare const parsePriority: (value: string) => number;
46
+ /**
47
+ * Create an enhanced option configuration with validation
48
+ */
49
+ export interface EnhancedOption {
50
+ flags: string;
51
+ description: string;
52
+ defaultValue?: unknown;
53
+ parser?: (value: string) => unknown;
54
+ required?: boolean;
55
+ }
56
+ /**
57
+ * Common option configurations
58
+ */
59
+ export declare const COMMON_OPTIONS: {
60
+ componentName: {
61
+ flags: string;
62
+ description: string;
63
+ parser: (value: string) => string;
64
+ required: true;
65
+ };
66
+ functionName: {
67
+ flags: string;
68
+ description: string;
69
+ parser: (value: string) => string;
70
+ required: true;
71
+ };
72
+ componentSlot: {
73
+ flags: string;
74
+ description: string;
75
+ parser: (value: string) => "header" | "footer" | "sidebar" | "main" | "checkout-summary" | "payment-method" | "shipping-method" | "customer-info" | "order-confirmation";
76
+ defaultValue: string;
77
+ };
78
+ functionInvocation: {
79
+ flags: string;
80
+ description: string;
81
+ parser: (value: string) => "request" | "response";
82
+ defaultValue: string;
83
+ };
84
+ tests: {
85
+ flags: string;
86
+ description: string;
87
+ defaultValue: boolean;
88
+ };
89
+ noTests: {
90
+ flags: string;
91
+ description: string;
92
+ };
93
+ path: {
94
+ flags: string;
95
+ description: string;
96
+ parser: (value: string) => string;
97
+ };
98
+ wait: {
99
+ flags: string;
100
+ description: string;
101
+ defaultValue: boolean;
102
+ };
103
+ storeId: {
104
+ flags: string;
105
+ description: string;
106
+ parser: (value: string) => string;
107
+ required: true;
108
+ };
109
+ versionName: {
110
+ flags: string;
111
+ description: string;
112
+ parser: (value: string) => string;
113
+ required: true;
114
+ };
115
+ template: {
116
+ flags: string;
117
+ description: string;
118
+ defaultValue: string;
119
+ };
120
+ active: {
121
+ flags: string;
122
+ description: string;
123
+ defaultValue: boolean;
124
+ };
125
+ noActive: {
126
+ flags: string;
127
+ description: string;
128
+ };
129
+ force: {
130
+ flags: string;
131
+ description: string;
132
+ defaultValue: boolean;
133
+ };
134
+ watch: {
135
+ flags: string;
136
+ description: string;
137
+ defaultValue: boolean;
138
+ };
139
+ priority: {
140
+ flags: string;
141
+ description: string;
142
+ parser: (value: string) => number;
143
+ defaultValue: number;
144
+ };
145
+ };
146
+ //# sourceMappingURL=command-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-parser.d.ts","sourceRoot":"","sources":["../../src/utils/command-parser.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EACtB,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,MAAM,IAET,OAAO,MAAM,KAAG,CAAC,CAiB1B;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,UAtBd,MAAM,WA0BtB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,UA/Bb,MAAM,WAmCtB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,UAxCd,MAAM,kJA4CtB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,UAjDnB,MAAM,2BAqDtB,CAAC;AAEF;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAczD;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,UA7EL,MAAM,WA6EwC,CAAC;AAEhE;;GAEG;AACH,eAAO,MAAM,SAAS,UAlFL,MAAM,WAwFtB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,UA7FR,MAAM,WAiGtB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,UAtGZ,MAAM,WA0GtB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,MAe7C,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,cAAc;;;;wBA9IV,MAAM;;;;;;wBAAN,MAAM;;;;;;wBAAN,MAAM;;;;;;wBAAN,MAAM;;;;;;;;;;;;;;;wBAAN,MAAM;;;;;;;;;;wBAAN,MAAM;;;;;;wBAAN,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+Gc,MAAM,KAAG,MAAM;;;CAsHV,CAAC"}