@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,402 +0,0 @@
1
- import type { Command } from "@commander-js/extra-typings";
2
- import { storeFactory, versionFactory } from "@ollie-shop/core/testing";
3
- import {
4
- createTestProgram,
5
- executeCLI,
6
- resetCLIMocks,
7
- } from "@tests/helpers/cli-test-helper";
8
- import { createMockCore } from "@tests/mocks";
9
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
10
- import { registerStoreVersionCommands } from "../store-version";
11
-
12
- // Mock the version actions module
13
- vi.mock("../../actions/version.actions", () => ({
14
- create: vi.fn(),
15
- list: vi.fn(),
16
- get: vi.fn(),
17
- setDefault: vi.fn(),
18
- activate: vi.fn(),
19
- deactivate: vi.fn(),
20
- clone: vi.fn(),
21
- deleteVersion: vi.fn(),
22
- }));
23
-
24
- // Import mocked actions
25
- import * as versionActions from "../../actions/version.actions";
26
-
27
- describe("Store Version Command", () => {
28
- let program: Command;
29
- let _mockCore: ReturnType<typeof createMockCore>;
30
-
31
- beforeEach(() => {
32
- const testSetup = createTestProgram();
33
- program = testSetup.program;
34
- _mockCore = createMockCore();
35
-
36
- // Register the store-version commands
37
- registerStoreVersionCommands(program);
38
-
39
- // Reset all mocks
40
- vi.clearAllMocks();
41
- });
42
-
43
- afterEach(() => {
44
- resetCLIMocks();
45
- });
46
-
47
- describe("create subcommand", () => {
48
- it("should create a version with required options", async () => {
49
- // Arrange
50
- const newVersion = versionFactory.build({
51
- name: "test-version",
52
- template: "default",
53
- active: true,
54
- });
55
-
56
- vi.mocked(versionActions.create).mockResolvedValue(newVersion);
57
-
58
- // Act
59
- const result = await executeCLI(program, [
60
- "store-version",
61
- "create",
62
- "--store",
63
- "123e4567-e89b-12d3-a456-426614174000",
64
- "--name",
65
- "test-version",
66
- ]);
67
-
68
- // Assert
69
- expect(result.exitCode).toBe(0);
70
- expect(versionActions.create).toHaveBeenCalledWith({
71
- store: "123e4567-e89b-12d3-a456-426614174000",
72
- name: "test-version",
73
- template: "default",
74
- active: true,
75
- });
76
- });
77
-
78
- it("should create an inactive version when --no-active is specified", async () => {
79
- // Arrange
80
- const newVersion = versionFactory.build({
81
- name: "test-version",
82
- active: false,
83
- });
84
-
85
- vi.mocked(versionActions.create).mockResolvedValue(newVersion);
86
-
87
- // Act
88
- const result = await executeCLI(program, [
89
- "store-version",
90
- "create",
91
- "--store",
92
- "123e4567-e89b-12d3-a456-426614174000",
93
- "--name",
94
- "test-version",
95
- "--no-active",
96
- ]);
97
-
98
- // Assert
99
- expect(result.exitCode).toBe(0);
100
- expect(versionActions.create).toHaveBeenCalledWith({
101
- store: "123e4567-e89b-12d3-a456-426614174000",
102
- name: "test-version",
103
- template: "default",
104
- active: false,
105
- });
106
- });
107
-
108
- it("should handle validation errors for invalid store ID", async () => {
109
- // Act
110
- const result = await executeCLI(program, [
111
- "store-version",
112
- "create",
113
- "--store",
114
- "invalid-uuid",
115
- "--name",
116
- "test-version",
117
- ]);
118
-
119
- // Assert
120
- expect(result.exitCode).toBe(1);
121
- expect(versionActions.create).not.toHaveBeenCalled();
122
- });
123
-
124
- it("should handle missing required options", async () => {
125
- // Act
126
- const result = await executeCLI(program, ["store-version", "create"]);
127
-
128
- // Assert
129
- expect(result.exitCode).toBe(1);
130
- expect(versionActions.create).not.toHaveBeenCalled();
131
- });
132
- });
133
-
134
- describe("list subcommand", () => {
135
- it("should list versions for a store", async () => {
136
- // Arrange
137
- const store = storeFactory.build();
138
- const versions = [
139
- versionFactory.build({
140
- storeId: store.id,
141
- name: "Production",
142
- default: true,
143
- }),
144
- versionFactory.build({
145
- storeId: store.id,
146
- name: "Staging",
147
- default: false,
148
- }),
149
- ];
150
-
151
- vi.mocked(versionActions.list).mockResolvedValue(versions);
152
-
153
- // Act
154
- const result = await executeCLI(program, [
155
- "store-version",
156
- "list",
157
- "--store",
158
- store.id,
159
- ]);
160
-
161
- // Assert
162
- expect(result.exitCode).toBe(0);
163
- expect(versionActions.list).toHaveBeenCalledWith({
164
- store: store.id,
165
- });
166
- });
167
-
168
- it("should handle validation errors for invalid store ID", async () => {
169
- // Act
170
- const result = await executeCLI(program, [
171
- "store-version",
172
- "list",
173
- "--store",
174
- "invalid-uuid",
175
- ]);
176
-
177
- // Assert
178
- expect(result.exitCode).toBe(1);
179
- expect(versionActions.list).not.toHaveBeenCalled();
180
- });
181
- });
182
-
183
- describe("get subcommand", () => {
184
- it("should get version details by ID", async () => {
185
- // Arrange
186
- const version = versionFactory.build();
187
- vi.mocked(versionActions.get).mockResolvedValue(version);
188
-
189
- // Act
190
- const result = await executeCLI(program, [
191
- "store-version",
192
- "get",
193
- version.id,
194
- ]);
195
-
196
- // Assert
197
- expect(result.exitCode).toBe(0);
198
- expect(versionActions.get).toHaveBeenCalledWith(version.id);
199
- });
200
-
201
- it("should handle validation errors for invalid version ID", async () => {
202
- // Act
203
- const result = await executeCLI(program, [
204
- "store-version",
205
- "get",
206
- "invalid-uuid",
207
- ]);
208
-
209
- // Assert
210
- expect(result.exitCode).toBe(1);
211
- expect(versionActions.get).not.toHaveBeenCalled();
212
- });
213
- });
214
-
215
- describe("set-default subcommand", () => {
216
- it("should set a version as default", async () => {
217
- // Arrange
218
- const version = versionFactory.build();
219
- const defaultVersion = { ...version, default: true };
220
- vi.mocked(versionActions.setDefault).mockResolvedValue(defaultVersion);
221
-
222
- // Act
223
- const result = await executeCLI(program, [
224
- "store-version",
225
- "set-default",
226
- version.id,
227
- ]);
228
-
229
- // Assert
230
- expect(result.exitCode).toBe(0);
231
- expect(versionActions.setDefault).toHaveBeenCalledWith(version.id);
232
- });
233
- });
234
-
235
- describe("activate subcommand", () => {
236
- it("should activate a version", async () => {
237
- // Arrange
238
- const version = versionFactory.build({ active: false });
239
- const activeVersion = { ...version, active: true };
240
- vi.mocked(versionActions.activate).mockResolvedValue(activeVersion);
241
-
242
- // Act
243
- const result = await executeCLI(program, [
244
- "store-version",
245
- "activate",
246
- version.id,
247
- ]);
248
-
249
- // Assert
250
- expect(result.exitCode).toBe(0);
251
- expect(versionActions.activate).toHaveBeenCalledWith(version.id);
252
- });
253
- });
254
-
255
- describe("deactivate subcommand", () => {
256
- it("should deactivate a version", async () => {
257
- // Arrange
258
- const version = versionFactory.build({ active: true });
259
- const inactiveVersion = { ...version, active: false };
260
- vi.mocked(versionActions.deactivate).mockResolvedValue(inactiveVersion);
261
-
262
- // Act
263
- const result = await executeCLI(program, [
264
- "store-version",
265
- "deactivate",
266
- version.id,
267
- ]);
268
-
269
- // Assert
270
- expect(result.exitCode).toBe(0);
271
- expect(versionActions.deactivate).toHaveBeenCalledWith(version.id);
272
- });
273
- });
274
-
275
- describe("clone subcommand", () => {
276
- it("should clone a version with a new name", async () => {
277
- // Arrange
278
- const originalVersion = versionFactory.build();
279
- const clonedVersion = versionFactory.build({ name: "Cloned Version" });
280
- vi.mocked(versionActions.clone).mockResolvedValue(clonedVersion);
281
-
282
- // Act
283
- const result = await executeCLI(program, [
284
- "store-version",
285
- "clone",
286
- originalVersion.id,
287
- "--name",
288
- "Cloned Version",
289
- ]);
290
-
291
- // Assert
292
- expect(result.exitCode).toBe(0);
293
- expect(versionActions.clone).toHaveBeenCalledWith(
294
- originalVersion.id,
295
- "Cloned Version",
296
- );
297
- });
298
-
299
- it("should handle missing name option", async () => {
300
- // Arrange
301
- const version = versionFactory.build();
302
-
303
- // Act
304
- const result = await executeCLI(program, [
305
- "store-version",
306
- "clone",
307
- version.id,
308
- ]);
309
-
310
- // Assert
311
- expect(result.exitCode).toBe(1);
312
- expect(versionActions.clone).not.toHaveBeenCalled();
313
- });
314
- });
315
-
316
- describe("delete subcommand", () => {
317
- it("should delete a version", async () => {
318
- // Arrange
319
- const version = versionFactory.build();
320
- vi.mocked(versionActions.deleteVersion).mockResolvedValue(undefined);
321
-
322
- // Act
323
- const result = await executeCLI(program, [
324
- "store-version",
325
- "delete",
326
- version.id,
327
- ]);
328
-
329
- // Assert
330
- expect(result.exitCode).toBe(0);
331
- expect(versionActions.deleteVersion).toHaveBeenCalledWith(
332
- version.id,
333
- undefined,
334
- );
335
- });
336
-
337
- it("should delete a version with force flag", async () => {
338
- // Arrange
339
- const version = versionFactory.build();
340
- vi.mocked(versionActions.deleteVersion).mockResolvedValue(undefined);
341
-
342
- // Act
343
- const result = await executeCLI(program, [
344
- "store-version",
345
- "delete",
346
- version.id,
347
- "--force",
348
- ]);
349
-
350
- // Assert
351
- expect(result.exitCode).toBe(0);
352
- expect(versionActions.deleteVersion).toHaveBeenCalledWith(
353
- version.id,
354
- true,
355
- );
356
- });
357
- });
358
-
359
- describe("error handling", () => {
360
- it("should handle action errors gracefully", async () => {
361
- // Arrange
362
- const error = new Error("Version creation failed");
363
- vi.mocked(versionActions.create).mockRejectedValue(error);
364
-
365
- // Act
366
- const result = await executeCLI(program, [
367
- "store-version",
368
- "create",
369
- "--store",
370
- "123e4567-e89b-12d3-a456-426614174000",
371
- "--name",
372
- "test-version",
373
- ]);
374
-
375
- // Assert
376
- expect(result.exitCode).toBe(1);
377
- });
378
- });
379
-
380
- describe("alias support", () => {
381
- it("should work with sv alias", async () => {
382
- // Arrange
383
- const store = storeFactory.build();
384
- const versions = [versionFactory.build({ storeId: store.id })];
385
- vi.mocked(versionActions.list).mockResolvedValue(versions);
386
-
387
- // Act
388
- const result = await executeCLI(program, [
389
- "sv",
390
- "list",
391
- "--store",
392
- store.id,
393
- ]);
394
-
395
- // Assert
396
- expect(result.exitCode).toBe(0);
397
- expect(versionActions.list).toHaveBeenCalledWith({
398
- store: store.id,
399
- });
400
- });
401
- });
402
- });
@@ -1,178 +0,0 @@
1
- import type { Command } from "@commander-js/extra-typings";
2
- import * as componentActions from "../actions/component.actions";
3
- import {
4
- ComponentBuildOptionsSchema,
5
- type ComponentCreateOptions,
6
- ComponentCreateOptionsSchema,
7
- type ComponentDeployOptions,
8
- ComponentDeployOptionsSchema,
9
- ComponentValidateOptionsSchema,
10
- } from "../schemas/command.schema";
11
- import { buildCommand, buildCommandGroup } from "../utils/command-builder";
12
- import { COMMON_OPTIONS } from "../utils/command-parser";
13
-
14
- export function registerComponentCommands(program: Command): void {
15
- const cmd = buildCommandGroup(
16
- program,
17
- "component",
18
- "Manage Ollie Shop components",
19
- ["comp"],
20
- );
21
-
22
- // Create component command
23
- buildCommand(cmd, {
24
- name: "create",
25
- description: "Create a new component",
26
- options: [
27
- COMMON_OPTIONS.componentName,
28
- COMMON_OPTIONS.componentSlot,
29
- COMMON_OPTIONS.tests,
30
- COMMON_OPTIONS.noTests,
31
- {
32
- flags: "-i, --interactive",
33
- description: "Use interactive mode",
34
- defaultValue: false,
35
- },
36
- ],
37
- schema: ComponentCreateOptionsSchema,
38
- examples: [
39
- {
40
- description: "Create a header component",
41
- command: "ollieshop component create --name header --slot header",
42
- },
43
- {
44
- description: "Create a component with TypeScript",
45
- command: "ollieshop component create --name product-list --typescript",
46
- },
47
- {
48
- description: "Interactive mode",
49
- command: "ollieshop component create --interactive",
50
- },
51
- {
52
- description: "Create with tests",
53
- command: "ollieshop component create --name product-list",
54
- },
55
- ],
56
- handler: async (options, console) => {
57
- // Use interactive mode if requested
58
- if ("interactive" in options && options.interactive) {
59
- const { runInteractiveCommand } = await import(
60
- "../utils/interactive-builder.js"
61
- );
62
- await runInteractiveCommand("component-create", console);
63
- return;
64
- }
65
-
66
- await componentActions.createComponent(
67
- options as ComponentCreateOptions,
68
- console,
69
- );
70
- },
71
- });
72
-
73
- // Validate component command
74
- buildCommand(cmd, {
75
- name: "validate",
76
- description: "Validate a component",
77
- options: [COMMON_OPTIONS.path],
78
- schema: ComponentValidateOptionsSchema,
79
- examples: [
80
- {
81
- description: "Validate current directory",
82
- command: "ollieshop component validate",
83
- },
84
- {
85
- description: "Validate specific component",
86
- command: "ollieshop component validate --path ./components/header",
87
- },
88
- ],
89
- handler: async (options, console) => {
90
- await componentActions.validateComponent(
91
- {
92
- path: options.path || process.cwd(),
93
- strict: options.strict ?? false,
94
- fix: options.fix ?? false,
95
- },
96
- console,
97
- );
98
- },
99
- });
100
-
101
- // Build component command
102
- buildCommand(cmd, {
103
- name: "build",
104
- description: "Build a component",
105
- options: [COMMON_OPTIONS.path, COMMON_OPTIONS.watch],
106
- schema: ComponentBuildOptionsSchema,
107
- examples: [
108
- {
109
- description: "Build current directory",
110
- command: "ollieshop component build",
111
- },
112
- {
113
- description: "Build specific component",
114
- command: "ollieshop component build --path ./components/header",
115
- },
116
- {
117
- description: "Build with watch mode",
118
- command: "ollieshop component build --watch",
119
- },
120
- ],
121
- handler: async (options, console) => {
122
- await componentActions.buildComponent(
123
- {
124
- path: options.path || process.cwd(),
125
- watch: options.watch ?? false,
126
- },
127
- console,
128
- );
129
- },
130
- });
131
-
132
- // Deploy component command
133
- buildCommand(cmd, {
134
- name: "deploy",
135
- description: "Deploy a component",
136
- options: [
137
- {
138
- flags: "--id <id>",
139
- description: "Component ID",
140
- required: true,
141
- },
142
- COMMON_OPTIONS.path,
143
- ],
144
- schema: ComponentDeployOptionsSchema,
145
- examples: [
146
- {
147
- description: "Deploy a component",
148
- command: "ollieshop component deploy --id comp-123",
149
- },
150
- ],
151
- handler: async (options: ComponentDeployOptions, console) => {
152
- // Map id to componentId if provided
153
- const deployOptions = {
154
- path: options.path,
155
- componentId: options.id || options.componentId,
156
- };
157
- await componentActions.deployComponent(deployOptions, console);
158
- },
159
- });
160
-
161
- // List components command
162
- buildCommand(cmd, {
163
- name: "list",
164
- description: "List all components",
165
- aliases: ["ls"],
166
- examples: [
167
- {
168
- description: "List all components",
169
- command: "ollieshop component list",
170
- },
171
- ],
172
- handler: async (_, console) => {
173
- await componentActions.listComponents(console);
174
- },
175
- });
176
-
177
- // Add more commands as needed
178
- }
@@ -1,24 +0,0 @@
1
- import type { Command } from "@commander-js/extra-typings";
2
- import { console as cliConsole } from "../utils/console";
3
-
4
- export function configureDocsCommand(program: Command): void {
5
- program
6
- .command("docs")
7
- .description("Show documentation links for Ollie Shop")
8
- .action(() => {
9
- cliConsole.info("Ollie Shop Documentation\n");
10
-
11
- cliConsole.info(
12
- `${"Main Docs:".padEnd(20)} https://docs.ollie.shop/ollie-shop`,
13
- );
14
- cliConsole.info(
15
- `${"Components:".padEnd(20)} https://docs.ollie.shop/ollie-shop/concepts/component`,
16
- );
17
- cliConsole.info(
18
- `${"Functions:".padEnd(20)} https://docs.ollie.shop/ollie-shop/concepts/function`,
19
- );
20
- cliConsole.info(
21
- `${"Versions:".padEnd(20)} https://docs.ollie.shop/ollie-shop/concepts/version\n`,
22
- );
23
- });
24
- }