@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,22 @@
1
+ import { vi } from "vitest";
2
+
3
+ export const createMockConsole = () => ({
4
+ setOptions: vi.fn(),
5
+ hint: vi.fn(),
6
+ info: vi.fn(),
7
+ success: vi.fn(),
8
+ error: vi.fn(),
9
+ warn: vi.fn(),
10
+ debug: vi.fn(),
11
+ dim: vi.fn(),
12
+ spinner: vi.fn(() => ({
13
+ start: vi.fn().mockReturnThis(),
14
+ succeed: vi.fn().mockReturnThis(),
15
+ fail: vi.fn().mockReturnThis(),
16
+ warn: vi.fn().mockReturnThis(),
17
+ stop: vi.fn().mockReturnThis(),
18
+ text: "",
19
+ })),
20
+ });
21
+
22
+ export const mockConsole = createMockConsole();
@@ -0,0 +1,137 @@
1
+ import { faker } from "@faker-js/faker";
2
+ import {
3
+ componentFactory,
4
+ functionFactory,
5
+ versionFactory,
6
+ } from "@ollie-shop/core/__tests__/factories";
7
+ import { vi } from "vitest";
8
+
9
+ // Mock the services from core
10
+ export const createMockCore = () => {
11
+ // Component service functions
12
+ const componentService = {
13
+ createComponent: vi.fn(),
14
+ listComponents: vi.fn(),
15
+ getComponent: vi.fn(),
16
+ deployComponent: vi.fn(),
17
+ buildComponent: vi.fn(),
18
+ validateComponent: vi.fn(),
19
+ enableComponent: vi.fn(),
20
+ disableComponent: vi.fn(),
21
+ updateComponent: vi.fn(),
22
+ getComponentMeta: vi.fn(),
23
+ updateComponentMeta: vi.fn(),
24
+ };
25
+
26
+ // Function service functions
27
+ const functionService = {
28
+ createFunction: vi.fn(),
29
+ listFunctions: vi.fn(),
30
+ deployFunction: vi.fn(),
31
+ buildFunction: vi.fn(),
32
+ validateFunction: vi.fn(),
33
+ testFunction: vi.fn(),
34
+ getFunctionMeta: vi.fn(),
35
+ updateFunctionMeta: vi.fn(),
36
+ };
37
+
38
+ // Version service functions
39
+ const versionService = {
40
+ createVersion: vi.fn(),
41
+ listVersions: vi.fn(),
42
+ getVersion: vi.fn(),
43
+ updateVersion: vi.fn(),
44
+ deleteVersion: vi.fn(),
45
+ setDefaultVersion: vi.fn(),
46
+ activateVersion: vi.fn(),
47
+ deactivateVersion: vi.fn(),
48
+ cloneVersion: vi.fn(),
49
+ };
50
+
51
+ // Setup default behaviors
52
+ componentService.createComponent.mockImplementation(
53
+ async (path, _options) => {
54
+ return { success: true, path };
55
+ },
56
+ );
57
+
58
+ componentService.listComponents.mockResolvedValue(
59
+ componentFactory.buildList(3),
60
+ );
61
+
62
+ componentService.deployComponent.mockImplementation(async (id, _path) => {
63
+ return componentFactory.build({
64
+ id,
65
+ url: faker.internet.url(),
66
+ active: true,
67
+ });
68
+ });
69
+
70
+ componentService.buildComponent.mockImplementation(async (path) => ({
71
+ success: true,
72
+ outputPath: `${path}/dist`,
73
+ size: faker.number.int({ min: 1000, max: 100000 }),
74
+ duration: faker.number.int({ min: 100, max: 5000 }),
75
+ }));
76
+
77
+ componentService.validateComponent.mockImplementation(async (_path) => ({
78
+ valid: true,
79
+ errors: [],
80
+ warnings: [],
81
+ }));
82
+
83
+ functionService.createFunction.mockImplementation(async (path, _options) => {
84
+ return { success: true, path };
85
+ });
86
+
87
+ functionService.listFunctions.mockResolvedValue(functionFactory.buildList(2));
88
+
89
+ functionService.deployFunction.mockImplementation(async (id, _path) => {
90
+ return functionFactory.build({
91
+ id,
92
+ urn: `arn:aws:lambda:us-east-1:${faker.string.numeric(12)}:function:deployed`,
93
+ active: true,
94
+ });
95
+ });
96
+
97
+ functionService.buildFunction.mockImplementation(async (path) => ({
98
+ success: true,
99
+ outputPath: `${path}/dist`,
100
+ size: faker.number.int({ min: 1000, max: 50000 }),
101
+ duration: faker.number.int({ min: 100, max: 3000 }),
102
+ }));
103
+
104
+ functionService.validateFunction.mockImplementation(async (_path) => ({
105
+ valid: true,
106
+ errors: [],
107
+ warnings: [],
108
+ }));
109
+
110
+ functionService.testFunction.mockImplementation(async (_path, _payload) => ({
111
+ success: true,
112
+ output: { message: "Test successful" },
113
+ logs: ["Function executed successfully"],
114
+ duration: faker.number.int({ min: 10, max: 500 }),
115
+ }));
116
+
117
+ versionService.createVersion.mockImplementation(async (data) =>
118
+ versionFactory.build({ ...data, id: faker.string.uuid() }),
119
+ );
120
+
121
+ versionService.listVersions.mockResolvedValue(versionFactory.buildList(2));
122
+
123
+ versionService.setDefaultVersion.mockImplementation(async (id) =>
124
+ versionFactory.build({ id, default: true }),
125
+ );
126
+
127
+ return {
128
+ componentService,
129
+ functionService,
130
+ versionService,
131
+ };
132
+ };
133
+
134
+ // Export individual mocks
135
+ export const mockComponentService = createMockCore().componentService;
136
+ export const mockFunctionService = createMockCore().functionService;
137
+ export const mockVersionService = createMockCore().versionService;
@@ -0,0 +1,4 @@
1
+ export * from "./core";
2
+ export * from "./console";
3
+ export * from "./inquirer";
4
+ export * from "./progress";
@@ -0,0 +1,16 @@
1
+ import { vi } from "vitest";
2
+
3
+ export const createMockInquirer = () => ({
4
+ prompt: vi.fn().mockResolvedValue({
5
+ name: "test-name",
6
+ slot: "header",
7
+ template: "default",
8
+ typescript: true,
9
+ includeTests: true,
10
+ includeStyles: true,
11
+ confirm: true,
12
+ }),
13
+ registerPrompt: vi.fn(),
14
+ });
15
+
16
+ export const mockInquirer = createMockInquirer();
@@ -0,0 +1,19 @@
1
+ import { vi } from "vitest";
2
+
3
+ export const createMockProgressBar = () => ({
4
+ start: vi.fn(),
5
+ increment: vi.fn(),
6
+ update: vi.fn(),
7
+ stop: vi.fn(),
8
+ });
9
+
10
+ export const mockProgressBar = createMockProgressBar();
11
+
12
+ export const createMockCliProgress = () => ({
13
+ SingleBar: vi.fn(() => mockProgressBar),
14
+ Presets: {
15
+ shades_classic: {},
16
+ },
17
+ });
18
+
19
+ export const mockCliProgress = createMockCliProgress();
@@ -0,0 +1,89 @@
1
+ import { Command } from "@commander-js/extra-typings";
2
+ import { vi } from "vitest";
3
+ /**
4
+ * CLI Testing Helper for Commander.js applications
5
+ * Based on best practices for testing CLI applications with Vitest
6
+ */
7
+ export interface CLITestResult {
8
+ exitCode: number;
9
+ stdout: string[];
10
+ stderr: string[];
11
+ error?: Error;
12
+ }
13
+ export interface ProcessMocks {
14
+ exit: ReturnType<typeof vi.fn>;
15
+ stdout: {
16
+ write: ReturnType<typeof vi.fn>;
17
+ };
18
+ stderr: {
19
+ write: ReturnType<typeof vi.fn>;
20
+ };
21
+ }
22
+ export interface ConsoleMocks {
23
+ log: ReturnType<typeof vi.fn>;
24
+ error: ReturnType<typeof vi.fn>;
25
+ warn: ReturnType<typeof vi.fn>;
26
+ info: ReturnType<typeof vi.fn>;
27
+ }
28
+ /**
29
+ * Create a test-friendly Commander.js program that captures output
30
+ * and prevents process.exit from terminating the test
31
+ */
32
+ export declare function createTestProgram(): {
33
+ program: Command;
34
+ mocks: {
35
+ process: ProcessMocks;
36
+ console: ConsoleMocks;
37
+ };
38
+ getResult: () => CLITestResult;
39
+ };
40
+ /**
41
+ * Execute a CLI command with arguments and capture the result
42
+ */
43
+ export declare function executeCLI(program: Command, args: string[], options?: {
44
+ from: "node" | "electron" | "user";
45
+ }): Promise<CLITestResult>;
46
+ /**
47
+ * Reset all CLI test mocks between tests
48
+ */
49
+ export declare function resetCLIMocks(): void;
50
+ /**
51
+ * Create mock for inquirer prompts
52
+ */
53
+ export declare function createInquirerMock(responses: Record<string, unknown>): {
54
+ prompt: import("vitest").Mock<(...args: any[]) => any>;
55
+ };
56
+ /**
57
+ * Create mock for ora spinner
58
+ */
59
+ export declare function createSpinnerMock(): {
60
+ mock: {
61
+ start: import("vitest").Mock<(...args: any[]) => any>;
62
+ stop: import("vitest").Mock<(...args: any[]) => any>;
63
+ succeed: import("vitest").Mock<(...args: any[]) => any>;
64
+ fail: import("vitest").Mock<(...args: any[]) => any>;
65
+ warn: import("vitest").Mock<(...args: any[]) => any>;
66
+ info: import("vitest").Mock<(...args: any[]) => any>;
67
+ text: string;
68
+ isSpinning: boolean;
69
+ };
70
+ create: import("vitest").Mock<() => {
71
+ start: import("vitest").Mock<(...args: any[]) => any>;
72
+ stop: import("vitest").Mock<(...args: any[]) => any>;
73
+ succeed: import("vitest").Mock<(...args: any[]) => any>;
74
+ fail: import("vitest").Mock<(...args: any[]) => any>;
75
+ warn: import("vitest").Mock<(...args: any[]) => any>;
76
+ info: import("vitest").Mock<(...args: any[]) => any>;
77
+ text: string;
78
+ isSpinning: boolean;
79
+ }>;
80
+ };
81
+ /**
82
+ * Assert CLI output contains expected text
83
+ */
84
+ export declare function expectCLIOutput(result: CLITestResult, expected: {
85
+ stdout?: string | RegExp;
86
+ stderr?: string | RegExp;
87
+ exitCode?: number;
88
+ }): void;
89
+ //# sourceMappingURL=cli-test-helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-test-helper.d.ts","sourceRoot":"","sources":["../../../src/__tests__/helpers/cli-test-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,EAAU,EAAE,EAAE,M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I,IAAI,CAGpC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;EAgBpE;AAED;;GAEG;AACH,wBAAgB,iBAAiB;;;;;;;;;;;;;;;;;;;;;EAgBhC;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE;IACR,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,QAuBF"}
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTestProgram = createTestProgram;
4
+ exports.executeCLI = executeCLI;
5
+ exports.resetCLIMocks = resetCLIMocks;
6
+ exports.createInquirerMock = createInquirerMock;
7
+ exports.createSpinnerMock = createSpinnerMock;
8
+ exports.expectCLIOutput = expectCLIOutput;
9
+ const extra_typings_1 = require("@commander-js/extra-typings");
10
+ const vitest_1 = require("vitest");
11
+ /**
12
+ * Create a test-friendly Commander.js program that captures output
13
+ * and prevents process.exit from terminating the test
14
+ */
15
+ function createTestProgram() {
16
+ const stdout = [];
17
+ const stderr = [];
18
+ let exitCode = 0;
19
+ let capturedError;
20
+ // Mock process methods
21
+ const processMocks = {
22
+ exit: vitest_1.vi.fn((code = 0) => {
23
+ exitCode = code;
24
+ // Throw error instead of exiting to prevent test termination
25
+ throw new Error(`process.exit(${code})`);
26
+ }),
27
+ stdout: {
28
+ write: vitest_1.vi.fn((data) => {
29
+ stdout.push(data);
30
+ return true;
31
+ }),
32
+ },
33
+ stderr: {
34
+ write: vitest_1.vi.fn((data) => {
35
+ stderr.push(data);
36
+ return true;
37
+ }),
38
+ },
39
+ };
40
+ // Mock console methods
41
+ const consoleMocks = {
42
+ log: vitest_1.vi.fn((...args) => {
43
+ stdout.push(`${args.join(" ")}\n`);
44
+ }),
45
+ error: vitest_1.vi.fn((...args) => {
46
+ stderr.push(`${args.join(" ")}\n`);
47
+ }),
48
+ warn: vitest_1.vi.fn((...args) => {
49
+ stderr.push(`${args.join(" ")}\n`);
50
+ }),
51
+ info: vitest_1.vi.fn((...args) => {
52
+ stdout.push(`${args.join(" ")}\n`);
53
+ }),
54
+ };
55
+ // Apply mocks
56
+ vitest_1.vi.spyOn(process, "exit").mockImplementation(((code) => {
57
+ throw new Error(`Process exit with code ${code}`);
58
+ }));
59
+ vitest_1.vi.spyOn(process.stdout, "write").mockImplementation(processMocks.stdout.write);
60
+ vitest_1.vi.spyOn(process.stderr, "write").mockImplementation(processMocks.stderr.write);
61
+ vitest_1.vi.spyOn(console, "log").mockImplementation(consoleMocks.log);
62
+ vitest_1.vi.spyOn(console, "error").mockImplementation(consoleMocks.error);
63
+ vitest_1.vi.spyOn(console, "warn").mockImplementation(consoleMocks.warn);
64
+ vitest_1.vi.spyOn(console, "info").mockImplementation(consoleMocks.info);
65
+ // Also mock global.console which is used by the CLI console utility
66
+ vitest_1.vi.spyOn(global.console, "log").mockImplementation(consoleMocks.log);
67
+ vitest_1.vi.spyOn(global.console, "error").mockImplementation(consoleMocks.error);
68
+ vitest_1.vi.spyOn(global.console, "warn").mockImplementation(consoleMocks.warn);
69
+ vitest_1.vi.spyOn(global.console, "info").mockImplementation(consoleMocks.info);
70
+ // Create program with exitOverride to handle errors gracefully
71
+ const program = new extra_typings_1.Command();
72
+ program
73
+ .exitOverride((err) => {
74
+ capturedError = err;
75
+ exitCode = err.exitCode || 1;
76
+ throw err;
77
+ })
78
+ .configureOutput({
79
+ writeOut: (str) => {
80
+ stdout.push(str);
81
+ },
82
+ writeErr: (str) => {
83
+ stderr.push(str);
84
+ },
85
+ });
86
+ const getResult = () => ({
87
+ exitCode,
88
+ stdout: [...stdout],
89
+ stderr: [...stderr],
90
+ error: capturedError,
91
+ });
92
+ return {
93
+ program,
94
+ mocks: {
95
+ process: processMocks,
96
+ console: consoleMocks,
97
+ },
98
+ getResult,
99
+ };
100
+ }
101
+ /**
102
+ * Execute a CLI command with arguments and capture the result
103
+ */
104
+ async function executeCLI(program, args, options = { from: "user" }) {
105
+ const stdout = [];
106
+ const stderr = [];
107
+ let exitCode = 0;
108
+ let capturedError;
109
+ // Capture output
110
+ const originalWriteOut = program.configureOutput().writeOut;
111
+ const originalWriteErr = program.configureOutput().writeErr;
112
+ program.configureOutput({
113
+ writeOut: (str) => {
114
+ stdout.push(str);
115
+ if (originalWriteOut)
116
+ originalWriteOut(str);
117
+ },
118
+ writeErr: (str) => {
119
+ stderr.push(str);
120
+ if (originalWriteErr)
121
+ originalWriteErr(str);
122
+ },
123
+ });
124
+ try {
125
+ await program.parseAsync(args, options);
126
+ }
127
+ catch (error) {
128
+ capturedError = error;
129
+ // Handle Commander.js specific errors
130
+ if (error && typeof error === "object" && "code" in error) {
131
+ const commanderError = error;
132
+ exitCode = commanderError.exitCode || 1;
133
+ }
134
+ else if (error instanceof Error &&
135
+ error.message.includes("process.exit")) {
136
+ // Handle our mocked process.exit
137
+ const match = error.message.match(/process\.exit\((\d+)\)/);
138
+ exitCode = match?.[1] ? Number.parseInt(match[1], 10) : 1;
139
+ }
140
+ else {
141
+ exitCode = 1;
142
+ }
143
+ }
144
+ return {
145
+ exitCode,
146
+ stdout,
147
+ stderr,
148
+ error: capturedError,
149
+ };
150
+ }
151
+ /**
152
+ * Reset all CLI test mocks between tests
153
+ */
154
+ function resetCLIMocks() {
155
+ vitest_1.vi.clearAllMocks();
156
+ vitest_1.vi.restoreAllMocks();
157
+ }
158
+ /**
159
+ * Create mock for inquirer prompts
160
+ */
161
+ function createInquirerMock(responses) {
162
+ return {
163
+ prompt: vitest_1.vi
164
+ .fn()
165
+ .mockImplementation((questions) => {
166
+ const answers = {};
167
+ for (const question of questions) {
168
+ if (question.name && responses[question.name] !== undefined) {
169
+ answers[question.name] = responses[question.name];
170
+ }
171
+ }
172
+ return Promise.resolve(answers);
173
+ }),
174
+ };
175
+ }
176
+ /**
177
+ * Create mock for ora spinner
178
+ */
179
+ function createSpinnerMock() {
180
+ const mock = {
181
+ start: vitest_1.vi.fn().mockReturnThis(),
182
+ stop: vitest_1.vi.fn().mockReturnThis(),
183
+ succeed: vitest_1.vi.fn().mockReturnThis(),
184
+ fail: vitest_1.vi.fn().mockReturnThis(),
185
+ warn: vitest_1.vi.fn().mockReturnThis(),
186
+ info: vitest_1.vi.fn().mockReturnThis(),
187
+ text: "",
188
+ isSpinning: false,
189
+ };
190
+ return {
191
+ mock,
192
+ create: vitest_1.vi.fn(() => mock),
193
+ };
194
+ }
195
+ /**
196
+ * Assert CLI output contains expected text
197
+ */
198
+ function expectCLIOutput(result, expected) {
199
+ if (expected.exitCode !== undefined) {
200
+ (0, vitest_1.expect)(result.exitCode).toBe(expected.exitCode);
201
+ }
202
+ if (expected.stdout !== undefined) {
203
+ const stdoutText = result.stdout.join("");
204
+ if (typeof expected.stdout === "string") {
205
+ (0, vitest_1.expect)(stdoutText).toContain(expected.stdout);
206
+ }
207
+ else {
208
+ (0, vitest_1.expect)(stdoutText).toMatch(expected.stdout);
209
+ }
210
+ }
211
+ if (expected.stderr !== undefined) {
212
+ const stderrText = result.stderr.join("");
213
+ if (typeof expected.stderr === "string") {
214
+ (0, vitest_1.expect)(stderrText).toContain(expected.stderr);
215
+ }
216
+ else {
217
+ (0, vitest_1.expect)(stderrText).toMatch(expected.stderr);
218
+ }
219
+ }
220
+ }
@@ -0,0 +1,69 @@
1
+ import { vi } from "vitest";
2
+ export interface MockConsole {
3
+ success: ReturnType<typeof vi.fn>;
4
+ error: ReturnType<typeof vi.fn>;
5
+ info: ReturnType<typeof vi.fn>;
6
+ warn: ReturnType<typeof vi.fn>;
7
+ hint: ReturnType<typeof vi.fn>;
8
+ spinner: ReturnType<typeof vi.fn>;
9
+ log: ReturnType<typeof vi.fn>;
10
+ dim: ReturnType<typeof vi.fn>;
11
+ }
12
+ export interface MockInquirer {
13
+ prompt: ReturnType<typeof vi.fn>;
14
+ select: ReturnType<typeof vi.fn>;
15
+ input: ReturnType<typeof vi.fn>;
16
+ confirm: ReturnType<typeof vi.fn>;
17
+ }
18
+ export interface MockSpinner {
19
+ succeed: ReturnType<typeof vi.fn>;
20
+ fail: ReturnType<typeof vi.fn>;
21
+ start: ReturnType<typeof vi.fn>;
22
+ stop: ReturnType<typeof vi.fn>;
23
+ }
24
+ export interface MockCore {
25
+ listComponents: ReturnType<typeof vi.fn>;
26
+ createComponent: ReturnType<typeof vi.fn>;
27
+ deployComponent: ReturnType<typeof vi.fn>;
28
+ deleteComponent: ReturnType<typeof vi.fn>;
29
+ listFunctions: ReturnType<typeof vi.fn>;
30
+ createFunction: ReturnType<typeof vi.fn>;
31
+ deployFunction: ReturnType<typeof vi.fn>;
32
+ deleteFunction: ReturnType<typeof vi.fn>;
33
+ listVersions: ReturnType<typeof vi.fn>;
34
+ createVersion: ReturnType<typeof vi.fn>;
35
+ setDefaultVersion: ReturnType<typeof vi.fn>;
36
+ deleteVersion: ReturnType<typeof vi.fn>;
37
+ }
38
+ export declare function createMockConsole(): MockConsole;
39
+ export declare function createMockInquirer(): MockInquirer;
40
+ export declare function createMockSpinner(): MockSpinner;
41
+ export declare function createMockCore(): MockCore & {
42
+ versionService: {
43
+ list: ReturnType<typeof vi.fn>;
44
+ create: ReturnType<typeof vi.fn>;
45
+ setDefault: ReturnType<typeof vi.fn>;
46
+ delete: ReturnType<typeof vi.fn>;
47
+ clone: ReturnType<typeof vi.fn>;
48
+ activate: ReturnType<typeof vi.fn>;
49
+ deactivate: ReturnType<typeof vi.fn>;
50
+ };
51
+ projectService: {
52
+ getProjectInfo: ReturnType<typeof vi.fn>;
53
+ };
54
+ componentService: {
55
+ list: ReturnType<typeof vi.fn>;
56
+ create: ReturnType<typeof vi.fn>;
57
+ deploy: ReturnType<typeof vi.fn>;
58
+ delete: ReturnType<typeof vi.fn>;
59
+ };
60
+ functionService: {
61
+ list: ReturnType<typeof vi.fn>;
62
+ create: ReturnType<typeof vi.fn>;
63
+ deploy: ReturnType<typeof vi.fn>;
64
+ delete: ReturnType<typeof vi.fn>;
65
+ update: ReturnType<typeof vi.fn>;
66
+ test: ReturnType<typeof vi.fn>;
67
+ };
68
+ };
69
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/__tests__/mocks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE5B,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IAClC,KAAK,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IAChC,IAAI,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IAC/B,IAAI,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IAC/B,IAAI,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IAC/B,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IAClC,GAAG,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IAC9B,GAAG,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IACjC,MAAM,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IACjC,KAAK,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IAChC,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,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EAAE,CAAC,CAAC;QACjC,IAAI,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;KAChC,CAAC;CACH,CAyCA"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createMockConsole = createMockConsole;
4
+ exports.createMockInquirer = createMockInquirer;
5
+ exports.createMockSpinner = createMockSpinner;
6
+ exports.createMockCore = createMockCore;
7
+ const vitest_1 = require("vitest");
8
+ function createMockConsole() {
9
+ return {
10
+ success: vitest_1.vi.fn(),
11
+ error: vitest_1.vi.fn(),
12
+ info: vitest_1.vi.fn(),
13
+ warn: vitest_1.vi.fn(),
14
+ hint: vitest_1.vi.fn(),
15
+ spinner: vitest_1.vi.fn(() => createMockSpinner()),
16
+ log: vitest_1.vi.fn(),
17
+ dim: vitest_1.vi.fn(),
18
+ };
19
+ }
20
+ function createMockInquirer() {
21
+ return {
22
+ prompt: vitest_1.vi.fn(),
23
+ select: vitest_1.vi.fn(),
24
+ input: vitest_1.vi.fn(),
25
+ confirm: vitest_1.vi.fn(),
26
+ };
27
+ }
28
+ function createMockSpinner() {
29
+ return {
30
+ succeed: vitest_1.vi.fn(),
31
+ fail: vitest_1.vi.fn(),
32
+ start: vitest_1.vi.fn(),
33
+ stop: vitest_1.vi.fn(),
34
+ };
35
+ }
36
+ function createMockCore() {
37
+ return {
38
+ listComponents: vitest_1.vi.fn(),
39
+ createComponent: vitest_1.vi.fn(),
40
+ deployComponent: vitest_1.vi.fn(),
41
+ deleteComponent: vitest_1.vi.fn(),
42
+ listFunctions: vitest_1.vi.fn(),
43
+ createFunction: vitest_1.vi.fn(),
44
+ deployFunction: vitest_1.vi.fn(),
45
+ deleteFunction: vitest_1.vi.fn(),
46
+ listVersions: vitest_1.vi.fn(),
47
+ createVersion: vitest_1.vi.fn(),
48
+ setDefaultVersion: vitest_1.vi.fn(),
49
+ deleteVersion: vitest_1.vi.fn(),
50
+ versionService: {
51
+ list: vitest_1.vi.fn(),
52
+ create: vitest_1.vi.fn(),
53
+ setDefault: vitest_1.vi.fn(),
54
+ delete: vitest_1.vi.fn(),
55
+ clone: vitest_1.vi.fn(),
56
+ activate: vitest_1.vi.fn(),
57
+ deactivate: vitest_1.vi.fn(),
58
+ },
59
+ projectService: {
60
+ getProjectInfo: vitest_1.vi.fn(),
61
+ },
62
+ componentService: {
63
+ list: vitest_1.vi.fn(),
64
+ create: vitest_1.vi.fn(),
65
+ deploy: vitest_1.vi.fn(),
66
+ delete: vitest_1.vi.fn(),
67
+ },
68
+ functionService: {
69
+ list: vitest_1.vi.fn(),
70
+ create: vitest_1.vi.fn(),
71
+ deploy: vitest_1.vi.fn(),
72
+ delete: vitest_1.vi.fn(),
73
+ update: vitest_1.vi.fn(),
74
+ test: vitest_1.vi.fn(),
75
+ },
76
+ };
77
+ }
@@ -0,0 +1,14 @@
1
+ import type { ComponentCreateOptions, ComponentDeployOptions, ComponentValidateOptions } from "../schemas/command.schema";
2
+ import type { CliConsole } from "../utils/console";
3
+ export declare function createComponent(options: ComponentCreateOptions, cliConsole: CliConsole): Promise<void>;
4
+ export declare function validateComponent(options: ComponentValidateOptions, cliConsole: CliConsole): Promise<void>;
5
+ export declare function buildComponent(options: {
6
+ path?: string;
7
+ watch?: boolean;
8
+ }, cliConsole: CliConsole): Promise<void>;
9
+ export declare function deployComponent(options: ComponentDeployOptions & {
10
+ wait?: boolean;
11
+ }, cliConsole: CliConsole): Promise<void>;
12
+ export declare function checkDeployStatus(buildId: string, cliConsole: CliConsole): Promise<void>;
13
+ export declare function listComponents(cliConsole: CliConsole): Promise<void>;
14
+ //# sourceMappingURL=component.actions.d.ts.map