@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,318 +0,0 @@
1
- import type { Command } from "@commander-js/extra-typings";
2
- import {
3
- createTestProgram,
4
- executeCLI,
5
- resetCLIMocks,
6
- } from "@tests/helpers/cli-test-helper";
7
- import { createMockCore } from "@tests/mocks";
8
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
9
- import { registerComponentCommands } from "../component";
10
-
11
- // Mock the component actions module
12
- vi.mock("../../actions/component.actions", () => ({
13
- createComponent: vi.fn(),
14
- listComponents: vi.fn(),
15
- deployComponent: vi.fn(),
16
- validateComponent: vi.fn(),
17
- }));
18
-
19
- // Import mocked actions
20
- import * as componentActions from "../../actions/component.actions";
21
-
22
- describe("Component Command", () => {
23
- let program: Command;
24
-
25
- beforeEach(() => {
26
- const testSetup = createTestProgram();
27
- program = testSetup.program;
28
- createMockCore();
29
-
30
- // Register the component commands
31
- registerComponentCommands(program);
32
-
33
- // Reset all mocks
34
- vi.clearAllMocks();
35
- });
36
-
37
- afterEach(() => {
38
- resetCLIMocks();
39
- });
40
-
41
- describe("list subcommand", () => {
42
- it("should list components successfully", async () => {
43
- // Arrange
44
- const components = [
45
- { id: "1", name: "Header", slot: "header", active: true },
46
- { id: "2", name: "Footer", slot: "footer", active: false },
47
- ];
48
- vi.mocked(componentActions.listComponents).mockResolvedValue(components);
49
-
50
- // Act
51
- const result = await executeCLI(program, ["component", "list"]);
52
-
53
- // Assert
54
- expect(result.exitCode).toBe(0);
55
- expect(componentActions.listComponents).toHaveBeenCalled();
56
- });
57
-
58
- it("should handle list errors gracefully", async () => {
59
- // Arrange
60
- const error = new Error("Failed to fetch components");
61
- vi.mocked(componentActions.listComponents).mockRejectedValue(error);
62
-
63
- // Act
64
- const result = await executeCLI(program, ["component", "list"]);
65
-
66
- // Assert
67
- expect(result.exitCode).toBe(1);
68
- });
69
- });
70
-
71
- describe("create subcommand", () => {
72
- it("should create component with options", async () => {
73
- // Arrange
74
- vi.mocked(componentActions.createComponent).mockResolvedValue();
75
-
76
- // Act
77
- const result = await executeCLI(program, [
78
- "component",
79
- "create",
80
- "--name",
81
- "my-component",
82
- "--slot",
83
- "header",
84
- ]);
85
-
86
- // Assert
87
- expect(result.exitCode).toBe(0);
88
- expect(componentActions.createComponent).toHaveBeenCalledWith(
89
- expect.objectContaining({
90
- name: "my-component",
91
- slot: "header",
92
- tests: true,
93
- interactive: false,
94
- }),
95
- expect.any(Object), // console object
96
- );
97
- });
98
-
99
- it("should create component with default values", async () => {
100
- // Arrange
101
- vi.mocked(componentActions.createComponent).mockResolvedValue();
102
-
103
- // Act
104
- const result = await executeCLI(program, [
105
- "component",
106
- "create",
107
- "--name",
108
- "my-component",
109
- ]);
110
-
111
- // Assert
112
- expect(result.exitCode).toBe(0);
113
- expect(componentActions.createComponent).toHaveBeenCalledWith(
114
- expect.objectContaining({
115
- name: "my-component",
116
- slot: "main",
117
- tests: true,
118
- interactive: false,
119
- }),
120
- expect.any(Object),
121
- );
122
- });
123
-
124
- it("should validate component name format - reject uppercase", async () => {
125
- // Act
126
- const result = await executeCLI(program, [
127
- "component",
128
- "create",
129
- "--name",
130
- "Test",
131
- "--slot",
132
- "header",
133
- ]);
134
-
135
- // Assert
136
- expect(result.exitCode).toBe(1);
137
- expect(componentActions.createComponent).not.toHaveBeenCalled();
138
- });
139
-
140
- it("should validate component name format - reject spaces", async () => {
141
- // Act
142
- const result = await executeCLI(program, [
143
- "component",
144
- "create",
145
- "--name",
146
- "test component",
147
- "--slot",
148
- "header",
149
- ]);
150
-
151
- // Assert
152
- expect(result.exitCode).toBe(1);
153
- expect(componentActions.createComponent).not.toHaveBeenCalled();
154
- });
155
-
156
- it("should validate component name format - accept valid kebab-case", async () => {
157
- // Arrange
158
- vi.mocked(componentActions.createComponent).mockResolvedValue();
159
-
160
- // Act
161
- const result = await executeCLI(program, [
162
- "component",
163
- "create",
164
- "--name",
165
- "test-component",
166
- "--slot",
167
- "header",
168
- ]);
169
-
170
- // Assert
171
- expect(result.exitCode).toBe(0);
172
- expect(componentActions.createComponent).toHaveBeenCalledWith(
173
- expect.objectContaining({
174
- name: "test-component",
175
- slot: "header",
176
- }),
177
- expect.any(Object),
178
- );
179
- });
180
-
181
- it("should require component name", async () => {
182
- // Act
183
- const result = await executeCLI(program, [
184
- "component",
185
- "create",
186
- "--slot",
187
- "header",
188
- ]);
189
-
190
- // Assert
191
- expect(result.exitCode).toBe(1);
192
- expect(componentActions.createComponent).not.toHaveBeenCalled();
193
- });
194
-
195
- it("should handle action errors", async () => {
196
- // Arrange
197
- const error = new Error("Creation failed");
198
- vi.mocked(componentActions.createComponent).mockRejectedValue(error);
199
-
200
- // Act
201
- const result = await executeCLI(program, [
202
- "component",
203
- "create",
204
- "--name",
205
- "test-component",
206
- ]);
207
-
208
- // Assert
209
- expect(result.exitCode).toBe(1);
210
- });
211
- });
212
-
213
- describe("deploy subcommand", () => {
214
- it("should deploy a component by path", async () => {
215
- // Arrange
216
- vi.mocked(componentActions.deployComponent).mockResolvedValue();
217
-
218
- // Act
219
- const result = await executeCLI(program, [
220
- "component",
221
- "deploy",
222
- "--path",
223
- "./my-component",
224
- "--id",
225
- "123e4567-e89b-12d3-a456-426614174000",
226
- ]);
227
-
228
- // Assert
229
- expect(result.exitCode).toBe(0);
230
- expect(componentActions.deployComponent).toHaveBeenCalledWith(
231
- expect.objectContaining({
232
- path: "./my-component",
233
- componentId: "123e4567-e89b-12d3-a456-426614174000",
234
- }),
235
- expect.any(Object),
236
- );
237
- });
238
-
239
- it("should deploy a component by ID", async () => {
240
- // Arrange
241
- vi.mocked(componentActions.deployComponent).mockResolvedValue();
242
-
243
- // Act
244
- const result = await executeCLI(program, [
245
- "component",
246
- "deploy",
247
- "--id",
248
- "123e4567-e89b-12d3-a456-426614174000",
249
- ]);
250
-
251
- // Assert
252
- expect(result.exitCode).toBe(0);
253
- expect(componentActions.deployComponent).toHaveBeenCalledWith(
254
- expect.objectContaining({
255
- componentId: "123e4567-e89b-12d3-a456-426614174000",
256
- }),
257
- expect.any(Object),
258
- );
259
- });
260
- });
261
-
262
- describe("validate subcommand", () => {
263
- it("should validate a component at path", async () => {
264
- // Arrange
265
- vi.mocked(componentActions.validateComponent).mockResolvedValue();
266
-
267
- // Act
268
- const result = await executeCLI(program, [
269
- "component",
270
- "validate",
271
- "--path",
272
- "./my-component",
273
- ]);
274
-
275
- // Assert
276
- expect(result.exitCode).toBe(0);
277
- expect(componentActions.validateComponent).toHaveBeenCalledWith(
278
- expect.objectContaining({
279
- path: "./my-component",
280
- }),
281
- expect.any(Object),
282
- );
283
- });
284
- });
285
-
286
- describe("error handling", () => {
287
- it("should handle validation errors gracefully", async () => {
288
- // Arrange
289
- const error = new Error("Validation failed");
290
- vi.mocked(componentActions.validateComponent).mockRejectedValue(error);
291
-
292
- // Act
293
- const result = await executeCLI(program, [
294
- "component",
295
- "validate",
296
- "--path",
297
- "./my-component",
298
- ]);
299
-
300
- // Assert
301
- expect(result.exitCode).toBe(1);
302
- });
303
- });
304
-
305
- describe("alias support", () => {
306
- it("should work with comp alias", async () => {
307
- // Arrange
308
- vi.mocked(componentActions.listComponents).mockResolvedValue();
309
-
310
- // Act
311
- const result = await executeCLI(program, ["comp", "list"]);
312
-
313
- // Assert
314
- expect(result.exitCode).toBe(0);
315
- expect(componentActions.listComponents).toHaveBeenCalled();
316
- });
317
- });
318
- });
@@ -1,220 +0,0 @@
1
- import type { Command } from "@commander-js/extra-typings";
2
- import {
3
- createTestProgram,
4
- executeCLI,
5
- resetCLIMocks,
6
- } from "@tests/helpers/cli-test-helper";
7
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
8
- import { registerFunctionCommands } from "../function";
9
-
10
- // Mock the function actions module
11
- vi.mock("../../actions/function.actions", () => ({
12
- createFunction: vi.fn(),
13
- listFunctions: vi.fn(),
14
- deployFunction: vi.fn(),
15
- validateFunction: vi.fn(),
16
- testFunction: vi.fn(),
17
- }));
18
-
19
- import * as functionActions from "../../actions/function.actions";
20
-
21
- describe("Function Command Validation and DX", () => {
22
- let program: Command;
23
- let testSetup: ReturnType<typeof createTestProgram>;
24
-
25
- beforeEach(() => {
26
- testSetup = createTestProgram();
27
- program = testSetup.program;
28
- registerFunctionCommands(program);
29
- vi.clearAllMocks();
30
- });
31
-
32
- afterEach(() => {
33
- resetCLIMocks();
34
- });
35
-
36
- describe("name validation", () => {
37
- it("should reject uppercase function names", async () => {
38
- const result = await executeCLI(program, [
39
- "function",
40
- "create",
41
- "--name",
42
- "ValidateOrder",
43
- ]);
44
-
45
- const consoleOutput = testSetup.mocks.console.error.mock.calls
46
- .map((call) => call.join(" "))
47
- .join("\n");
48
-
49
- expect(result.exitCode).toBe(1);
50
- expect(consoleOutput).toContain("Validation failed");
51
- expect(consoleOutput).toContain("Must be lowercase with hyphens only");
52
- expect(functionActions.createFunction).not.toHaveBeenCalled();
53
- });
54
-
55
- it("should reject function names with spaces", async () => {
56
- const result = await executeCLI(program, [
57
- "function",
58
- "create",
59
- "--name",
60
- "validate order",
61
- ]);
62
-
63
- const consoleOutput = testSetup.mocks.console.error.mock.calls
64
- .map((call) => call.join(" "))
65
- .join("\n");
66
-
67
- expect(result.exitCode).toBe(1);
68
- expect(consoleOutput).toContain("Validation failed");
69
- expect(functionActions.createFunction).not.toHaveBeenCalled();
70
- });
71
-
72
- it("should reject function names with underscores", async () => {
73
- const result = await executeCLI(program, [
74
- "function",
75
- "create",
76
- "--name",
77
- "validate_order",
78
- ]);
79
-
80
- const consoleOutput = testSetup.mocks.console.error.mock.calls
81
- .map((call) => call.join(" "))
82
- .join("\n");
83
-
84
- expect(result.exitCode).toBe(1);
85
- expect(consoleOutput).toContain("Validation failed");
86
- expect(functionActions.createFunction).not.toHaveBeenCalled();
87
- });
88
-
89
- it("should require function name", async () => {
90
- const result = await executeCLI(program, [
91
- "function",
92
- "create",
93
- "--event",
94
- "cart",
95
- ]);
96
-
97
- expect(result.exitCode).toBe(1);
98
- expect(functionActions.createFunction).not.toHaveBeenCalled();
99
- });
100
-
101
- it("should accept valid kebab-case names", async () => {
102
- vi.mocked(functionActions.createFunction).mockResolvedValue();
103
-
104
- const result = await executeCLI(program, [
105
- "function",
106
- "create",
107
- "--name",
108
- "validate-order",
109
- ]);
110
-
111
- expect(result.exitCode).toBe(0);
112
- expect(functionActions.createFunction).toHaveBeenCalledWith(
113
- expect.objectContaining({
114
- name: "validate-order",
115
- }),
116
- expect.any(Object),
117
- );
118
- });
119
-
120
- it("should accept names with numbers", async () => {
121
- vi.mocked(functionActions.createFunction).mockResolvedValue();
122
-
123
- const result = await executeCLI(program, [
124
- "function",
125
- "create",
126
- "--name",
127
- "validate-order-v2",
128
- ]);
129
-
130
- expect(result.exitCode).toBe(0);
131
- expect(functionActions.createFunction).toHaveBeenCalledWith(
132
- expect.objectContaining({
133
- name: "validate-order-v2",
134
- }),
135
- expect.any(Object),
136
- );
137
- });
138
- });
139
-
140
- describe("invocation validation", () => {
141
- it("should reject invalid invocation types", async () => {
142
- const result = await executeCLI(program, [
143
- "function",
144
- "create",
145
- "--name",
146
- "test-func",
147
- "--invocation",
148
- "invalid",
149
- ]);
150
-
151
- expect(result.exitCode).toBe(1);
152
- expect(result.stderr.join("")).toContain("Invalid function invocation");
153
- expect(result.stderr.join("")).toContain(
154
- "Valid invocations: request, response",
155
- );
156
- expect(functionActions.createFunction).not.toHaveBeenCalled();
157
- });
158
-
159
- it("should accept all valid invocation types", async () => {
160
- vi.mocked(functionActions.createFunction).mockResolvedValue();
161
-
162
- const validInvocations = ["request", "response"];
163
-
164
- for (const invocation of validInvocations) {
165
- vi.clearAllMocks();
166
-
167
- const result = await executeCLI(program, [
168
- "function",
169
- "create",
170
- "--name",
171
- "test-func",
172
- "--invocation",
173
- invocation,
174
- ]);
175
-
176
- expect(result.exitCode).toBe(0);
177
- expect(functionActions.createFunction).toHaveBeenCalledWith(
178
- expect.objectContaining({
179
- invocation,
180
- }),
181
- expect.any(Object),
182
- );
183
- }
184
- });
185
- });
186
-
187
- describe("help command", () => {
188
- it("should show examples in help output", async () => {
189
- const result = await executeCLI(program, [
190
- "function",
191
- "create",
192
- "--help",
193
- ]);
194
-
195
- const output = result.stdout.join("") + result.stderr.join("");
196
- expect(output).toContain("Examples:");
197
- expect(output).toContain("Create a function to validate orders:");
198
- expect(output).toContain(
199
- "$ ollieshop function create --name validate-order --event order --timing before",
200
- );
201
- expect(output).toContain("Create a discount function for cart:");
202
- expect(output).toContain("Create a JavaScript function without tests:");
203
- });
204
- });
205
-
206
- describe("unknown options", () => {
207
- it("should provide helpful error for unknown options", async () => {
208
- const result = await executeCLI(program, [
209
- "function",
210
- "create",
211
- "--name",
212
- "test",
213
- "--unknown",
214
- ]);
215
-
216
- expect(result.exitCode).toBe(1);
217
- expect(result.stderr.join("")).toContain("unknown option '--unknown'");
218
- });
219
- });
220
- });