@ollie-shop/cli 0.1.3 → 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 (181) hide show
  1. package/.turbo/turbo-build.log +2 -11
  2. package/CHANGELOG.md +17 -5
  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 +93 -226
  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 +44 -9
  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 +24 -0
  140. package/src/commands/function.ts +252 -0
  141. package/src/commands/help.ts +18 -0
  142. package/src/commands/index.ts +21 -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 +51 -0
  147. package/src/commands/whoami.ts +46 -0
  148. package/src/index.ts +110 -15
  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 +41 -0
  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/store.ts +23 -0
  176. package/src/utils/validation-error-formatter.ts +337 -0
  177. package/src/utils/validation-helpers.ts +192 -0
  178. package/tsconfig.json +13 -7
  179. package/vitest.config.ts +28 -0
  180. package/vitest.setup.ts +29 -0
  181. package/tsup.config.ts +0 -15
@@ -0,0 +1,192 @@
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
+ export interface ValidationResult {
13
+ valid: boolean;
14
+ errors?: Array<{ message?: string } | string>;
15
+ warnings?: Array<{ message?: string } | string>;
16
+ }
17
+
18
+ export interface SpinnerManager {
19
+ succeed: (text: string) => void;
20
+ fail: (text: string) => void;
21
+ }
22
+
23
+ /**
24
+ * Validate component name format using Zod schema
25
+ */
26
+ export function validateComponentName(name: string): true | string {
27
+ const result = ComponentNameSchema.safeParse(name);
28
+ return result.success
29
+ ? true
30
+ : result.error.errors[0]?.message || "Invalid component name";
31
+ }
32
+
33
+ /**
34
+ * Validate function name format using Zod schema
35
+ */
36
+ export function validateFunctionName(name: string): true | string {
37
+ const result = FunctionNameSchema.safeParse(name);
38
+ return result.success
39
+ ? true
40
+ : result.error.errors[0]?.message || "Invalid function name";
41
+ }
42
+
43
+ /**
44
+ * Validate store ID format using Zod schema
45
+ */
46
+ export function validateStoreId(storeId: string): true | string {
47
+ const result = StoreIdSchema.safeParse(storeId);
48
+ return result.success
49
+ ? true
50
+ : result.error.errors[0]?.message || "Invalid store ID";
51
+ }
52
+
53
+ /**
54
+ * Validate version name using Zod schema
55
+ */
56
+ export function validateVersionName(name: string): true | string {
57
+ const result = VersionNameSchema.safeParse(name);
58
+ return result.success
59
+ ? true
60
+ : result.error.errors[0]?.message || "Invalid version name";
61
+ }
62
+
63
+ /**
64
+ * Validate priority value using Zod schema
65
+ */
66
+ export function validatePriority(priority: number): true | string {
67
+ const result = PrioritySchema.safeParse(priority);
68
+ return result.success
69
+ ? true
70
+ : result.error.errors[0]?.message || "Invalid priority";
71
+ }
72
+
73
+ /**
74
+ * Validate URL or URL pattern using Zod schema
75
+ */
76
+ export function validateUrl(url: string): true | string {
77
+ const result = UrlSchema.safeParse(url);
78
+ return result.success
79
+ ? true
80
+ : result.error.errors[0]?.message || "Invalid URL";
81
+ }
82
+
83
+ /**
84
+ * Validate semantic version using Zod schema
85
+ */
86
+ export function validateSemver(version: string): true | string {
87
+ const result = SemverSchema.safeParse(version);
88
+ return result.success
89
+ ? true
90
+ : result.error.errors[0]?.message || "Invalid semantic version";
91
+ }
92
+
93
+ /**
94
+ * Process validation errors and display them to the user
95
+ */
96
+ export function processValidationErrors(
97
+ errors: Array<{ message?: string } | string>,
98
+ cliConsole: CliConsole,
99
+ ): void {
100
+ cliConsole.error("Errors:");
101
+ for (const error of errors) {
102
+ const message = typeof error === "string" ? error : error.message || error;
103
+ cliConsole.error(`• ${message}`);
104
+ }
105
+ }
106
+
107
+ /**
108
+ * Process validation warnings and display them to the user
109
+ */
110
+ export function processValidationWarnings(
111
+ warnings: Array<{ message?: string } | string>,
112
+ cliConsole: CliConsole,
113
+ ): void {
114
+ cliConsole.warn("Warnings:");
115
+ for (const warning of warnings) {
116
+ const message =
117
+ typeof warning === "string" ? warning : warning.message || warning;
118
+ cliConsole.warn(`• ${message}`);
119
+ }
120
+ }
121
+
122
+ /**
123
+ * Handle validation result with spinner and console output
124
+ */
125
+ export function handleValidationResult(
126
+ result: ValidationResult | unknown,
127
+ spinner: SpinnerManager,
128
+ cliConsole: CliConsole,
129
+ entityType: string,
130
+ ): void {
131
+ if (typeof result === "object" && result !== null && "valid" in result) {
132
+ const validationResult = result as ValidationResult;
133
+
134
+ handleValidResult(validationResult, spinner, cliConsole, entityType);
135
+ handleValidationWarnings(validationResult, cliConsole);
136
+ handleValidationErrors(validationResult);
137
+ } else {
138
+ spinner.succeed(`${entityType} validation completed`);
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Handle valid/invalid validation status
144
+ */
145
+ function handleValidResult(
146
+ result: ValidationResult,
147
+ spinner: SpinnerManager,
148
+ cliConsole: CliConsole,
149
+ entityType: string,
150
+ ): void {
151
+ if (result.valid) {
152
+ spinner.succeed(`${entityType} is valid!`);
153
+ } else {
154
+ spinner.fail(`${entityType} validation failed`);
155
+ if (result.errors?.length) {
156
+ processValidationErrors(result.errors, cliConsole);
157
+ }
158
+ }
159
+ }
160
+
161
+ /**
162
+ * Handle validation warnings display
163
+ */
164
+ function handleValidationWarnings(
165
+ result: ValidationResult,
166
+ cliConsole: CliConsole,
167
+ ): void {
168
+ if (result.warnings?.length) {
169
+ processValidationWarnings(result.warnings, cliConsole);
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Handle validation errors and throw if invalid
175
+ */
176
+ function handleValidationErrors(result: ValidationResult): void {
177
+ if (!result.valid) {
178
+ throw new Error("Validation failed");
179
+ }
180
+ }
181
+
182
+ // Test helpers for mocking
183
+ export function createMockSpinner(): SpinnerManager {
184
+ return {
185
+ succeed: () => {
186
+ // Mock spinner success - intentionally empty
187
+ },
188
+ fail: () => {
189
+ // Mock spinner failure - intentionally empty
190
+ },
191
+ };
192
+ }
package/tsconfig.json CHANGED
@@ -1,20 +1,26 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "lib": ["ESNext", "DOM"],
4
- "module": "ESNext",
5
- "target": "ESNext",
6
- "moduleResolution": "Bundler",
3
+ "lib": ["ESNext"],
4
+ "module": "Node16",
5
+ "target": "ES2020",
6
+ "moduleResolution": "Node16",
7
7
  "jsx": "react-jsx",
8
8
  "strict": true,
9
9
  "declaration": true,
10
+ "declarationMap": true,
10
11
  "noUncheckedIndexedAccess": true,
11
12
  "skipLibCheck": true,
12
13
  "esModuleInterop": true,
14
+ "allowSyntheticDefaultImports": true,
13
15
  "resolveJsonModule": true,
14
- "types": ["node", "vitest/globals"],
16
+ "outDir": "dist",
17
+ "rootDir": "src",
18
+ "isolatedModules": true,
15
19
  "paths": {
16
- "@/*": ["./src/*"]
20
+ "@/*": ["./src/*"],
21
+ "@tests/*": ["./src/__tests__/*"]
17
22
  }
18
23
  },
19
- "exclude": ["node_modules", "dist"]
24
+ "include": ["src/**/*"],
25
+ "exclude": ["node_modules", "dist", "**/*.test.ts"]
20
26
  }
package/vitest.config.ts CHANGED
@@ -1,7 +1,35 @@
1
+ import path from "node:path";
1
2
  import { defineConfig } from "vitest/config";
2
3
 
3
4
  export default defineConfig({
4
5
  test: {
5
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
+ },
6
34
  },
7
35
  });
@@ -0,0 +1,29 @@
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
+ });
package/tsup.config.ts DELETED
@@ -1,15 +0,0 @@
1
- import { defineConfig } from "tsup";
2
-
3
- export default defineConfig({
4
- entry: ["./src/index.ts"],
5
- bundle: true,
6
- splitting: false,
7
- minify: false,
8
- sourcemap: false,
9
- platform: "node",
10
- format: "cjs",
11
- clean: true,
12
- treeshake: true,
13
- dts: false,
14
- banner: { js: "#!/usr/bin/env node" },
15
- });