@ollie-shop/cli 0.3.0 → 0.3.2

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 (124) hide show
  1. package/.turbo/turbo-build.log +14 -2
  2. package/CHANGELOG.md +13 -0
  3. package/__tests__/mocks/core.ts +1 -1
  4. package/dist/index.d.ts +0 -2
  5. package/dist/index.js +40574 -75
  6. package/package.json +7 -6
  7. package/src/actions/component.actions.ts +31 -0
  8. package/src/actions/function.actions.ts +34 -0
  9. package/src/actions/project.actions.ts +6 -2
  10. package/src/commands/__tests__/store-version.test.ts +1 -4
  11. package/tsup.config.ts +15 -0
  12. package/dist/__tests__/helpers/cli-test-helper.d.ts +0 -89
  13. package/dist/__tests__/helpers/cli-test-helper.d.ts.map +0 -1
  14. package/dist/__tests__/helpers/cli-test-helper.js +0 -220
  15. package/dist/__tests__/mocks/index.d.ts +0 -69
  16. package/dist/__tests__/mocks/index.d.ts.map +0 -1
  17. package/dist/__tests__/mocks/index.js +0 -77
  18. package/dist/actions/component.actions.d.ts +0 -14
  19. package/dist/actions/component.actions.d.ts.map +0 -1
  20. package/dist/actions/component.actions.js +0 -273
  21. package/dist/actions/function.actions.d.ts +0 -15
  22. package/dist/actions/function.actions.d.ts.map +0 -1
  23. package/dist/actions/function.actions.js +0 -254
  24. package/dist/actions/project.actions.d.ts +0 -17
  25. package/dist/actions/project.actions.d.ts.map +0 -1
  26. package/dist/actions/project.actions.js +0 -97
  27. package/dist/actions/version.actions.d.ts +0 -19
  28. package/dist/actions/version.actions.d.ts.map +0 -1
  29. package/dist/actions/version.actions.js +0 -216
  30. package/dist/commands/component.d.ts +0 -3
  31. package/dist/commands/component.d.ts.map +0 -1
  32. package/dist/commands/component.js +0 -192
  33. package/dist/commands/docs.d.ts +0 -3
  34. package/dist/commands/docs.d.ts.map +0 -1
  35. package/dist/commands/docs.js +0 -16
  36. package/dist/commands/function.d.ts +0 -3
  37. package/dist/commands/function.d.ts.map +0 -1
  38. package/dist/commands/function.js +0 -243
  39. package/dist/commands/help.d.ts +0 -3
  40. package/dist/commands/help.d.ts.map +0 -1
  41. package/dist/commands/help.js +0 -20
  42. package/dist/commands/index.d.ts +0 -3
  43. package/dist/commands/index.d.ts.map +0 -1
  44. package/dist/commands/index.js +0 -26
  45. package/dist/commands/login.d.ts +0 -3
  46. package/dist/commands/login.d.ts.map +0 -1
  47. package/dist/commands/login.js +0 -175
  48. package/dist/commands/project.d.ts +0 -3
  49. package/dist/commands/project.d.ts.map +0 -1
  50. package/dist/commands/project.js +0 -78
  51. package/dist/commands/store-version.d.ts +0 -3
  52. package/dist/commands/store-version.d.ts.map +0 -1
  53. package/dist/commands/store-version.js +0 -241
  54. package/dist/commands/version.d.ts +0 -3
  55. package/dist/commands/version.d.ts.map +0 -1
  56. package/dist/commands/version.js +0 -46
  57. package/dist/commands/whoami.d.ts +0 -3
  58. package/dist/commands/whoami.d.ts.map +0 -1
  59. package/dist/commands/whoami.js +0 -41
  60. package/dist/index.d.ts.map +0 -1
  61. package/dist/prompts/component.prompts.d.ts +0 -14
  62. package/dist/prompts/component.prompts.d.ts.map +0 -1
  63. package/dist/prompts/component.prompts.js +0 -75
  64. package/dist/prompts/function.prompts.d.ts +0 -21
  65. package/dist/prompts/function.prompts.d.ts.map +0 -1
  66. package/dist/prompts/function.prompts.js +0 -127
  67. package/dist/schemas/command.schema.d.ts +0 -516
  68. package/dist/schemas/command.schema.d.ts.map +0 -1
  69. package/dist/schemas/command.schema.js +0 -267
  70. package/dist/types/index.d.ts +0 -147
  71. package/dist/types/index.d.ts.map +0 -1
  72. package/dist/types/index.js +0 -18
  73. package/dist/utils/auth.d.ts +0 -4
  74. package/dist/utils/auth.d.ts.map +0 -1
  75. package/dist/utils/auth.js +0 -26
  76. package/dist/utils/cli-progress-reporter.d.ts +0 -12
  77. package/dist/utils/cli-progress-reporter.d.ts.map +0 -1
  78. package/dist/utils/cli-progress-reporter.js +0 -77
  79. package/dist/utils/command-builder.d.ts +0 -22
  80. package/dist/utils/command-builder.d.ts.map +0 -1
  81. package/dist/utils/command-builder.js +0 -268
  82. package/dist/utils/command-helpers.d.ts +0 -19
  83. package/dist/utils/command-helpers.d.ts.map +0 -1
  84. package/dist/utils/command-helpers.js +0 -79
  85. package/dist/utils/command-parser.d.ts +0 -146
  86. package/dist/utils/command-parser.d.ts.map +0 -1
  87. package/dist/utils/command-parser.js +0 -179
  88. package/dist/utils/command-suggestions.d.ts +0 -35
  89. package/dist/utils/command-suggestions.d.ts.map +0 -1
  90. package/dist/utils/command-suggestions.js +0 -152
  91. package/dist/utils/console.d.ts +0 -44
  92. package/dist/utils/console.d.ts.map +0 -1
  93. package/dist/utils/console.js +0 -233
  94. package/dist/utils/constants.d.ts +0 -8
  95. package/dist/utils/constants.d.ts.map +0 -1
  96. package/dist/utils/constants.js +0 -10
  97. package/dist/utils/context-detector.d.ts +0 -12
  98. package/dist/utils/context-detector.d.ts.map +0 -1
  99. package/dist/utils/context-detector.js +0 -155
  100. package/dist/utils/enhanced-error-handler.d.ts +0 -47
  101. package/dist/utils/enhanced-error-handler.d.ts.map +0 -1
  102. package/dist/utils/enhanced-error-handler.js +0 -221
  103. package/dist/utils/error-handler.d.ts +0 -3
  104. package/dist/utils/error-handler.d.ts.map +0 -1
  105. package/dist/utils/error-handler.js +0 -55
  106. package/dist/utils/errors.d.ts +0 -44
  107. package/dist/utils/errors.d.ts.map +0 -1
  108. package/dist/utils/errors.js +0 -76
  109. package/dist/utils/interactive-builder.d.ts +0 -22
  110. package/dist/utils/interactive-builder.d.ts.map +0 -1
  111. package/dist/utils/interactive-builder.js +0 -246
  112. package/dist/utils/rich-progress.d.ts +0 -59
  113. package/dist/utils/rich-progress.d.ts.map +0 -1
  114. package/dist/utils/rich-progress.js +0 -234
  115. package/dist/utils/store.d.ts +0 -11
  116. package/dist/utils/store.d.ts.map +0 -1
  117. package/dist/utils/store.js +0 -19
  118. package/dist/utils/validation-error-formatter.d.ts +0 -25
  119. package/dist/utils/validation-error-formatter.d.ts.map +0 -1
  120. package/dist/utils/validation-error-formatter.js +0 -258
  121. package/dist/utils/validation-helpers.d.ts +0 -60
  122. package/dist/utils/validation-helpers.d.ts.map +0 -1
  123. package/dist/utils/validation-helpers.js +0 -152
  124. package/src/commands/__tests__/version.test.ts +0 -71
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ollie-shop/cli",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Ollie Shop CLI for building custom checkouts",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,8 +20,7 @@
20
20
  "open": "^8.4.2",
21
21
  "ora": "^5.4.1",
22
22
  "semver": "^7.5.4",
23
- "zod": "^3.22.4",
24
- "@ollie-shop/core": "1.0.0"
23
+ "zod": "^3.22.4"
25
24
  },
26
25
  "devDependencies": {
27
26
  "@anatine/zod-mock": "^3.14.0",
@@ -33,18 +32,20 @@
33
32
  "@vitest/coverage-v8": "3.0.4",
34
33
  "fishery": "^2.3.1",
35
34
  "msw": "^2.10.3",
35
+ "tsup": "^8.0.1",
36
36
  "typescript": "^5.7.3",
37
37
  "vitest": "^3.0.4",
38
38
  "vitest-mock-extended": "^3.1.0",
39
- "wait-for-expect": "^3.0.2"
39
+ "wait-for-expect": "^3.0.2",
40
+ "@ollie-shop/core": "1.0.2"
40
41
  },
41
42
  "publishConfig": {
42
43
  "access": "public",
43
44
  "registry": "https://registry.npmjs.org/"
44
45
  },
45
46
  "scripts": {
46
- "build": "tsc",
47
- "dev": "tsc --watch",
47
+ "build": "tsup",
48
+ "dev": "tsup --watch",
48
49
  "test": "vitest",
49
50
  "test:coverage": "vitest run --coverage",
50
51
  "lint": "eslint src/**/*.ts",
@@ -54,6 +54,14 @@ export async function createComponent(
54
54
  ]);
55
55
  } catch (error) {
56
56
  spinner.fail("Failed to create component");
57
+ const { message, stack } =
58
+ error instanceof Error
59
+ ? error
60
+ : { message: "Unexpected error", stack: undefined };
61
+ cliConsole.error(`Error details: ${message}`);
62
+ if (stack) {
63
+ cliConsole.debug(`Stack trace: ${stack}`);
64
+ }
57
65
  throw error;
58
66
  }
59
67
  }
@@ -75,6 +83,14 @@ export async function validateComponent(
75
83
  handleValidationResult(result, spinner, cliConsole, "Component");
76
84
  } catch (error) {
77
85
  spinner.fail("Validation failed");
86
+ const { message, stack } =
87
+ error instanceof Error
88
+ ? error
89
+ : { message: "Unexpected error", stack: undefined };
90
+ cliConsole.error(`Error details: ${message}`);
91
+ if (stack) {
92
+ cliConsole.debug(`Stack trace: ${stack}`);
93
+ }
78
94
  throw error;
79
95
  }
80
96
  }
@@ -129,6 +145,11 @@ export async function deployComponent(
129
145
  throw new Error("Component ID is required for deployment");
130
146
  }
131
147
 
148
+ cliConsole.warn(
149
+ "[WARNING] Component deployment is not yet implemented in production",
150
+ );
151
+ cliConsole.info("This is a demo simulation showing how deployment will work");
152
+
132
153
  const spinner = cliConsole.spinner({
133
154
  text: "Building and deploying component...",
134
155
  });
@@ -218,6 +239,11 @@ export async function checkDeployStatus(
218
239
  buildId: string,
219
240
  cliConsole: CliConsole,
220
241
  ): Promise<void> {
242
+ cliConsole.warn(
243
+ "[WARNING] Deploy status check is not yet implemented in production",
244
+ );
245
+ cliConsole.info("Showing mock status for demo purposes");
246
+
221
247
  const spinner = cliConsole.spinner({ text: "Checking deployment status..." });
222
248
 
223
249
  try {
@@ -266,6 +292,11 @@ export async function checkDeployStatus(
266
292
  }
267
293
 
268
294
  export async function listComponents(cliConsole: CliConsole): Promise<void> {
295
+ cliConsole.warn(
296
+ "[WARNING] Component listing is not yet implemented in production",
297
+ );
298
+ cliConsole.info("Showing mock components for demo purposes");
299
+
269
300
  const spinner = cliConsole.spinner({ text: "Loading components..." });
270
301
 
271
302
  try {
@@ -55,6 +55,14 @@ export async function createFunction(
55
55
  ]);
56
56
  } catch (error) {
57
57
  spinner.fail("Failed to create function");
58
+ const { message, stack } =
59
+ error instanceof Error
60
+ ? error
61
+ : { message: "Unexpected error", stack: undefined };
62
+ cliConsole.error(`Error details: ${message}`);
63
+ if (stack) {
64
+ cliConsole.debug(`Stack trace: ${stack}`);
65
+ }
58
66
  throw error;
59
67
  }
60
68
  }
@@ -116,6 +124,14 @@ export async function testFunction(
116
124
  }
117
125
  } catch (error) {
118
126
  spinner.fail("Tests failed");
127
+ const { message, stack } =
128
+ error instanceof Error
129
+ ? error
130
+ : { message: "Unexpected error", stack: undefined };
131
+ cliConsole.error(`Error details: ${message}`);
132
+ if (stack) {
133
+ cliConsole.debug(`Stack trace: ${stack}`);
134
+ }
119
135
  throw error;
120
136
  }
121
137
  }
@@ -138,6 +154,14 @@ export async function validateFunction(
138
154
  handleValidationResult(result, spinner, cliConsole, "Function");
139
155
  } catch (error) {
140
156
  spinner.fail("Validation failed");
157
+ const { message, stack } =
158
+ error instanceof Error
159
+ ? error
160
+ : { message: "Unexpected error", stack: undefined };
161
+ cliConsole.error(`Error details: ${message}`);
162
+ if (stack) {
163
+ cliConsole.debug(`Stack trace: ${stack}`);
164
+ }
141
165
  throw error;
142
166
  }
143
167
  }
@@ -150,6 +174,11 @@ export async function deployFunction(
150
174
  throw new Error("Function ID is required for deployment");
151
175
  }
152
176
 
177
+ cliConsole.warn(
178
+ "[WARNING] Function deployment is not yet implemented in production",
179
+ );
180
+ cliConsole.info("This is a demo simulation showing how deployment will work");
181
+
153
182
  const spinner = cliConsole.spinner({
154
183
  text: "Building and deploying function...",
155
184
  });
@@ -240,6 +269,11 @@ export async function deployFunction(
240
269
  }
241
270
 
242
271
  export async function listFunctions(cliConsole: CliConsole): Promise<void> {
272
+ cliConsole.warn(
273
+ "[WARNING] Function listing is not yet implemented in production",
274
+ );
275
+ cliConsole.info("Showing mock functions for demo purposes");
276
+
243
277
  const spinner = cliConsole.spinner({ text: "Loading functions..." });
244
278
 
245
279
  try {
@@ -92,7 +92,9 @@ export async function buildProject(
92
92
 
93
93
  const targetPath = options.path || process.cwd();
94
94
 
95
- cliConsole.warn("Project building is not yet implemented");
95
+ cliConsole.warn(
96
+ "[WARNING] Project building is not yet implemented in production",
97
+ );
96
98
  cliConsole.info(`Target path: ${targetPath}`);
97
99
 
98
100
  if (options.watch) {
@@ -112,7 +114,9 @@ export async function startDevServer(
112
114
  // TODO: Implement development server functionality
113
115
  // This function needs to be implemented in the core package
114
116
 
115
- cliConsole.warn("Development server is not yet implemented");
117
+ cliConsole.warn(
118
+ "[WARNING] Development server is not yet implemented in production",
119
+ );
116
120
  cliConsole.info(`Would start server on port ${options.port || 3000}`);
117
121
 
118
122
  if (options.open) {
@@ -1,8 +1,5 @@
1
1
  import type { Command } from "@commander-js/extra-typings";
2
- import {
3
- storeFactory,
4
- versionFactory,
5
- } from "@ollie-shop/core/__tests__/factories";
2
+ import { storeFactory, versionFactory } from "@ollie-shop/core/testing";
6
3
  import {
7
4
  createTestProgram,
8
5
  executeCLI,
package/tsup.config.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { defineConfig } from "tsup";
2
+
3
+ export default defineConfig({
4
+ entry: ["src/index.ts"],
5
+ bundle: true,
6
+ minify: false,
7
+ sourcemap: false,
8
+ format: ["cjs"],
9
+ clean: true,
10
+ dts: true,
11
+ treeshake: true,
12
+ platform: "node",
13
+ target: "node18",
14
+ noExternal: ["@ollie-shop/core"],
15
+ });
@@ -1,89 +0,0 @@
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
@@ -1 +0,0 @@
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,MAAM,QAAQ,CAAC;AAEpC;;;GAGG;AAEH,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IAC/B,MAAM,EAAE;QACN,KAAK,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;KACjC,CAAC;IACF,MAAM,EAAE;QACN,KAAK,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;KACjC,CAAC;CACH;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;IAC9B,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;CAChC;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE;QACL,OAAO,EAAE,YAAY,CAAC;QACtB,OAAO,EAAE,YAAY,CAAC;KACvB,CAAC;IACF,SAAS,EAAE,MAAM,aAAa,CAAC;CAChC,CAgGA;AAED;;GAEG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,GAAE;IAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAAA;CAAqB,GACjE,OAAO,CAAC,aAAa,CAAC,CAgDxB;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,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"}
@@ -1,220 +0,0 @@
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
- }
@@ -1,69 +0,0 @@
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<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