@posthog/wizard 0.7.0 → 0.8.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 (138) hide show
  1. package/dist/bin.d.ts +2 -0
  2. package/dist/bin.js +28 -0
  3. package/dist/bin.js.map +1 -0
  4. package/dist/src/lib/config.d.ts +49 -0
  5. package/dist/src/lib/config.js +85 -0
  6. package/dist/src/lib/config.js.map +1 -0
  7. package/dist/src/lib/constants.d.ts +25 -0
  8. package/dist/src/lib/constants.js +45 -0
  9. package/dist/src/lib/constants.js.map +1 -0
  10. package/dist/src/lib/messages.d.ts +17 -0
  11. package/dist/src/lib/messages.js +68 -0
  12. package/dist/src/lib/messages.js.map +1 -0
  13. package/dist/src/lib/prompts.d.ts +16 -0
  14. package/dist/src/lib/prompts.js +83 -0
  15. package/dist/src/lib/prompts.js.map +1 -0
  16. package/dist/src/nextjs/docs.d.ts +8 -0
  17. package/dist/src/nextjs/docs.js +257 -0
  18. package/dist/src/nextjs/docs.js.map +1 -0
  19. package/dist/src/nextjs/nextjs-wizard.d.ts +2 -0
  20. package/dist/src/nextjs/nextjs-wizard.js +136 -0
  21. package/dist/src/nextjs/nextjs-wizard.js.map +1 -0
  22. package/dist/src/nextjs/utils.d.ts +9 -0
  23. package/dist/src/nextjs/utils.js +83 -0
  24. package/dist/src/nextjs/utils.js.map +1 -0
  25. package/dist/src/react/docs.d.ts +4 -0
  26. package/dist/src/react/docs.js +46 -0
  27. package/dist/src/react/docs.js.map +1 -0
  28. package/dist/src/react/react-wizard.d.ts +2 -0
  29. package/dist/src/react/react-wizard.js +115 -0
  30. package/dist/src/react/react-wizard.js.map +1 -0
  31. package/dist/src/react-native/docs.d.ts +5 -0
  32. package/dist/src/react-native/docs.js +31 -0
  33. package/dist/src/react-native/docs.js.map +1 -0
  34. package/dist/src/react-native/react-native-wizard.d.ts +2 -0
  35. package/dist/src/react-native/react-native-wizard.js +124 -0
  36. package/dist/src/react-native/react-native-wizard.js.map +1 -0
  37. package/dist/src/run.d.ts +13 -0
  38. package/dist/src/run.js +85 -0
  39. package/dist/src/run.js.map +1 -0
  40. package/dist/src/steps/__tests__/add-editor-rules.test.d.ts +1 -0
  41. package/dist/src/steps/__tests__/add-editor-rules.test.js +218 -0
  42. package/dist/src/steps/__tests__/add-editor-rules.test.js.map +1 -0
  43. package/dist/src/steps/__tests__/create-pr.test.d.ts +1 -0
  44. package/dist/src/steps/__tests__/create-pr.test.js +193 -0
  45. package/dist/src/steps/__tests__/create-pr.test.js.map +1 -0
  46. package/dist/src/steps/add-editor-rules.d.ts +9 -0
  47. package/dist/src/steps/add-editor-rules.js +92 -0
  48. package/dist/src/steps/add-editor-rules.js.map +1 -0
  49. package/dist/src/steps/add-or-update-environment-variables.d.ts +10 -0
  50. package/dist/src/steps/add-or-update-environment-variables.js +194 -0
  51. package/dist/src/steps/add-or-update-environment-variables.js.map +1 -0
  52. package/dist/src/steps/create-pr.d.ts +27 -0
  53. package/dist/src/steps/create-pr.js +305 -0
  54. package/dist/src/steps/create-pr.js.map +1 -0
  55. package/dist/src/steps/index.d.ts +4 -0
  56. package/dist/src/steps/index.js +21 -0
  57. package/dist/src/steps/index.js.map +1 -0
  58. package/dist/src/steps/run-prettier.d.ts +5 -0
  59. package/dist/src/steps/run-prettier.js +93 -0
  60. package/dist/src/steps/run-prettier.js.map +1 -0
  61. package/dist/src/steps/upload-environment-variables/EnvironmentProvider.d.ts +8 -0
  62. package/dist/src/steps/upload-environment-variables/EnvironmentProvider.js +12 -0
  63. package/dist/src/steps/upload-environment-variables/EnvironmentProvider.js.map +1 -0
  64. package/dist/src/steps/upload-environment-variables/index.d.ts +6 -0
  65. package/dist/src/steps/upload-environment-variables/index.js +66 -0
  66. package/dist/src/steps/upload-environment-variables/index.js.map +1 -0
  67. package/dist/src/steps/upload-environment-variables/providers/__tests__/vercel.test.d.ts +1 -0
  68. package/dist/src/steps/upload-environment-variables/providers/__tests__/vercel.test.js +117 -0
  69. package/dist/src/steps/upload-environment-variables/providers/__tests__/vercel.test.js.map +1 -0
  70. package/dist/src/steps/upload-environment-variables/providers/vercel.d.ts +14 -0
  71. package/dist/src/steps/upload-environment-variables/providers/vercel.js +146 -0
  72. package/dist/src/steps/upload-environment-variables/providers/vercel.js.map +1 -0
  73. package/dist/src/svelte/docs.d.ts +3 -0
  74. package/dist/src/svelte/docs.js +110 -0
  75. package/dist/src/svelte/docs.js.map +1 -0
  76. package/dist/src/svelte/svelte-wizard.d.ts +2 -0
  77. package/dist/src/svelte/svelte-wizard.js +115 -0
  78. package/dist/src/svelte/svelte-wizard.js.map +1 -0
  79. package/dist/src/telemetry.d.ts +2 -0
  80. package/dist/src/telemetry.js +13 -0
  81. package/dist/src/telemetry.js.map +1 -0
  82. package/dist/src/utils/__tests__/clack-utils.test.d.ts +1 -0
  83. package/dist/src/utils/__tests__/clack-utils.test.js +128 -0
  84. package/dist/src/utils/__tests__/clack-utils.test.js.map +1 -0
  85. package/dist/src/utils/analytics.d.ts +12 -0
  86. package/dist/src/utils/analytics.js +59 -0
  87. package/dist/src/utils/analytics.js.map +1 -0
  88. package/dist/src/utils/bash.d.ts +2 -0
  89. package/dist/src/utils/bash.js +54 -0
  90. package/dist/src/utils/bash.js.map +1 -0
  91. package/dist/src/utils/clack-utils.d.ts +180 -0
  92. package/dist/src/utils/clack-utils.js +634 -0
  93. package/dist/src/utils/clack-utils.js.map +1 -0
  94. package/dist/src/utils/clack.d.ts +2 -0
  95. package/dist/src/utils/clack.js +9 -0
  96. package/dist/src/utils/clack.js.map +1 -0
  97. package/dist/src/utils/debug.d.ts +2 -0
  98. package/dist/src/utils/debug.js +22 -0
  99. package/dist/src/utils/debug.js.map +1 -0
  100. package/dist/src/utils/environment.d.ts +3 -0
  101. package/dist/src/utils/environment.js +64 -0
  102. package/dist/src/utils/environment.js.map +1 -0
  103. package/dist/src/utils/file-utils.d.ts +29 -0
  104. package/dist/src/utils/file-utils.js +177 -0
  105. package/dist/src/utils/file-utils.js.map +1 -0
  106. package/dist/src/utils/logging.d.ts +9 -0
  107. package/dist/src/utils/logging.js +50 -0
  108. package/dist/src/utils/logging.js.map +1 -0
  109. package/dist/src/utils/package-json.d.ts +25 -0
  110. package/dist/src/utils/package-json.js +27 -0
  111. package/dist/src/utils/package-json.js.map +1 -0
  112. package/dist/src/utils/package-manager.d.ts +21 -0
  113. package/dist/src/utils/package-manager.js +208 -0
  114. package/dist/src/utils/package-manager.js.map +1 -0
  115. package/dist/src/utils/query.d.ts +8 -0
  116. package/dist/src/utils/query.js +27 -0
  117. package/dist/src/utils/query.js.map +1 -0
  118. package/dist/src/utils/rules/next-rules.md +9 -0
  119. package/dist/src/utils/rules/react-native-rules.md +7 -0
  120. package/dist/src/utils/rules/react-rules.md +7 -0
  121. package/dist/src/utils/rules/svelte-rules.md +7 -0
  122. package/dist/src/utils/rules/universal.md +20 -0
  123. package/dist/src/utils/semver.d.ts +5 -0
  124. package/dist/src/utils/semver.js +25 -0
  125. package/dist/src/utils/semver.js.map +1 -0
  126. package/dist/src/utils/string.d.ts +1 -0
  127. package/dist/src/utils/string.js +9 -0
  128. package/dist/src/utils/string.js.map +1 -0
  129. package/dist/src/utils/types.d.ts +48 -0
  130. package/dist/src/utils/types.js +3 -0
  131. package/dist/src/utils/types.js.map +1 -0
  132. package/dist/src/utils/urls.d.ts +4 -0
  133. package/dist/src/utils/urls.js +35 -0
  134. package/dist/src/utils/urls.js.map +1 -0
  135. package/dist/src/utils/vendor/is-unicorn-supported.d.ts +1 -0
  136. package/dist/src/utils/vendor/is-unicorn-supported.js +24 -0
  137. package/dist/src/utils/vendor/is-unicorn-supported.js.map +1 -0
  138. package/package.json +5 -1
@@ -0,0 +1,218 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ const fs = __importStar(require("fs"));
40
+ const path_1 = __importDefault(require("path"));
41
+ const add_editor_rules_1 = require("../add-editor-rules");
42
+ const analytics_1 = require("../../utils/analytics");
43
+ const clack_1 = __importDefault(require("../../utils/clack"));
44
+ const chalk_1 = __importDefault(require("chalk"));
45
+ // Mock dependencies
46
+ jest.mock('fs', () => ({
47
+ promises: {
48
+ mkdir: jest.fn(),
49
+ readFile: jest.fn(),
50
+ writeFile: jest.fn(),
51
+ },
52
+ }));
53
+ jest.mock('../../utils/analytics', () => ({
54
+ analytics: {
55
+ capture: jest.fn(),
56
+ setTag: jest.fn(),
57
+ shutdown: jest.fn().mockResolvedValue(undefined),
58
+ },
59
+ }));
60
+ jest.mock('../../utils/clack', () => ({
61
+ log: {
62
+ info: jest.fn(),
63
+ },
64
+ select: jest.fn().mockResolvedValue(true),
65
+ isCancel: jest.fn((value) => false),
66
+ cancel: jest.fn(),
67
+ }));
68
+ describe('addEditorRules', () => {
69
+ const mockOptions = {
70
+ installDir: '/test/dir',
71
+ rulesName: 'react-rules.md',
72
+ integration: 'react',
73
+ };
74
+ const originalEnv = process.env;
75
+ const mkdirMock = fs.promises.mkdir;
76
+ const readFileMock = fs.promises.readFile;
77
+ const writeFileMock = fs.promises.writeFile;
78
+ // eslint-disable-next-line @typescript-eslint/unbound-method
79
+ const captureMock = analytics_1.analytics.capture;
80
+ const infoMock = clack_1.default.log.info;
81
+ const selectMock = clack_1.default.select;
82
+ const isCancelMock = clack_1.default.isCancel;
83
+ const cancelMock = clack_1.default.cancel;
84
+ beforeEach(() => {
85
+ // Reset all mocks before each test
86
+ jest.clearAllMocks();
87
+ // Clear mock implementations
88
+ fs.promises.mkdir.mockReset();
89
+ fs.promises.readFile.mockReset();
90
+ fs.promises.writeFile.mockReset();
91
+ selectMock.mockReset();
92
+ selectMock.mockResolvedValue(true); // Default to "Yes" for the prompt
93
+ isCancelMock.mockReset();
94
+ isCancelMock.mockReturnValue(false);
95
+ cancelMock.mockReset();
96
+ process.env = { ...originalEnv };
97
+ });
98
+ afterAll(() => {
99
+ process.env = originalEnv;
100
+ });
101
+ it('should not install rules when CURSOR_TRACE_ID is not set', async () => {
102
+ delete process.env.CURSOR_TRACE_ID;
103
+ await (0, add_editor_rules_1.addEditorRulesStep)(mockOptions);
104
+ expect(mkdirMock).not.toHaveBeenCalled();
105
+ expect(readFileMock).not.toHaveBeenCalled();
106
+ expect(writeFileMock).not.toHaveBeenCalled();
107
+ expect(captureMock).not.toHaveBeenCalled();
108
+ expect(infoMock).not.toHaveBeenCalled();
109
+ });
110
+ it('should install rules when CURSOR_TRACE_ID is set', async () => {
111
+ process.env.CURSOR_TRACE_ID = 'test-trace-id';
112
+ const mockFrameworkRules = 'framework rules {universal} content';
113
+ const mockUniversalRules = 'universal rules content';
114
+ const expectedCombinedRules = 'framework rules universal rules content content';
115
+ fs.promises.readFile
116
+ .mockImplementationOnce(() => Promise.resolve(mockFrameworkRules))
117
+ .mockImplementationOnce(() => Promise.resolve(mockUniversalRules));
118
+ await (0, add_editor_rules_1.addEditorRulesStep)(mockOptions);
119
+ // Check if directory was created
120
+ expect(mkdirMock).toHaveBeenCalledWith(path_1.default.join('/test/dir', '.cursor', 'rules'), { recursive: true });
121
+ // Check if correct files were read
122
+ expect(readFileMock).toHaveBeenCalledTimes(2);
123
+ expect(readFileMock).toHaveBeenNthCalledWith(1, expect.stringMatching(/react-rules\.md$/), 'utf8');
124
+ expect(readFileMock).toHaveBeenNthCalledWith(2, expect.stringMatching(/universal\.md$/), 'utf8');
125
+ // Check if combined rules were written correctly
126
+ expect(writeFileMock).toHaveBeenCalledWith(path_1.default.join('/test/dir', '.cursor', 'rules', 'posthog-integration.mdc'), expectedCombinedRules, 'utf8');
127
+ // Check if analytics were captured
128
+ expect(captureMock).toHaveBeenCalledWith('wizard interaction', {
129
+ action: 'added editor rules',
130
+ integration: mockOptions.integration,
131
+ });
132
+ // Check if success message was logged
133
+ expect(infoMock).toHaveBeenCalledWith(`Added Cursor rules to ${chalk_1.default.bold.cyan('.cursor/rules/posthog-integration.mdc')}`);
134
+ });
135
+ it('should handle file system errors gracefully', async () => {
136
+ process.env.CURSOR_TRACE_ID = 'test-trace-id';
137
+ const mockError = new Error('File not found');
138
+ // Mock readFile to throw an error
139
+ fs.promises.readFile.mockRejectedValue(mockError);
140
+ await expect((0, add_editor_rules_1.addEditorRulesStep)(mockOptions)).rejects.toThrow(mockError);
141
+ expect(writeFileMock).not.toHaveBeenCalled();
142
+ expect(captureMock).not.toHaveBeenCalled();
143
+ expect(infoMock).not.toHaveBeenCalled();
144
+ });
145
+ it('should handle missing rules files gracefully', async () => {
146
+ process.env.CURSOR_TRACE_ID = 'test-trace-id';
147
+ const mockError = new Error('File system error');
148
+ // Mock mkdir to throw an error
149
+ fs.promises.mkdir.mockRejectedValue(mockError);
150
+ await expect((0, add_editor_rules_1.addEditorRulesStep)(mockOptions)).rejects.toThrow(mockError);
151
+ expect(writeFileMock).not.toHaveBeenCalled();
152
+ expect(captureMock).not.toHaveBeenCalled();
153
+ expect(infoMock).not.toHaveBeenCalled();
154
+ });
155
+ it('should correctly substitute universal rules with realistic content', async () => {
156
+ process.env.CURSOR_TRACE_ID = 'test-trace-id';
157
+ const mockFrameworkRules = `---
158
+ description: apply when interacting with PostHog/analytics tasks
159
+ globs:
160
+ alwaysApply: true
161
+ ---
162
+
163
+ {universal}
164
+
165
+ # Framework-specific rules
166
+ - Rule 1
167
+ - Rule 2`;
168
+ const mockUniversalRules = `Never hallucinate an API key. Instead, always use the API key populated in the .env file.
169
+
170
+ # Feature flags
171
+
172
+ A given feature flag should be used in as few places as possible. Do not increase the risk of undefined behavior by scattering the same feature flag across multiple areas of code.`;
173
+ const expectedCombinedRules = `---
174
+ description: apply when interacting with PostHog/analytics tasks
175
+ globs:
176
+ alwaysApply: true
177
+ ---
178
+
179
+ Never hallucinate an API key. Instead, always use the API key populated in the .env file.
180
+
181
+ # Feature flags
182
+
183
+ A given feature flag should be used in as few places as possible. Do not increase the risk of undefined behavior by scattering the same feature flag across multiple areas of code.
184
+
185
+ # Framework-specific rules
186
+ - Rule 1
187
+ - Rule 2`;
188
+ fs.promises.readFile
189
+ .mockImplementationOnce(() => Promise.resolve(mockFrameworkRules))
190
+ .mockImplementationOnce(() => Promise.resolve(mockUniversalRules));
191
+ await (0, add_editor_rules_1.addEditorRulesStep)(mockOptions);
192
+ // Check if directory was created
193
+ expect(mkdirMock).toHaveBeenCalledWith(path_1.default.join('/test/dir', '.cursor', 'rules'), { recursive: true });
194
+ // Check if correct files were read
195
+ expect(readFileMock).toHaveBeenCalledWith(expect.stringMatching(/react-rules\.md$/), 'utf8');
196
+ expect(readFileMock).toHaveBeenCalledWith(expect.stringMatching(/universal\.md$/), 'utf8');
197
+ // Check if combined rules were written correctly
198
+ expect(writeFileMock).toHaveBeenCalledWith(path_1.default.join('/test/dir', '.cursor', 'rules', 'posthog-integration.mdc'), expectedCombinedRules, 'utf8');
199
+ // Check if analytics were captured
200
+ expect(captureMock).toHaveBeenCalledWith('wizard interaction', {
201
+ action: 'added editor rules',
202
+ integration: mockOptions.integration,
203
+ });
204
+ // Check if success message was logged
205
+ expect(infoMock).toHaveBeenCalledWith(`Added Cursor rules to ${chalk_1.default.bold.cyan('.cursor/rules/posthog-integration.mdc')}`);
206
+ });
207
+ it('should not install rules when user declines', async () => {
208
+ process.env.CURSOR_TRACE_ID = 'test-trace-id';
209
+ selectMock.mockResolvedValue(false);
210
+ await (0, add_editor_rules_1.addEditorRulesStep)(mockOptions);
211
+ expect(mkdirMock).not.toHaveBeenCalled();
212
+ expect(readFileMock).not.toHaveBeenCalled();
213
+ expect(writeFileMock).not.toHaveBeenCalled();
214
+ expect(captureMock).not.toHaveBeenCalled();
215
+ expect(infoMock).not.toHaveBeenCalled();
216
+ });
217
+ });
218
+ //# sourceMappingURL=add-editor-rules.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-editor-rules.test.js","sourceRoot":"","sources":["../../../../src/steps/__tests__/add-editor-rules.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,gDAAwB;AACxB,0DAAyD;AACzD,qDAAkD;AAClD,8DAAsC;AAEtC,kDAA0B;AAE1B,oBAAoB;AACpB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;IACrB,QAAQ,EAAE;QACR,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;QAChB,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;QACnB,SAAS,EAAE,IAAI,CAAC,EAAE,EAAE;KACrB;CACF,CAAC,CAAC,CAAC;AAEJ,IAAI,CAAC,IAAI,CAAC,uBAAuB,EAAE,G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MAAM,CAAC,aAAa,CAAC,CAAC,oBAAoB,CACxC,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,yBAAyB,CAAC,EACrE,qBAAqB,EACrB,MAAM,CACP,CAAC;QAEF,mCAAmC;QACnC,MAAM,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC,oBAAoB,EAAE;YAC7D,MAAM,EAAE,oBAAoB;YAC5B,WAAW,EAAE,WAAW,CAAC,WAAW;SACrC,CAAC,CAAC;QAEH,sCAAsC;QACtC,MAAM,CAAC,QAAQ,CAAC,CAAC,oBAAoB,CACnC,yBAAyB,eAAK,CAAC,IAAI,CAAC,IAAI,CACtC,uCAAuC,CACxC,EAAE,CACJ,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,KAAK,IAAI,EAAE;QAC3D,OAAO,CAAC,GAAG,CAAC,eAAe,GAAG,eAAe,CAAC;QAC9C,UAAU,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAEpC,MAAM,IAAA,qCAAkB,EAAC,WAAW,CAAC,CAAC;QAEtC,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACzC,MAAM,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QAC5C,MAAM,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QAC7C,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QAC3C,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IAC1C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import * as fs from 'fs';\nimport path from 'path';\nimport { addEditorRulesStep } from '../add-editor-rules';\nimport { analytics } from '../../utils/analytics';\nimport clack from '../../utils/clack';\nimport { Integration } from '../../lib/constants';\nimport chalk from 'chalk';\n\n// Mock dependencies\njest.mock('fs', () => ({\n promises: {\n mkdir: jest.fn(),\n readFile: jest.fn(),\n writeFile: jest.fn(),\n },\n}));\n\njest.mock('../../utils/analytics', () => ({\n analytics: {\n capture: jest.fn(),\n setTag: jest.fn(),\n shutdown: jest.fn().mockResolvedValue(undefined),\n },\n}));\n\njest.mock('../../utils/clack', () => ({\n log: {\n info: jest.fn(),\n },\n select: jest.fn().mockResolvedValue(true),\n isCancel: jest.fn((value: unknown): value is symbol => false),\n cancel: jest.fn(),\n}));\n\ndescribe('addEditorRules', () => {\n const mockOptions = {\n installDir: '/test/dir',\n rulesName: 'react-rules.md',\n integration: 'react' as Integration,\n };\n\n const originalEnv = process.env;\n const mkdirMock = fs.promises.mkdir as jest.Mock;\n const readFileMock = fs.promises.readFile as jest.Mock;\n const writeFileMock = fs.promises.writeFile as jest.Mock;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const captureMock = analytics.capture as jest.Mock;\n const infoMock = clack.log.info as jest.Mock;\n const selectMock = clack.select as jest.Mock;\n const isCancelMock = clack.isCancel as unknown as jest.Mock;\n const cancelMock = clack.cancel as jest.Mock;\n\n beforeEach(() => {\n // Reset all mocks before each test\n jest.clearAllMocks();\n // Clear mock implementations\n (fs.promises.mkdir as jest.Mock).mockReset();\n (fs.promises.readFile as jest.Mock).mockReset();\n (fs.promises.writeFile as jest.Mock).mockReset();\n selectMock.mockReset();\n selectMock.mockResolvedValue(true); // Default to \"Yes\" for the prompt\n isCancelMock.mockReset();\n isCancelMock.mockReturnValue(false);\n cancelMock.mockReset();\n process.env = { ...originalEnv };\n });\n\n afterAll(() => {\n process.env = originalEnv;\n });\n\n it('should not install rules when CURSOR_TRACE_ID is not set', async () => {\n delete process.env.CURSOR_TRACE_ID;\n\n await addEditorRulesStep(mockOptions);\n\n expect(mkdirMock).not.toHaveBeenCalled();\n expect(readFileMock).not.toHaveBeenCalled();\n expect(writeFileMock).not.toHaveBeenCalled();\n expect(captureMock).not.toHaveBeenCalled();\n expect(infoMock).not.toHaveBeenCalled();\n });\n\n it('should install rules when CURSOR_TRACE_ID is set', async () => {\n process.env.CURSOR_TRACE_ID = 'test-trace-id';\n\n const mockFrameworkRules = 'framework rules {universal} content';\n const mockUniversalRules = 'universal rules content';\n const expectedCombinedRules =\n 'framework rules universal rules content content';\n\n (fs.promises.readFile as jest.Mock)\n .mockImplementationOnce(() => Promise.resolve(mockFrameworkRules))\n .mockImplementationOnce(() => Promise.resolve(mockUniversalRules));\n\n await addEditorRulesStep(mockOptions);\n\n // Check if directory was created\n expect(mkdirMock).toHaveBeenCalledWith(\n path.join('/test/dir', '.cursor', 'rules'),\n { recursive: true },\n );\n\n // Check if correct files were read\n expect(readFileMock).toHaveBeenCalledTimes(2);\n expect(readFileMock).toHaveBeenNthCalledWith(\n 1,\n expect.stringMatching(/react-rules\\.md$/),\n 'utf8',\n );\n expect(readFileMock).toHaveBeenNthCalledWith(\n 2,\n expect.stringMatching(/universal\\.md$/),\n 'utf8',\n );\n\n // Check if combined rules were written correctly\n expect(writeFileMock).toHaveBeenCalledWith(\n path.join('/test/dir', '.cursor', 'rules', 'posthog-integration.mdc'),\n expectedCombinedRules,\n 'utf8',\n );\n\n // Check if analytics were captured\n expect(captureMock).toHaveBeenCalledWith('wizard interaction', {\n action: 'added editor rules',\n integration: mockOptions.integration,\n });\n\n // Check if success message was logged\n expect(infoMock).toHaveBeenCalledWith(\n `Added Cursor rules to ${chalk.bold.cyan(\n '.cursor/rules/posthog-integration.mdc',\n )}`,\n );\n });\n\n it('should handle file system errors gracefully', async () => {\n process.env.CURSOR_TRACE_ID = 'test-trace-id';\n const mockError = new Error('File not found');\n\n // Mock readFile to throw an error\n (fs.promises.readFile as jest.Mock).mockRejectedValue(mockError);\n\n await expect(addEditorRulesStep(mockOptions)).rejects.toThrow(mockError);\n\n expect(writeFileMock).not.toHaveBeenCalled();\n expect(captureMock).not.toHaveBeenCalled();\n expect(infoMock).not.toHaveBeenCalled();\n });\n\n it('should handle missing rules files gracefully', async () => {\n process.env.CURSOR_TRACE_ID = 'test-trace-id';\n const mockError = new Error('File system error');\n\n // Mock mkdir to throw an error\n (fs.promises.mkdir as jest.Mock).mockRejectedValue(mockError);\n\n await expect(addEditorRulesStep(mockOptions)).rejects.toThrow(mockError);\n\n expect(writeFileMock).not.toHaveBeenCalled();\n expect(captureMock).not.toHaveBeenCalled();\n expect(infoMock).not.toHaveBeenCalled();\n });\n\n it('should correctly substitute universal rules with realistic content', async () => {\n process.env.CURSOR_TRACE_ID = 'test-trace-id';\n\n const mockFrameworkRules = `---\ndescription: apply when interacting with PostHog/analytics tasks\nglobs: \nalwaysApply: true\n---\n\n{universal}\n\n# Framework-specific rules\n- Rule 1\n- Rule 2`;\n\n const mockUniversalRules = `Never hallucinate an API key. Instead, always use the API key populated in the .env file.\n\n# Feature flags\n\nA given feature flag should be used in as few places as possible. Do not increase the risk of undefined behavior by scattering the same feature flag across multiple areas of code.`;\n\n const expectedCombinedRules = `---\ndescription: apply when interacting with PostHog/analytics tasks\nglobs: \nalwaysApply: true\n---\n\nNever hallucinate an API key. Instead, always use the API key populated in the .env file.\n\n# Feature flags\n\nA given feature flag should be used in as few places as possible. Do not increase the risk of undefined behavior by scattering the same feature flag across multiple areas of code.\n\n# Framework-specific rules\n- Rule 1\n- Rule 2`;\n\n (fs.promises.readFile as jest.Mock)\n .mockImplementationOnce(() => Promise.resolve(mockFrameworkRules))\n .mockImplementationOnce(() => Promise.resolve(mockUniversalRules));\n\n await addEditorRulesStep(mockOptions);\n\n // Check if directory was created\n expect(mkdirMock).toHaveBeenCalledWith(\n path.join('/test/dir', '.cursor', 'rules'),\n { recursive: true },\n );\n\n // Check if correct files were read\n expect(readFileMock).toHaveBeenCalledWith(\n expect.stringMatching(/react-rules\\.md$/),\n 'utf8',\n );\n expect(readFileMock).toHaveBeenCalledWith(\n expect.stringMatching(/universal\\.md$/),\n 'utf8',\n );\n\n // Check if combined rules were written correctly\n expect(writeFileMock).toHaveBeenCalledWith(\n path.join('/test/dir', '.cursor', 'rules', 'posthog-integration.mdc'),\n expectedCombinedRules,\n 'utf8',\n );\n\n // Check if analytics were captured\n expect(captureMock).toHaveBeenCalledWith('wizard interaction', {\n action: 'added editor rules',\n integration: mockOptions.integration,\n });\n\n // Check if success message was logged\n expect(infoMock).toHaveBeenCalledWith(\n `Added Cursor rules to ${chalk.bold.cyan(\n '.cursor/rules/posthog-integration.mdc',\n )}`,\n );\n });\n\n it('should not install rules when user declines', async () => {\n process.env.CURSOR_TRACE_ID = 'test-trace-id';\n selectMock.mockResolvedValue(false);\n\n await addEditorRulesStep(mockOptions);\n\n expect(mkdirMock).not.toHaveBeenCalled();\n expect(readFileMock).not.toHaveBeenCalled();\n expect(writeFileMock).not.toHaveBeenCalled();\n expect(captureMock).not.toHaveBeenCalled();\n expect(infoMock).not.toHaveBeenCalled();\n });\n});\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const childProcess = __importStar(require("node:child_process"));
37
+ const create_pr_1 = require("../create-pr");
38
+ // Mock dependencies
39
+ jest.mock('node:child_process', () => ({
40
+ exec: jest.fn(),
41
+ }));
42
+ describe('Git operations', () => {
43
+ const execMock = childProcess.exec;
44
+ const testDir = '/test/dir';
45
+ beforeEach(() => {
46
+ jest.clearAllMocks();
47
+ });
48
+ describe('getCurrentBranch', () => {
49
+ it('should return the current branch name on success', async () => {
50
+ execMock.mockImplementation((_cmd, _opts, callback) => {
51
+ callback(null, 'main', '');
52
+ return {};
53
+ });
54
+ const result = await (0, create_pr_1.getCurrentBranch)(testDir);
55
+ expect(result).toEqual({ success: true, data: 'main' });
56
+ expect(execMock).toHaveBeenCalledWith('git rev-parse --abbrev-ref HEAD', { cwd: testDir }, expect.any(Function));
57
+ });
58
+ it('should return error on failure', async () => {
59
+ execMock.mockImplementation((_cmd, _opts, callback) => {
60
+ callback(new Error('git error'), '', 'Failed to get branch');
61
+ return {};
62
+ });
63
+ const result = await (0, create_pr_1.getCurrentBranch)(testDir);
64
+ expect(result).toEqual({ success: false, error: 'Failed to get branch' });
65
+ });
66
+ });
67
+ describe('checkForEnvFiles', () => {
68
+ it('should return true when .env files are found', async () => {
69
+ execMock.mockImplementation((_cmd, _opts, callback) => {
70
+ callback(null, '.env\n.env.local', '');
71
+ return {};
72
+ });
73
+ const result = await (0, create_pr_1.checkForEnvFiles)(testDir);
74
+ expect(result).toEqual({ success: true, data: true });
75
+ });
76
+ it('should return false when no .env files are found', async () => {
77
+ const error = new Error('No match');
78
+ error.code = 1;
79
+ execMock.mockImplementation((_cmd, _opts, callback) => {
80
+ callback(error, '', 'command failed with exit code 1');
81
+ return {};
82
+ });
83
+ const result = await (0, create_pr_1.checkForEnvFiles)(testDir);
84
+ expect(result).toEqual({
85
+ success: false,
86
+ error: 'command failed with exit code 1',
87
+ });
88
+ });
89
+ it('should handle grep errors correctly', async () => {
90
+ execMock.mockImplementation((_cmd, _opts, callback) => {
91
+ callback(new Error('grep error'), '', 'Some other error');
92
+ return {};
93
+ });
94
+ const result = await (0, create_pr_1.checkForEnvFiles)(testDir);
95
+ expect(result).toEqual({ success: false, error: 'Some other error' });
96
+ });
97
+ });
98
+ describe('checkBranchExists', () => {
99
+ it('should return success when branch does not exist', async () => {
100
+ execMock.mockImplementation((_cmd, _opts, callback) => {
101
+ callback(new Error('branch not found'), '', 'fatal: not a valid ref');
102
+ return {};
103
+ });
104
+ const result = await (0, create_pr_1.checkBranchExists)('new-branch', testDir);
105
+ expect(result).toEqual({ success: true, data: true });
106
+ });
107
+ it('should return failure when branch exists', async () => {
108
+ execMock.mockImplementation((_cmd, _opts, callback) => {
109
+ callback(null, 'ref exists', '');
110
+ return {};
111
+ });
112
+ const result = await (0, create_pr_1.checkBranchExists)('existing-branch', testDir);
113
+ expect(result).toEqual({ success: false, data: false });
114
+ });
115
+ });
116
+ describe('createGitHubPR', () => {
117
+ it('should create PR successfully', async () => {
118
+ const prUrl = 'https://github.com/org/repo/pull/1';
119
+ execMock.mockImplementation((_cmd, _opts, callback) => {
120
+ callback(null, prUrl, '');
121
+ return {};
122
+ });
123
+ const result = await (0, create_pr_1.createGitHubPR)('main', 'feature', 'title', 'body', testDir);
124
+ expect(result).toEqual({ success: true, data: prUrl });
125
+ expect(execMock).toHaveBeenCalledWith('gh pr create --base main --head feature --title "title" --body "body"', { cwd: testDir }, expect.any(Function));
126
+ });
127
+ it('should handle PR creation failure', async () => {
128
+ execMock.mockImplementation((_cmd, _opts, callback) => {
129
+ callback(new Error('PR creation failed'), '', 'Authentication failed');
130
+ return {};
131
+ });
132
+ const result = await (0, create_pr_1.createGitHubPR)('main', 'feature', 'title', 'body', testDir);
133
+ expect(result).toEqual({
134
+ success: false,
135
+ error: 'Authentication failed',
136
+ });
137
+ });
138
+ });
139
+ describe('Git operations', () => {
140
+ const testCases = [
141
+ {
142
+ fn: create_pr_1.createBranch,
143
+ args: ['new-branch', testDir],
144
+ command: 'git checkout -b new-branch',
145
+ name: 'createBranch',
146
+ },
147
+ {
148
+ fn: create_pr_1.stageChanges,
149
+ args: [testDir],
150
+ command: 'git add .',
151
+ name: 'stageChanges',
152
+ },
153
+ {
154
+ fn: create_pr_1.commitChanges,
155
+ args: ['commit message', testDir],
156
+ command: 'git commit -m "commit message"',
157
+ name: 'commitChanges',
158
+ },
159
+ {
160
+ fn: create_pr_1.pushBranch,
161
+ args: ['branch-name', testDir],
162
+ command: 'git push -u origin branch-name',
163
+ name: 'pushBranch',
164
+ },
165
+ {
166
+ fn: create_pr_1.checkGitHubAuth,
167
+ args: [testDir],
168
+ command: 'gh auth status',
169
+ name: 'checkGitHubAuth',
170
+ },
171
+ ];
172
+ testCases.forEach(({ fn, args, command, name }) => {
173
+ it(`${name} should execute correctly`, async () => {
174
+ execMock.mockImplementation((_cmd, _opts, callback) => {
175
+ callback(null, 'success', '');
176
+ return {};
177
+ });
178
+ const result = await fn(...args);
179
+ expect(result).toEqual({ success: true, data: 'success' });
180
+ expect(execMock).toHaveBeenCalledWith(command, { cwd: testDir }, expect.any(Function));
181
+ });
182
+ it(`${name} should handle errors`, async () => {
183
+ execMock.mockImplementation((_cmd, _opts, callback) => {
184
+ callback(new Error('operation failed'), '', 'Command failed');
185
+ return {};
186
+ });
187
+ const result = await fn(...args);
188
+ expect(result).toEqual({ success: false, error: 'Command failed' });
189
+ });
190
+ });
191
+ });
192
+ });
193
+ //# sourceMappingURL=create-pr.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-pr.test.js","sourceRoot":"","sources":["../../../../src/steps/__tests__/create-pr.test.ts"],"names":[],"mappings":";;;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AAE,KAAK,EAAE,gBAAgB,EAAE,CAAC,CAAC;YACtE,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import * as childProcess from 'node:child_process';\nimport type { ExecException } from 'node:child_process';\nimport {\n checkBranchExists,\n checkForEnvFiles,\n checkGitHubAuth,\n commitChanges,\n createBranch,\n createGitHubPR,\n getCurrentBranch,\n pushBranch,\n stageChanges,\n} from '../create-pr';\n\n// Mock dependencies\njest.mock('node:child_process', () => ({\n exec: jest.fn(),\n}));\n\ntype ExecCallback = (\n error: ExecException | null,\n stdout: string,\n stderr: string,\n) => void;\n\ntype TestCase = {\n fn: (...args: any[]) => Promise<any>;\n args: readonly any[];\n command: string;\n name: string;\n};\n\ndescribe('Git operations', () => {\n const execMock = childProcess.exec as unknown as jest.Mock;\n const testDir = '/test/dir';\n\n beforeEach(() => {\n jest.clearAllMocks();\n });\n\n describe('getCurrentBranch', () => {\n it('should return the current branch name on success', async () => {\n execMock.mockImplementation(\n (_cmd: string, _opts: any, callback: ExecCallback) => {\n callback(null, 'main', '');\n return {} as childProcess.ChildProcess;\n },\n );\n\n const result = await getCurrentBranch(testDir);\n expect(result).toEqual({ success: true, data: 'main' });\n expect(execMock).toHaveBeenCalledWith(\n 'git rev-parse --abbrev-ref HEAD',\n { cwd: testDir },\n expect.any(Function),\n );\n });\n\n it('should return error on failure', async () => {\n execMock.mockImplementation(\n (_cmd: string, _opts: any, callback: ExecCallback) => {\n callback(new Error('git error'), '', 'Failed to get branch');\n return {} as childProcess.ChildProcess;\n },\n );\n\n const result = await getCurrentBranch(testDir);\n expect(result).toEqual({ success: false, error: 'Failed to get branch' });\n });\n });\n\n describe('checkForEnvFiles', () => {\n it('should return true when .env files are found', async () => {\n execMock.mockImplementation(\n (_cmd: string, _opts: any, callback: ExecCallback) => {\n callback(null, '.env\\n.env.local', '');\n return {} as childProcess.ChildProcess;\n },\n );\n\n const result = await checkForEnvFiles(testDir);\n expect(result).toEqual({ success: true, data: true });\n });\n\n it('should return false when no .env files are found', async () => {\n const error = new Error('No match') as ExecException;\n error.code = 1;\n execMock.mockImplementation(\n (_cmd: string, _opts: any, callback: ExecCallback) => {\n callback(error, '', 'command failed with exit code 1');\n return {} as childProcess.ChildProcess;\n },\n );\n\n const result = await checkForEnvFiles(testDir);\n expect(result).toEqual({\n success: false,\n error: 'command failed with exit code 1',\n });\n });\n\n it('should handle grep errors correctly', async () => {\n execMock.mockImplementation(\n (_cmd: string, _opts: any, callback: ExecCallback) => {\n callback(new Error('grep error'), '', 'Some other error');\n return {} as childProcess.ChildProcess;\n },\n );\n\n const result = await checkForEnvFiles(testDir);\n expect(result).toEqual({ success: false, error: 'Some other error' });\n });\n });\n\n describe('checkBranchExists', () => {\n it('should return success when branch does not exist', async () => {\n execMock.mockImplementation(\n (_cmd: string, _opts: any, callback: ExecCallback) => {\n callback(new Error('branch not found'), '', 'fatal: not a valid ref');\n return {} as childProcess.ChildProcess;\n },\n );\n\n const result = await checkBranchExists('new-branch', testDir);\n expect(result).toEqual({ success: true, data: true });\n });\n\n it('should return failure when branch exists', async () => {\n execMock.mockImplementation(\n (_cmd: string, _opts: any, callback: ExecCallback) => {\n callback(null, 'ref exists', '');\n return {} as childProcess.ChildProcess;\n },\n );\n\n const result = await checkBranchExists('existing-branch', testDir);\n expect(result).toEqual({ success: false, data: false });\n });\n });\n\n describe('createGitHubPR', () => {\n it('should create PR successfully', async () => {\n const prUrl = 'https://github.com/org/repo/pull/1';\n execMock.mockImplementation(\n (_cmd: string, _opts: any, callback: ExecCallback) => {\n callback(null, prUrl, '');\n return {} as childProcess.ChildProcess;\n },\n );\n\n const result = await createGitHubPR(\n 'main',\n 'feature',\n 'title',\n 'body',\n testDir,\n );\n expect(result).toEqual({ success: true, data: prUrl });\n expect(execMock).toHaveBeenCalledWith(\n 'gh pr create --base main --head feature --title \"title\" --body \"body\"',\n { cwd: testDir },\n expect.any(Function),\n );\n });\n\n it('should handle PR creation failure', async () => {\n execMock.mockImplementation(\n (_cmd: string, _opts: any, callback: ExecCallback) => {\n callback(\n new Error('PR creation failed'),\n '',\n 'Authentication failed',\n );\n return {} as childProcess.ChildProcess;\n },\n );\n\n const result = await createGitHubPR(\n 'main',\n 'feature',\n 'title',\n 'body',\n testDir,\n );\n expect(result).toEqual({\n success: false,\n error: 'Authentication failed',\n });\n });\n });\n\n describe('Git operations', () => {\n const testCases: TestCase[] = [\n {\n fn: createBranch,\n args: ['new-branch', testDir] as const,\n command: 'git checkout -b new-branch',\n name: 'createBranch',\n },\n {\n fn: stageChanges,\n args: [testDir] as const,\n command: 'git add .',\n name: 'stageChanges',\n },\n {\n fn: commitChanges,\n args: ['commit message', testDir] as const,\n command: 'git commit -m \"commit message\"',\n name: 'commitChanges',\n },\n {\n fn: pushBranch,\n args: ['branch-name', testDir] as const,\n command: 'git push -u origin branch-name',\n name: 'pushBranch',\n },\n {\n fn: checkGitHubAuth,\n args: [testDir] as const,\n command: 'gh auth status',\n name: 'checkGitHubAuth',\n },\n ];\n\n testCases.forEach(({ fn, args, command, name }) => {\n it(`${name} should execute correctly`, async () => {\n execMock.mockImplementation(\n (_cmd: string, _opts: any, callback: ExecCallback) => {\n callback(null, 'success', '');\n return {} as childProcess.ChildProcess;\n },\n );\n\n const result = await fn(...args);\n expect(result).toEqual({ success: true, data: 'success' });\n expect(execMock).toHaveBeenCalledWith(\n command,\n { cwd: testDir },\n expect.any(Function),\n );\n });\n\n it(`${name} should handle errors`, async () => {\n execMock.mockImplementation(\n (_cmd: string, _opts: any, callback: ExecCallback) => {\n callback(new Error('operation failed'), '', 'Command failed');\n return {} as childProcess.ChildProcess;\n },\n );\n\n const result = await fn(...args);\n expect(result).toEqual({ success: false, error: 'Command failed' });\n });\n });\n });\n});\n"]}
@@ -0,0 +1,9 @@
1
+ import { Integration } from '../lib/constants';
2
+ type AddEditorRulesStepOptions = {
3
+ installDir: string;
4
+ rulesName: string;
5
+ integration: Integration;
6
+ default?: boolean;
7
+ };
8
+ export declare const addEditorRulesStep: ({ installDir, rulesName, integration, default: defaultAddEditorRules, }: AddEditorRulesStepOptions) => Promise<boolean>;
9
+ export {};
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.addEditorRulesStep = void 0;
40
+ const fs = __importStar(require("fs"));
41
+ const chalk_1 = __importDefault(require("chalk"));
42
+ const path_1 = __importDefault(require("path"));
43
+ const analytics_1 = require("../utils/analytics");
44
+ const clack_1 = __importDefault(require("../utils/clack"));
45
+ const telemetry_1 = require("../telemetry");
46
+ const clack_utils_1 = require("../utils/clack-utils");
47
+ const addEditorRulesStep = async ({ installDir, rulesName, integration, default: defaultAddEditorRules, }) => {
48
+ // Add rules file if in Cursor environment
49
+ if (process.env.CURSOR_TRACE_ID) {
50
+ const addEditorRules = defaultAddEditorRules
51
+ ? true
52
+ : await (0, clack_utils_1.abortIfCancelled)(clack_1.default.select({
53
+ message: 'Would you like to have PostHog added to your Cursor rules?',
54
+ options: [
55
+ {
56
+ label: 'Yes, please!',
57
+ value: true,
58
+ hint: 'Add PostHog to your Cursor rules',
59
+ },
60
+ {
61
+ label: 'No, thanks',
62
+ value: false,
63
+ hint: 'Skip adding PostHog to your Cursor rules',
64
+ },
65
+ ],
66
+ }));
67
+ if (!addEditorRules) {
68
+ return false;
69
+ }
70
+ return (0, telemetry_1.traceStep)('add-editor-rules', async () => {
71
+ const docsDir = path_1.default.join(installDir, '.cursor', 'rules');
72
+ await fs.promises.mkdir(docsDir, { recursive: true });
73
+ const frameworkRules = await fs.promises.readFile(path_1.default.join(__dirname, '..', 'utils', 'rules', rulesName), 'utf8');
74
+ const universalRulesPath = path_1.default.join(__dirname, '..', 'utils', 'rules', 'universal.md');
75
+ const universalRules = await fs.promises.readFile(universalRulesPath, 'utf8');
76
+ // Replace {universal} placeholder with universal rules content
77
+ const combinedRules = frameworkRules.replace('{universal}', universalRules);
78
+ const targetPath = path_1.default.join(docsDir, 'posthog-integration.mdc');
79
+ // Write the combined rules
80
+ await fs.promises.writeFile(targetPath, combinedRules, 'utf8');
81
+ analytics_1.analytics.capture('wizard interaction', {
82
+ action: 'added editor rules',
83
+ integration,
84
+ });
85
+ clack_1.default.log.info(`Added Cursor rules to ${chalk_1.default.bold.cyan(`.cursor/rules/posthog-integration.mdc`)}`);
86
+ return true;
87
+ });
88
+ }
89
+ return false;
90
+ };
91
+ exports.addEditorRulesStep = addEditorRulesStep;
92
+ //# sourceMappingURL=add-editor-rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-editor-rules.js","sourceRoot":"","sources":["../../../src/steps/add-editor-rules.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,kDAA0B;AAC1B,gDAAwB;AAExB,kDAA+C;AAC/C,2DAAmC;AACnC,4CAAyC;AACzC,sDAAwD;AASjD,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACvC,UAAU,EACV,SAAS,EACT,WAAW,EACX,OAAO,EAAE,qBAAqB,GACJ,EAAoB,EAAE;IAChD,0CAA0C;IAC1C,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC;QAChC,MAAM,cAAc,GAAY,qBAAqB;YACnD,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,MAAM,IAAA,8BAAgB,EACpB,eAAK,CAAC,MAAM,CAAC;gBACX,OAAO,EACL,4DAA4D;gBAC9D,OAAO,EAAE;oBACP;wBACE,KAAK,EAAE,cAAc;wBACrB,KAAK,EAAE,IAAI;wBACX,IAAI,EAAE,kCAAkC;qBACzC;oBACD;wBACE,KAAK,EAAE,YAAY;wBACnB,KAAK,EAAE,KAAK;wBACZ,IAAI,EAAE,0CAA0C;qBACjD;iBACF;aACF,CAAC,CACH,CAAC;QAEN,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAA,qBAAS,EAAC,kBAAkB,EAAE,KAAK,IAAI,EAAE;YAC9C,MAAM,OAAO,GAAG,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;YAE1D,MAAM,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAEtD,MAAM,cAAc,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAC/C,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,EACvD,MAAM,CACP,CAAC;YACF,MAAM,kBAAkB,GAAG,cAAI,CAAC,IAAI,CAClC,SAAS,EACT,IAAI,EACJ,OAAO,EACP,OAAO,EACP,cAAc,CACf,CAAC;YAEF,MAAM,cAAc,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAC/C,kBAAkB,EAClB,MAAM,CACP,CAAC;YAEF,+DAA+D;YAC/D,MAAM,aAAa,GAAG,cAAc,CAAC,OAAO,CAC1C,aAAa,EACb,cAAc,CACf,CAAC;YACF,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,yBAAyB,CAAC,CAAC;YAEjE,2BAA2B;YAC3B,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;YAE/D,qBAAS,CAAC,OAAO,CAAC,oBAAoB,EAAE;gBACtC,MAAM,EAAE,oBAAoB;gBAC5B,WAAW;aACZ,CAAC,CAAC;YAEH,eAAK,CAAC,GAAG,CAAC,IAAI,CACZ,yBAAyB,eAAK,CAAC,IAAI,CAAC,IAAI,CACtC,uCAAuC,CACxC,EAAE,CACJ,CAAC;YAEF,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAjFW,QAAA,kBAAkB,sBAiF7B","sourcesContent":["import * as fs from 'fs';\nimport chalk from 'chalk';\nimport path from 'path';\nimport { Integration } from '../lib/constants';\nimport { analytics } from '../utils/analytics';\nimport clack from '../utils/clack';\nimport { traceStep } from '../telemetry';\nimport { abortIfCancelled } from '../utils/clack-utils';\n\ntype AddEditorRulesStepOptions = {\n installDir: string;\n rulesName: string;\n integration: Integration;\n default?: boolean;\n};\n\nexport const addEditorRulesStep = async ({\n installDir,\n rulesName,\n integration,\n default: defaultAddEditorRules,\n}: AddEditorRulesStepOptions): Promise<boolean> => {\n // Add rules file if in Cursor environment\n if (process.env.CURSOR_TRACE_ID) {\n const addEditorRules: boolean = defaultAddEditorRules\n ? true\n : await abortIfCancelled(\n clack.select({\n message:\n 'Would you like to have PostHog added to your Cursor rules?',\n options: [\n {\n label: 'Yes, please!',\n value: true,\n hint: 'Add PostHog to your Cursor rules',\n },\n {\n label: 'No, thanks',\n value: false,\n hint: 'Skip adding PostHog to your Cursor rules',\n },\n ],\n }),\n );\n\n if (!addEditorRules) {\n return false;\n }\n\n return traceStep('add-editor-rules', async () => {\n const docsDir = path.join(installDir, '.cursor', 'rules');\n\n await fs.promises.mkdir(docsDir, { recursive: true });\n\n const frameworkRules = await fs.promises.readFile(\n path.join(__dirname, '..', 'utils', 'rules', rulesName),\n 'utf8',\n );\n const universalRulesPath = path.join(\n __dirname,\n '..',\n 'utils',\n 'rules',\n 'universal.md',\n );\n\n const universalRules = await fs.promises.readFile(\n universalRulesPath,\n 'utf8',\n );\n\n // Replace {universal} placeholder with universal rules content\n const combinedRules = frameworkRules.replace(\n '{universal}',\n universalRules,\n );\n const targetPath = path.join(docsDir, 'posthog-integration.mdc');\n\n // Write the combined rules\n await fs.promises.writeFile(targetPath, combinedRules, 'utf8');\n\n analytics.capture('wizard interaction', {\n action: 'added editor rules',\n integration,\n });\n\n clack.log.info(\n `Added Cursor rules to ${chalk.bold.cyan(\n `.cursor/rules/posthog-integration.mdc`,\n )}`,\n );\n\n return true;\n });\n }\n\n return false;\n};\n"]}
@@ -0,0 +1,10 @@
1
+ import type { Integration } from '../lib/constants';
2
+ export declare function addOrUpdateEnvironmentVariablesStep({ installDir, variables, integration, }: {
3
+ installDir: string;
4
+ variables: Record<string, string>;
5
+ integration: Integration;
6
+ }): Promise<{
7
+ relativeEnvFilePath: string;
8
+ addedEnvVariables: boolean;
9
+ addedGitignore: boolean;
10
+ }>;