@ollie-shop/cli 0.3.4 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/.turbo/turbo-build.log +6 -9
  2. package/CHANGELOG.md +27 -0
  3. package/dist/index.js +993 -3956
  4. package/package.json +15 -37
  5. package/src/README.md +126 -0
  6. package/src/cli.tsx +45 -0
  7. package/src/commands/help.tsx +79 -0
  8. package/src/commands/login.tsx +92 -0
  9. package/src/commands/start.tsx +411 -0
  10. package/src/index.tsx +8 -0
  11. package/src/utils/auth.ts +218 -21
  12. package/src/utils/bundle.ts +177 -0
  13. package/src/utils/config.ts +123 -0
  14. package/src/utils/esbuild.ts +541 -0
  15. package/tsconfig.json +10 -15
  16. package/tsup.config.ts +7 -7
  17. package/CLAUDE_CLI.md +0 -265
  18. package/README.md +0 -711
  19. package/__tests__/mocks/console.ts +0 -22
  20. package/__tests__/mocks/core.ts +0 -137
  21. package/__tests__/mocks/index.ts +0 -4
  22. package/__tests__/mocks/inquirer.ts +0 -16
  23. package/__tests__/mocks/progress.ts +0 -19
  24. package/dist/index.d.ts +0 -1
  25. package/src/__tests__/helpers/cli-test-helper.ts +0 -281
  26. package/src/__tests__/mocks/index.ts +0 -142
  27. package/src/actions/component.actions.ts +0 -278
  28. package/src/actions/function.actions.ts +0 -220
  29. package/src/actions/project.actions.ts +0 -131
  30. package/src/actions/version.actions.ts +0 -233
  31. package/src/commands/__tests__/component-validation.test.ts +0 -250
  32. package/src/commands/__tests__/component.test.ts +0 -318
  33. package/src/commands/__tests__/function-validation.test.ts +0 -220
  34. package/src/commands/__tests__/function.test.ts +0 -286
  35. package/src/commands/__tests__/store-version-validation.test.ts +0 -414
  36. package/src/commands/__tests__/store-version.test.ts +0 -402
  37. package/src/commands/component.ts +0 -178
  38. package/src/commands/docs.ts +0 -24
  39. package/src/commands/function.ts +0 -201
  40. package/src/commands/help.ts +0 -18
  41. package/src/commands/index.ts +0 -27
  42. package/src/commands/login.ts +0 -267
  43. package/src/commands/project.ts +0 -107
  44. package/src/commands/store-version.ts +0 -242
  45. package/src/commands/version.ts +0 -51
  46. package/src/commands/whoami.ts +0 -46
  47. package/src/index.ts +0 -116
  48. package/src/prompts/component.prompts.ts +0 -94
  49. package/src/prompts/function.prompts.ts +0 -168
  50. package/src/schemas/command.schema.ts +0 -644
  51. package/src/types/index.ts +0 -183
  52. package/src/utils/__tests__/command-parser.test.ts +0 -159
  53. package/src/utils/__tests__/command-suggestions.test.ts +0 -185
  54. package/src/utils/__tests__/console.test.ts +0 -192
  55. package/src/utils/__tests__/context-detector.test.ts +0 -258
  56. package/src/utils/__tests__/enhanced-error-handler.test.ts +0 -137
  57. package/src/utils/__tests__/error-handler.test.ts +0 -107
  58. package/src/utils/__tests__/rich-progress.test.ts +0 -181
  59. package/src/utils/__tests__/validation-error-formatter.test.ts +0 -175
  60. package/src/utils/__tests__/validation-helpers.test.ts +0 -125
  61. package/src/utils/cli-progress-reporter.ts +0 -84
  62. package/src/utils/command-builder.ts +0 -390
  63. package/src/utils/command-helpers.ts +0 -83
  64. package/src/utils/command-parser.ts +0 -245
  65. package/src/utils/command-suggestions.ts +0 -176
  66. package/src/utils/console.ts +0 -320
  67. package/src/utils/constants.ts +0 -39
  68. package/src/utils/context-detector.ts +0 -177
  69. package/src/utils/deploy-helpers.ts +0 -357
  70. package/src/utils/enhanced-error-handler.ts +0 -264
  71. package/src/utils/error-handler.ts +0 -60
  72. package/src/utils/errors.ts +0 -256
  73. package/src/utils/interactive-builder.ts +0 -325
  74. package/src/utils/rich-progress.ts +0 -331
  75. package/src/utils/store.ts +0 -23
  76. package/src/utils/validation-error-formatter.ts +0 -337
  77. package/src/utils/validation-helpers.ts +0 -325
  78. package/vitest.config.ts +0 -35
  79. package/vitest.setup.ts +0 -29
@@ -1,325 +0,0 @@
1
- import {
2
- ComponentNameSchema,
3
- FunctionNameSchema,
4
- PrioritySchema,
5
- SemverSchema,
6
- StoreIdSchema,
7
- UrlSchema,
8
- VersionNameSchema,
9
- } from "../schemas/command.schema";
10
- import type { CliConsole } from "./console";
11
-
12
- /**
13
- * Result of a validation operation
14
- * @interface ValidationResult
15
- * @property {boolean} valid - Whether the validation passed
16
- * @property {Array<{message?: string} | string>} [errors] - List of validation errors
17
- * @property {Array<{message?: string} | string>} [warnings] - List of validation warnings
18
- */
19
- export interface ValidationResult {
20
- valid: boolean;
21
- errors?: Array<{ message?: string } | string>;
22
- warnings?: Array<{ message?: string } | string>;
23
- }
24
-
25
- /**
26
- * Interface for managing spinner states
27
- * @interface SpinnerManager
28
- * @property {Function} succeed - Mark spinner as successful with message
29
- * @property {Function} fail - Mark spinner as failed with message
30
- */
31
- export interface SpinnerManager {
32
- succeed: (text: string) => void;
33
- fail: (text: string) => void;
34
- }
35
-
36
- /**
37
- * Validates a component name against naming conventions
38
- * Component names must be lowercase, use hyphens, and follow kebab-case
39
- *
40
- * @param {string} name - The component name to validate
41
- * @returns {true | string} Returns true if valid, or an error message string if invalid
42
- * @example
43
- * ```typescript
44
- * validateComponentName("my-header") // returns true
45
- * validateComponentName("MyHeader") // returns "Component name must be lowercase"
46
- * validateComponentName("my_header") // returns "Use hyphens instead of underscores"
47
- * ```
48
- */
49
- export function validateComponentName(name: string): true | string {
50
- const result = ComponentNameSchema.safeParse(name);
51
- return result.success
52
- ? true
53
- : result.error.errors[0]?.message || "Invalid component name";
54
- }
55
-
56
- /**
57
- * Validates a function name against naming conventions
58
- * Function names must be lowercase, use hyphens, and follow kebab-case
59
- *
60
- * @param {string} name - The function name to validate
61
- * @returns {true | string} Returns true if valid, or an error message string if invalid
62
- * @example
63
- * ```typescript
64
- * validateFunctionName("validate-cart") // returns true
65
- * validateFunctionName("validateCart") // returns "Function name must be lowercase"
66
- * validateFunctionName("validate cart") // returns "No spaces allowed in function names"
67
- * ```
68
- */
69
- export function validateFunctionName(name: string): true | string {
70
- const result = FunctionNameSchema.safeParse(name);
71
- return result.success
72
- ? true
73
- : result.error.errors[0]?.message || "Invalid function name";
74
- }
75
-
76
- /**
77
- * Validates a store ID is in proper UUID v4 format
78
- *
79
- * @param {string} storeId - The store ID to validate
80
- * @returns {true | string} Returns true if valid UUID, or an error message if invalid
81
- * @example
82
- * ```typescript
83
- * validateStoreId("123e4567-e89b-12d3-a456-426614174000") // returns true
84
- * validateStoreId("invalid-id") // returns "Invalid store ID format"
85
- * ```
86
- */
87
- export function validateStoreId(storeId: string): true | string {
88
- const result = StoreIdSchema.safeParse(storeId);
89
- return result.success
90
- ? true
91
- : result.error.errors[0]?.message || "Invalid store ID";
92
- }
93
-
94
- /**
95
- * Validates a version name meets requirements
96
- * Version names must be 1-100 characters long
97
- *
98
- * @param {string} name - The version name to validate
99
- * @returns {true | string} Returns true if valid, or an error message if invalid
100
- * @example
101
- * ```typescript
102
- * validateVersionName("Production v2.0") // returns true
103
- * validateVersionName("") // returns "Version name is required"
104
- * validateVersionName("a".repeat(101)) // returns "Version name is too long (max 100 characters)"
105
- * ```
106
- */
107
- export function validateVersionName(name: string): true | string {
108
- const result = VersionNameSchema.safeParse(name);
109
- return result.success
110
- ? true
111
- : result.error.errors[0]?.message || "Invalid version name";
112
- }
113
-
114
- /**
115
- * Validates a priority value is within acceptable range
116
- * Priority must be an integer between 0 and 100 (inclusive)
117
- *
118
- * @param {number} priority - The priority value to validate
119
- * @returns {true | string} Returns true if valid, or an error message if invalid
120
- * @example
121
- * ```typescript
122
- * validatePriority(50) // returns true
123
- * validatePriority(0) // returns true (minimum)
124
- * validatePriority(100) // returns true (maximum)
125
- * validatePriority(150) // returns "Priority must be between 0 and 100"
126
- * validatePriority(50.5) // returns "Priority must be a whole number"
127
- * ```
128
- */
129
- export function validatePriority(priority: number): true | string {
130
- const result = PrioritySchema.safeParse(priority);
131
- return result.success
132
- ? true
133
- : result.error.errors[0]?.message || "Invalid priority";
134
- }
135
-
136
- /**
137
- * Validates a URL or URL pattern for functions
138
- * Supports both full URLs (http/https) and path patterns (e.g., /api/*)
139
- *
140
- * @param {string} url - The URL or pattern to validate
141
- * @returns {true | string} Returns true if valid, or an error message if invalid
142
- * @example
143
- * ```typescript
144
- * validateUrl("https://api.example.com/webhook") // returns true
145
- * validateUrl("/api/cart/*") // returns true (path pattern)
146
- * validateUrl("/*") // returns true (wildcard pattern)
147
- * validateUrl("ftp://example.com") // returns "URL must be a valid URL or path pattern"
148
- * validateUrl("") // returns "URL is required"
149
- * ```
150
- */
151
- export function validateUrl(url: string): true | string {
152
- const result = UrlSchema.safeParse(url);
153
- return result.success
154
- ? true
155
- : result.error.errors[0]?.message || "Invalid URL";
156
- }
157
-
158
- /**
159
- * Validates a semantic version string
160
- * Must follow semver format: MAJOR.MINOR.PATCH (e.g., 1.0.0)
161
- *
162
- * @param {string} version - The version string to validate
163
- * @returns {true | string} Returns true if valid semver, or an error message if invalid
164
- * @example
165
- * ```typescript
166
- * validateSemver("1.0.0") // returns true
167
- * validateSemver("2.4.6") // returns true
168
- * validateSemver("1.0") // returns "Version must follow semantic versioning format (e.g., 1.0.0)"
169
- * validateSemver("v1.0.0") // returns "Version must follow semantic versioning format (e.g., 1.0.0)"
170
- * ```
171
- */
172
- export function validateSemver(version: string): true | string {
173
- const result = SemverSchema.safeParse(version);
174
- return result.success
175
- ? true
176
- : result.error.errors[0]?.message || "Invalid semantic version";
177
- }
178
-
179
- /**
180
- * Processes and displays validation errors to the user
181
- * Formats errors into a readable list with bullet points
182
- *
183
- * @param {Array<{message?: string} | string>} errors - Array of error objects or strings
184
- * @param {CliConsole} cliConsole - Console instance for output
185
- * @example
186
- * ```typescript
187
- * processValidationErrors(["Invalid name", {message: "Path not found"}], console);
188
- * // Output:
189
- * // Errors:
190
- * // • Invalid name
191
- * // • Path not found
192
- * ```
193
- */
194
- export function processValidationErrors(
195
- errors: Array<{ message?: string } | string>,
196
- cliConsole: CliConsole,
197
- ): void {
198
- cliConsole.error("Errors:");
199
- for (const error of errors) {
200
- const message = typeof error === "string" ? error : error.message || error;
201
- cliConsole.error(`• ${message}`);
202
- }
203
- }
204
-
205
- /**
206
- * Processes and displays validation warnings to the user
207
- * Formats warnings into a readable list with bullet points
208
- *
209
- * @param {Array<{message?: string} | string>} warnings - Array of warning objects or strings
210
- * @param {CliConsole} cliConsole - Console instance for output
211
- * @example
212
- * ```typescript
213
- * processValidationWarnings(["Deprecated feature used"], console);
214
- * // Output:
215
- * // Warnings:
216
- * // • Deprecated feature used
217
- * ```
218
- */
219
- export function processValidationWarnings(
220
- warnings: Array<{ message?: string } | string>,
221
- cliConsole: CliConsole,
222
- ): void {
223
- cliConsole.warn("Warnings:");
224
- for (const warning of warnings) {
225
- const message =
226
- typeof warning === "string" ? warning : warning.message || warning;
227
- cliConsole.warn(`• ${message}`);
228
- }
229
- }
230
-
231
- /**
232
- * Handles validation results by updating spinner state and displaying errors/warnings
233
- * Central function for processing validation outcomes in CLI commands
234
- *
235
- * @param {ValidationResult | unknown} result - Validation result object or unknown type
236
- * @param {SpinnerManager} spinner - Spinner instance to update visual feedback
237
- * @param {CliConsole} cliConsole - Console instance for output
238
- * @param {string} entityType - Type of entity being validated (e.g., "Component", "Function")
239
- * @example
240
- * ```typescript
241
- * const result = await validateComponent(path);
242
- * handleValidationResult(result, spinner, console, "Component");
243
- * // Updates spinner to success/fail and displays any errors or warnings
244
- * ```
245
- */
246
- export function handleValidationResult(
247
- result: ValidationResult | unknown,
248
- spinner: SpinnerManager,
249
- cliConsole: CliConsole,
250
- entityType: string,
251
- ): void {
252
- if (typeof result === "object" && result !== null && "valid" in result) {
253
- const validationResult = result as ValidationResult;
254
-
255
- handleValidResult(validationResult, spinner, cliConsole, entityType);
256
- handleValidationWarnings(validationResult, cliConsole);
257
- handleValidationErrors(validationResult);
258
- } else {
259
- spinner.succeed(`${entityType} validation completed`);
260
- }
261
- }
262
-
263
- /**
264
- * Updates spinner state based on validation success/failure
265
- * Internal helper for handleValidationResult
266
- *
267
- * @param {ValidationResult} result - Validation result with valid status
268
- * @param {SpinnerManager} spinner - Spinner to update
269
- * @param {CliConsole} cliConsole - Console for error output
270
- * @param {string} entityType - Type of entity for messaging
271
- * @private
272
- */
273
- function handleValidResult(
274
- result: ValidationResult,
275
- spinner: SpinnerManager,
276
- cliConsole: CliConsole,
277
- entityType: string,
278
- ): void {
279
- if (result.valid) {
280
- spinner.succeed(`${entityType} is valid!`);
281
- } else {
282
- spinner.fail(`${entityType} validation failed`);
283
- if (result.errors?.length) {
284
- processValidationErrors(result.errors, cliConsole);
285
- }
286
- }
287
- }
288
-
289
- /**
290
- * Displays validation warnings if present
291
- * Internal helper for handleValidationResult
292
- *
293
- * @param {ValidationResult} result - Validation result potentially containing warnings
294
- * @param {CliConsole} cliConsole - Console for warning output
295
- * @private
296
- */
297
- function handleValidationWarnings(
298
- result: ValidationResult,
299
- cliConsole: CliConsole,
300
- ): void {
301
- if (result.warnings?.length) {
302
- processValidationWarnings(result.warnings, cliConsole);
303
- }
304
- }
305
-
306
- /**
307
- * Handle validation errors and throw if invalid
308
- */
309
- function handleValidationErrors(result: ValidationResult): void {
310
- if (!result.valid) {
311
- throw new Error("Validation failed");
312
- }
313
- }
314
-
315
- // Test helpers for mocking
316
- export function createMockSpinner(): SpinnerManager {
317
- return {
318
- succeed: () => {
319
- // Mock spinner success - intentionally empty
320
- },
321
- fail: () => {
322
- // Mock spinner failure - intentionally empty
323
- },
324
- };
325
- }
package/vitest.config.ts DELETED
@@ -1,35 +0,0 @@
1
- import path from "node:path";
2
- import { defineConfig } from "vitest/config";
3
-
4
- export default defineConfig({
5
- test: {
6
- globals: true,
7
- environment: "node",
8
- exclude: ["**/node_modules/**", "**/dist/**", "**/components/**"],
9
- include: ["src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
10
- coverage: {
11
- provider: "v8",
12
- reporter: ["text", "json", "html"],
13
- exclude: [
14
- "node_modules/",
15
- "dist/",
16
- "**/*.d.ts",
17
- "**/*.config.ts",
18
- "**/__tests__/**",
19
- ],
20
- thresholds: {
21
- lines: 80,
22
- functions: 80,
23
- branches: 80,
24
- statements: 80,
25
- },
26
- },
27
- setupFiles: ["./vitest.setup.ts"],
28
- },
29
- resolve: {
30
- alias: {
31
- "@": path.resolve(__dirname, "./src"),
32
- "@tests": path.resolve(__dirname, "./src/__tests__"),
33
- },
34
- },
35
- });
package/vitest.setup.ts DELETED
@@ -1,29 +0,0 @@
1
- import { vi } from "vitest";
2
-
3
- // Mock console methods
4
- global.console = {
5
- ...console,
6
- log: vi.fn(),
7
- debug: vi.fn(),
8
- info: vi.fn(),
9
- warn: vi.fn(),
10
- error: vi.fn(),
11
- };
12
-
13
- // Mock process.exit
14
- vi.spyOn(process, "exit").mockImplementation((code?: string | number) => {
15
- throw new Error(`process.exit called with code ${code}`);
16
- });
17
-
18
- // Set test environment
19
- process.env.NODE_ENV = "test";
20
- process.env.OLLIE_SHOP_CONFIG_DIR = "/tmp/ollie-shop-test";
21
-
22
- // Global test utilities
23
- beforeEach(() => {
24
- vi.clearAllMocks();
25
- });
26
-
27
- afterEach(() => {
28
- vi.restoreAllMocks();
29
- });