@hubspot/cli 6.2.0 → 6.2.2-beta.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 (344) hide show
  1. package/README.md +12 -95
  2. package/bin/cli.d.ts +2 -0
  3. package/bin/cli.js +107 -128
  4. package/commands/accounts/clean.d.ts +1 -0
  5. package/commands/accounts/clean.js +82 -116
  6. package/commands/accounts/info.d.ts +1 -0
  7. package/commands/accounts/info.js +32 -43
  8. package/commands/accounts/list.d.ts +1 -0
  9. package/commands/accounts/list.js +65 -92
  10. package/commands/accounts/remove.d.ts +1 -0
  11. package/commands/accounts/remove.js +43 -73
  12. package/commands/accounts/rename.d.ts +1 -0
  13. package/commands/accounts/rename.js +26 -41
  14. package/commands/accounts/use.d.ts +1 -0
  15. package/commands/accounts/use.js +36 -57
  16. package/commands/accounts.d.ts +1 -0
  17. package/commands/accounts.js +16 -18
  18. package/commands/auth.d.ts +1 -0
  19. package/commands/auth.js +133 -200
  20. package/commands/cms/convertFields.d.ts +1 -0
  21. package/commands/cms/convertFields.js +66 -81
  22. package/commands/cms/lighthouseScore.d.ts +1 -0
  23. package/commands/cms/lighthouseScore.js +236 -298
  24. package/commands/cms/reactModules.d.ts +1 -0
  25. package/commands/cms/reactModules.js +46 -53
  26. package/commands/cms.d.ts +1 -0
  27. package/commands/cms.js +11 -13
  28. package/commands/config/set.d.ts +1 -0
  29. package/commands/config/set.js +64 -79
  30. package/commands/config.d.ts +1 -0
  31. package/commands/config.js +7 -9
  32. package/commands/create/api-sample.d.ts +1 -0
  33. package/commands/create/api-sample.js +54 -74
  34. package/commands/create/app.d.ts +1 -0
  35. package/commands/create/app.js +8 -7
  36. package/commands/create/function.d.ts +1 -0
  37. package/commands/create/function.js +15 -14
  38. package/commands/create/index.d.ts +1 -0
  39. package/commands/create/index.js +12 -9
  40. package/commands/create/module.d.ts +1 -0
  41. package/commands/create/module.js +21 -19
  42. package/commands/create/react-app.d.ts +1 -0
  43. package/commands/create/react-app.js +7 -6
  44. package/commands/create/template.d.ts +1 -0
  45. package/commands/create/template.js +23 -24
  46. package/commands/create/vue-app.d.ts +1 -0
  47. package/commands/create/vue-app.js +7 -6
  48. package/commands/create/webpack-serverless.d.ts +1 -0
  49. package/commands/create/webpack-serverless.js +7 -6
  50. package/commands/create/website-theme.d.ts +1 -0
  51. package/commands/create/website-theme.js +15 -15
  52. package/commands/create.d.ts +24 -0
  53. package/commands/create.js +65 -80
  54. package/commands/customObject/create.d.ts +1 -0
  55. package/commands/customObject/create.js +33 -47
  56. package/commands/customObject/schema/create.d.ts +1 -0
  57. package/commands/customObject/schema/create.js +42 -67
  58. package/commands/customObject/schema/delete.d.ts +1 -0
  59. package/commands/customObject/schema/delete.js +28 -39
  60. package/commands/customObject/schema/fetch-all.d.ts +1 -0
  61. package/commands/customObject/schema/fetch-all.js +30 -39
  62. package/commands/customObject/schema/fetch.d.ts +1 -0
  63. package/commands/customObject/schema/fetch.js +48 -63
  64. package/commands/customObject/schema/list.d.ts +1 -0
  65. package/commands/customObject/schema/list.js +14 -17
  66. package/commands/customObject/schema/update.d.ts +1 -0
  67. package/commands/customObject/schema/update.js +46 -72
  68. package/commands/customObject/schema.d.ts +1 -0
  69. package/commands/customObject/schema.js +12 -12
  70. package/commands/customObject.d.ts +1 -0
  71. package/commands/customObject.js +14 -22
  72. package/commands/feedback.d.ts +1 -0
  73. package/commands/feedback.js +25 -33
  74. package/commands/fetch.d.ts +1 -0
  75. package/commands/fetch.js +53 -78
  76. package/commands/filemanager/fetch.d.ts +1 -0
  77. package/commands/filemanager/fetch.js +38 -56
  78. package/commands/filemanager/upload.d.ts +1 -0
  79. package/commands/filemanager/upload.js +88 -128
  80. package/commands/filemanager.d.ts +1 -0
  81. package/commands/filemanager.js +12 -18
  82. package/commands/functions/deploy.d.ts +1 -0
  83. package/commands/functions/deploy.js +76 -99
  84. package/commands/functions/list.d.ts +1 -0
  85. package/commands/functions/list.js +41 -48
  86. package/commands/functions/server.d.ts +1 -0
  87. package/commands/functions/server.js +50 -65
  88. package/commands/functions.d.ts +1 -0
  89. package/commands/functions.js +13 -15
  90. package/commands/hubdb/clear.d.ts +1 -0
  91. package/commands/hubdb/clear.js +37 -56
  92. package/commands/hubdb/create.d.ts +1 -0
  93. package/commands/hubdb/create.js +34 -57
  94. package/commands/hubdb/delete.d.ts +1 -0
  95. package/commands/hubdb/delete.js +29 -44
  96. package/commands/hubdb/fetch.d.ts +1 -0
  97. package/commands/hubdb/fetch.js +30 -46
  98. package/commands/hubdb.d.ts +1 -0
  99. package/commands/hubdb.js +12 -14
  100. package/commands/init.d.ts +1 -0
  101. package/commands/init.js +103 -160
  102. package/commands/lint.d.ts +1 -0
  103. package/commands/lint.js +34 -45
  104. package/commands/list.d.ts +1 -0
  105. package/commands/list.js +74 -101
  106. package/commands/logs.d.ts +1 -0
  107. package/commands/logs.js +98 -121
  108. package/commands/module/marketplace-validate.d.ts +1 -0
  109. package/commands/module/marketplace-validate.js +32 -57
  110. package/commands/module.d.ts +1 -0
  111. package/commands/module.js +7 -9
  112. package/commands/mv.d.ts +1 -0
  113. package/commands/mv.js +53 -71
  114. package/commands/open.d.ts +1 -0
  115. package/commands/open.js +48 -62
  116. package/commands/project/add.d.ts +1 -0
  117. package/commands/project/add.js +47 -70
  118. package/commands/project/cloneApp.d.ts +1 -0
  119. package/commands/project/cloneApp.js +119 -180
  120. package/commands/project/create.d.ts +1 -0
  121. package/commands/project/create.js +49 -81
  122. package/commands/project/deploy.d.ts +1 -0
  123. package/commands/project/deploy.js +105 -182
  124. package/commands/project/dev.d.ts +1 -0
  125. package/commands/project/dev.js +126 -227
  126. package/commands/project/download.d.ts +1 -0
  127. package/commands/project/download.js +73 -123
  128. package/commands/project/installDeps.d.ts +1 -0
  129. package/commands/project/installDeps.js +52 -59
  130. package/commands/project/listBuilds.d.ts +1 -0
  131. package/commands/project/listBuilds.js +97 -139
  132. package/commands/project/logs.d.ts +1 -0
  133. package/commands/project/logs.js +86 -128
  134. package/commands/project/migrateApp.d.ts +1 -0
  135. package/commands/project/migrateApp.js +158 -248
  136. package/commands/project/open.d.ts +1 -0
  137. package/commands/project/open.js +44 -68
  138. package/commands/project/upload.d.ts +1 -0
  139. package/commands/project/upload.js +72 -116
  140. package/commands/project/watch.d.ts +1 -0
  141. package/commands/project/watch.js +94 -152
  142. package/commands/project.d.ts +1 -0
  143. package/commands/project.js +21 -23
  144. package/commands/remove.d.ts +1 -0
  145. package/commands/remove.js +28 -43
  146. package/commands/sandbox/create.d.ts +1 -0
  147. package/commands/sandbox/create.js +143 -187
  148. package/commands/sandbox/delete.d.ts +1 -0
  149. package/commands/sandbox/delete.js +166 -221
  150. package/commands/sandbox.d.ts +1 -0
  151. package/commands/sandbox.js +10 -12
  152. package/commands/secrets/addSecret.d.ts +1 -0
  153. package/commands/secrets/addSecret.js +34 -52
  154. package/commands/secrets/deleteSecret.d.ts +1 -0
  155. package/commands/secrets/deleteSecret.js +33 -50
  156. package/commands/secrets/listSecrets.d.ts +1 -0
  157. package/commands/secrets/listSecrets.js +28 -42
  158. package/commands/secrets/updateSecret.d.ts +1 -0
  159. package/commands/secrets/updateSecret.js +35 -53
  160. package/commands/secrets.d.ts +1 -0
  161. package/commands/secrets.js +12 -13
  162. package/commands/theme/generate-selectors.d.ts +1 -0
  163. package/commands/theme/generate-selectors.js +129 -192
  164. package/commands/theme/marketplace-validate.d.ts +1 -0
  165. package/commands/theme/marketplace-validate.js +32 -57
  166. package/commands/theme/preview.d.ts +1 -0
  167. package/commands/theme/preview.js +170 -195
  168. package/commands/theme.d.ts +1 -0
  169. package/commands/theme.js +9 -11
  170. package/commands/upload.d.ts +1 -0
  171. package/commands/upload.js +199 -287
  172. package/commands/watch.d.ts +1 -0
  173. package/commands/watch.js +128 -172
  174. package/lang/en.lyaml +2 -3
  175. package/lib/DevServerManager.d.ts +1 -0
  176. package/lib/DevServerManager.js +99 -124
  177. package/lib/LocalDevManager.d.ts +1 -0
  178. package/lib/LocalDevManager.js +322 -490
  179. package/lib/accountTypes.d.ts +7 -0
  180. package/lib/accountTypes.js +32 -34
  181. package/lib/buildAccount.d.ts +1 -0
  182. package/lib/buildAccount.js +132 -179
  183. package/lib/commonOpts.d.ts +1 -0
  184. package/lib/commonOpts.js +60 -91
  185. package/lib/configOptions.d.ts +1 -0
  186. package/lib/configOptions.js +110 -0
  187. package/lib/constants.d.ts +84 -0
  188. package/lib/constants.js +64 -91
  189. package/lib/debugInfo.d.ts +1 -0
  190. package/lib/debugInfo.js +14 -13
  191. package/lib/dependencyManagement.d.ts +1 -0
  192. package/lib/dependencyManagement.js +92 -132
  193. package/lib/developerTestAccounts.d.ts +1 -0
  194. package/lib/developerTestAccounts.js +67 -91
  195. package/lib/enums/exitCodes.d.ts +5 -0
  196. package/lib/enums/exitCodes.js +7 -8
  197. package/lib/environment.d.ts +1 -0
  198. package/lib/environment.js +13 -14
  199. package/lib/errorHandlers/index.d.ts +1 -0
  200. package/lib/errorHandlers/index.js +66 -80
  201. package/lib/errorHandlers/suppressError.d.ts +1 -0
  202. package/lib/errorHandlers/suppressError.js +66 -106
  203. package/lib/filesystem.d.ts +2 -0
  204. package/lib/filesystem.js +22 -28
  205. package/lib/generate-selectors.d.ts +1 -0
  206. package/lib/generate-selectors.js +102 -138
  207. package/lib/hasFeature.d.ts +1 -0
  208. package/lib/hasFeature.js +8 -15
  209. package/lib/hasFlag.d.ts +1 -0
  210. package/lib/hasFlag.js +13 -13
  211. package/lib/hublValidate.d.ts +2 -0
  212. package/lib/hublValidate.js +28 -28
  213. package/lib/interpolation.d.ts +1 -0
  214. package/lib/interpolation.js +50 -92
  215. package/lib/interpolationHelpers.d.ts +10 -0
  216. package/lib/interpolationHelpers.js +30 -22
  217. package/lib/lang.d.ts +1 -0
  218. package/lib/lang.js +52 -78
  219. package/lib/links.d.ts +1 -0
  220. package/lib/links.js +94 -114
  221. package/lib/localDev.d.ts +1 -0
  222. package/lib/localDev.js +285 -433
  223. package/lib/marketplace-validate.d.ts +1 -0
  224. package/lib/marketplace-validate.js +105 -126
  225. package/lib/oauth.d.ts +1 -0
  226. package/lib/oauth.js +64 -78
  227. package/lib/polling.d.ts +1 -0
  228. package/lib/polling.js +26 -26
  229. package/lib/process.d.ts +1 -0
  230. package/lib/process.js +41 -53
  231. package/lib/projectLogsManager.d.ts +1 -0
  232. package/lib/projectLogsManager.js +78 -130
  233. package/lib/projectStructure.d.ts +1 -0
  234. package/lib/projectStructure.js +89 -109
  235. package/lib/projects.d.ts +1 -0
  236. package/lib/projects.js +595 -958
  237. package/lib/projectsWatch.d.ts +1 -0
  238. package/lib/projectsWatch.js +127 -228
  239. package/lib/prompts/accountNamePrompt.d.ts +1 -0
  240. package/lib/prompts/accountNamePrompt.js +60 -65
  241. package/lib/prompts/accountsPrompt.d.ts +1 -0
  242. package/lib/prompts/accountsPrompt.js +33 -37
  243. package/lib/prompts/activeInstallConfirmationPrompt.d.ts +1 -0
  244. package/lib/prompts/activeInstallConfirmationPrompt.js +13 -13
  245. package/lib/prompts/cleanUploadPrompt.d.ts +1 -0
  246. package/lib/prompts/cleanUploadPrompt.js +13 -13
  247. package/lib/prompts/cmsFieldPrompt.d.ts +1 -0
  248. package/lib/prompts/cmsFieldPrompt.js +37 -39
  249. package/lib/prompts/createApiSamplePrompt.d.ts +1 -0
  250. package/lib/prompts/createApiSamplePrompt.js +49 -52
  251. package/lib/prompts/createFunctionPrompt.d.ts +1 -0
  252. package/lib/prompts/createFunctionPrompt.js +57 -56
  253. package/lib/prompts/createModulePrompt.d.ts +1 -0
  254. package/lib/prompts/createModulePrompt.js +47 -50
  255. package/lib/prompts/createProjectPrompt.d.ts +1 -0
  256. package/lib/prompts/createProjectPrompt.js +95 -129
  257. package/lib/prompts/createTemplatePrompt.d.ts +1 -0
  258. package/lib/prompts/createTemplatePrompt.js +18 -19
  259. package/lib/prompts/deployBuildIdPrompt.d.ts +1 -0
  260. package/lib/prompts/deployBuildIdPrompt.js +15 -15
  261. package/lib/prompts/downloadProjectPrompt.d.ts +1 -0
  262. package/lib/prompts/downloadProjectPrompt.js +39 -41
  263. package/lib/prompts/feedbackPrompt.d.ts +1 -0
  264. package/lib/prompts/feedbackPrompt.js +29 -30
  265. package/lib/prompts/folderOverwritePrompt.d.ts +1 -0
  266. package/lib/prompts/folderOverwritePrompt.js +10 -10
  267. package/lib/prompts/installPublicAppPrompt.d.ts +1 -0
  268. package/lib/prompts/installPublicAppPrompt.js +29 -42
  269. package/lib/prompts/personalAccessKeyPrompt.d.ts +1 -0
  270. package/lib/prompts/personalAccessKeyPrompt.js +104 -110
  271. package/lib/prompts/previewPrompt.d.ts +1 -0
  272. package/lib/prompts/previewPrompt.js +46 -47
  273. package/lib/prompts/projectAddPrompt.d.ts +1 -0
  274. package/lib/prompts/projectAddPrompt.js +37 -38
  275. package/lib/prompts/projectDevTargetAccountPrompt.d.ts +1 -0
  276. package/lib/prompts/projectDevTargetAccountPrompt.js +150 -193
  277. package/lib/prompts/projectNamePrompt.d.ts +1 -0
  278. package/lib/prompts/projectNamePrompt.js +25 -25
  279. package/lib/prompts/projectsLogsPrompt.d.ts +1 -0
  280. package/lib/prompts/projectsLogsPrompt.js +21 -27
  281. package/lib/prompts/promptUtils.d.ts +1 -0
  282. package/lib/prompts/promptUtils.js +17 -17
  283. package/lib/prompts/sandboxesPrompt.d.ts +1 -0
  284. package/lib/prompts/sandboxesPrompt.js +50 -59
  285. package/lib/prompts/secretPrompt.d.ts +1 -0
  286. package/lib/prompts/secretPrompt.js +15 -16
  287. package/lib/prompts/selectPublicAppPrompt.d.ts +1 -0
  288. package/lib/prompts/selectPublicAppPrompt.js +58 -82
  289. package/lib/prompts/setAsDefaultAccountPrompt.d.ts +1 -0
  290. package/lib/prompts/setAsDefaultAccountPrompt.js +19 -24
  291. package/lib/prompts/uploadPrompt.d.ts +1 -0
  292. package/lib/prompts/uploadPrompt.js +30 -30
  293. package/lib/regex.d.ts +1 -0
  294. package/lib/regex.js +4 -5
  295. package/lib/sandboxSync.d.ts +1 -0
  296. package/lib/sandboxSync.js +100 -166
  297. package/lib/sandboxes.d.ts +1 -0
  298. package/lib/sandboxes.js +201 -316
  299. package/lib/schema.d.ts +3 -0
  300. package/lib/schema.js +29 -33
  301. package/lib/serverlessLogs.d.ts +1 -0
  302. package/lib/serverlessLogs.js +131 -173
  303. package/lib/ui/SpinniesManager.d.ts +1 -0
  304. package/lib/ui/SpinniesManager.js +198 -254
  305. package/lib/ui/git.d.ts +1 -0
  306. package/lib/ui/git.js +20 -19
  307. package/lib/ui/index.d.ts +1 -0
  308. package/lib/ui/index.js +117 -167
  309. package/lib/ui/serverlessFunctionLogs.d.ts +1 -0
  310. package/lib/ui/serverlessFunctionLogs.js +53 -70
  311. package/lib/ui/spinniesUtils.d.ts +1 -0
  312. package/lib/ui/spinniesUtils.js +111 -133
  313. package/lib/ui/supportHyperlinks.d.ts +1 -0
  314. package/lib/ui/supportHyperlinks.js +49 -62
  315. package/lib/ui/supportsColor.d.ts +1 -0
  316. package/lib/ui/supportsColor.js +81 -109
  317. package/lib/ui/table.d.ts +1 -0
  318. package/lib/ui/table.js +49 -55
  319. package/lib/upload.d.ts +1 -0
  320. package/lib/upload.js +40 -43
  321. package/lib/usageTracking.d.ts +1 -0
  322. package/lib/usageTracking.js +133 -155
  323. package/lib/validation.d.ts +1 -0
  324. package/lib/validation.js +144 -203
  325. package/package.json +84 -48
  326. package/CHANGELOG.md +0 -16
  327. package/commands/__tests__/projects.test.js +0 -105
  328. package/commands/config/set/allowUsageTracking.js +0 -52
  329. package/commands/config/set/defaultMode.js +0 -59
  330. package/commands/config/set/httpTimeout.js +0 -42
  331. package/commands/project/__tests__/deploy.test.js +0 -443
  332. package/commands/project/__tests__/installDeps.test.js +0 -168
  333. package/commands/project/__tests__/logs.test.js +0 -304
  334. package/hubspot.sample.config.yml +0 -28
  335. package/jest.config.js +0 -4
  336. package/lib/__tests__/commonOpts.test.js +0 -83
  337. package/lib/__tests__/dependencyManagement.test.js +0 -243
  338. package/lib/__tests__/downloadProjectPrompt.test.js +0 -31
  339. package/lib/__tests__/projectLogsManager.test.js +0 -212
  340. package/lib/__tests__/projects.test.js +0 -140
  341. package/lib/__tests__/serverlessLogs.test.js +0 -162
  342. package/lib/__tests__/validation.test.js +0 -140
  343. package/lib/getFunctionArrays.js +0 -18
  344. package/lib/prompts/__tests__/projectsLogsPrompt.test.js +0 -46
@@ -1,243 +0,0 @@
1
- jest.mock('../projects');
2
- jest.mock('@hubspot/local-dev-lib/logger');
3
- jest.mock('@hubspot/local-dev-lib/fs');
4
- jest.mock('../ui/SpinniesManager');
5
- jest.mock('fs', () => ({
6
- ...jest.requireActual('fs'),
7
- existsSync: jest.fn().mockReturnValue(true),
8
- }));
9
-
10
- const util = require('util');
11
- const {
12
- isGloballyInstalled,
13
- installPackages,
14
- getProjectPackageJsonLocations,
15
- } = require('../dependencyManagement');
16
- const { walk } = require('@hubspot/local-dev-lib/fs');
17
- const path = require('path');
18
- const { getProjectConfig } = require('../projects');
19
- const SpinniesManager = require('../ui/SpinniesManager');
20
- const { existsSync } = require('fs');
21
-
22
- describe('cli/lib/dependencyManagement', () => {
23
- let execMock;
24
-
25
- const projectDir = path.join('path', 'to', 'project');
26
- const srcDir = 'src';
27
- const appDir = path.join(projectDir, srcDir, 'app');
28
- const appFunctionsDir = path.join(appDir, 'app.functions');
29
- const extensionsDir = path.join(appDir, 'exensions');
30
- const projectName = 'super cool test project';
31
- const installLocations = [appFunctionsDir, extensionsDir];
32
-
33
- beforeEach(() => {
34
- execMock = jest.fn();
35
- util.promisify = jest.fn().mockReturnValue(execMock);
36
- getProjectConfig.mockResolvedValue({
37
- projectDir,
38
- projectConfig: {
39
- srcDir,
40
- name: projectName,
41
- },
42
- });
43
- });
44
-
45
- describe('isGloballyInstalled', () => {
46
- it('should return true when exec is successful', async () => {
47
- const actual = await isGloballyInstalled('npm');
48
- expect(actual).toBe(true);
49
- expect(execMock).toHaveBeenCalledTimes(1);
50
- expect(execMock).toHaveBeenCalledWith('npm --version');
51
- });
52
-
53
- it('should return false when exec is unsuccessful', async () => {
54
- execMock = jest.fn().mockImplementationOnce(() => {
55
- throw new Error('unsuccessful');
56
- });
57
- util.promisify = jest.fn().mockReturnValueOnce(execMock);
58
- const actual = await isGloballyInstalled('npm');
59
- expect(actual).toBe(false);
60
- expect(execMock).toHaveBeenCalledTimes(1);
61
- expect(execMock).toHaveBeenCalledWith('npm --version');
62
- });
63
- });
64
-
65
- describe('installPackages', () => {
66
- it('should setup a loading spinner', async () => {
67
- const packages = ['package1', 'package2'];
68
- await installPackages({ packages, installLocations });
69
- expect(SpinniesManager.init).toHaveBeenCalledTimes(
70
- installLocations.length
71
- );
72
- expect(SpinniesManager.add).toHaveBeenCalledTimes(
73
- installLocations.length
74
- );
75
- expect(SpinniesManager.succeed).toHaveBeenCalledTimes(
76
- installLocations.length
77
- );
78
- });
79
-
80
- it('should install the provided packages in all the provided install locations', async () => {
81
- const packages = ['package1', 'package2'];
82
- await installPackages({ packages, installLocations });
83
-
84
- expect(execMock).toHaveBeenCalledTimes(installLocations.length);
85
- expect(SpinniesManager.add).toHaveBeenCalledTimes(
86
- installLocations.length
87
- );
88
- expect(SpinniesManager.succeed).toHaveBeenCalledTimes(
89
- installLocations.length
90
- );
91
-
92
- for (const location of installLocations) {
93
- expect(execMock).toHaveBeenCalledWith(`npm install package1 package2`, {
94
- cwd: location,
95
- });
96
- expect(SpinniesManager.add).toHaveBeenCalledWith(
97
- `installingDependencies-${location}`,
98
- {
99
- text: `Installing [package1, package2] in ${location}`,
100
- }
101
- );
102
- expect(SpinniesManager.succeed).toHaveBeenCalledWith(
103
- `installingDependencies-${location}`,
104
- {
105
- text: `Installed dependencies in ${location}`,
106
- }
107
- );
108
- }
109
- });
110
-
111
- it('should use the provided install locations', async () => {
112
- await installPackages({ installLocations });
113
- expect(execMock).toHaveBeenCalledTimes(installLocations.length);
114
- expect(execMock).toHaveBeenCalledWith(`npm install`, {
115
- cwd: appFunctionsDir,
116
- });
117
- expect(execMock).toHaveBeenCalledWith(`npm install`, {
118
- cwd: extensionsDir,
119
- });
120
- });
121
-
122
- it('should locate the projects package.json files when install locations is not provided', async () => {
123
- const installLocations = [
124
- path.join(appFunctionsDir, 'package.json'),
125
- path.join(extensionsDir, 'package.json'),
126
- ];
127
-
128
- walk.mockResolvedValue(installLocations);
129
-
130
- getProjectConfig.mockResolvedValue({
131
- projectDir,
132
- projectConfig: {
133
- srcDir,
134
- },
135
- });
136
-
137
- await installPackages({});
138
- // It's called once per each install location, plus once to check if npm installed
139
- expect(execMock).toHaveBeenCalledTimes(installLocations.length + 1);
140
- expect(execMock).toHaveBeenCalledWith(`npm install`, {
141
- cwd: appFunctionsDir,
142
- });
143
- expect(execMock).toHaveBeenCalledWith(`npm install`, {
144
- cwd: extensionsDir,
145
- });
146
- });
147
-
148
- it('should throw an error when installing the dependencies fails', async () => {
149
- execMock = jest.fn().mockImplementation(command => {
150
- if (command !== 'npm --version') {
151
- throw new Error('OH NO');
152
- }
153
- });
154
-
155
- util.promisify = jest.fn().mockReturnValue(execMock);
156
-
157
- const installLocations = [
158
- path.join(appFunctionsDir, 'package.json'),
159
- path.join(extensionsDir, 'package.json'),
160
- ];
161
-
162
- walk.mockResolvedValue(installLocations);
163
-
164
- getProjectConfig.mockResolvedValue({
165
- projectDir,
166
- projectConfig: {
167
- srcDir,
168
- },
169
- });
170
-
171
- await expect(() => installPackages({})).rejects.toThrowError(
172
- `Installing dependencies for ${appFunctionsDir} failed`
173
- );
174
-
175
- expect(SpinniesManager.fail).toHaveBeenCalledTimes(
176
- installLocations.length
177
- );
178
-
179
- expect(SpinniesManager.fail).toHaveBeenCalledWith(
180
- `installingDependencies-${appFunctionsDir}`,
181
- {
182
- text: `Installing dependencies for ${appFunctionsDir} failed`,
183
- }
184
- );
185
- expect(SpinniesManager.fail).toHaveBeenCalledWith(
186
- `installingDependencies-${extensionsDir}`,
187
- {
188
- text: `Installing dependencies for ${extensionsDir} failed`,
189
- }
190
- );
191
- });
192
- });
193
-
194
- describe('getProjectPackageJsonFiles', () => {
195
- it('should throw an error when ran outside the boundary of a project', async () => {
196
- getProjectConfig.mockResolvedValue({});
197
- await expect(() => getProjectPackageJsonLocations()).rejects.toThrowError(
198
- 'No project detected. Run this command from a project directory.'
199
- );
200
- });
201
-
202
- it('should throw an error if npm is not globally installed', async () => {
203
- execMock = jest.fn().mockImplementation(() => {
204
- throw new Error('OH NO');
205
- });
206
- util.promisify = jest.fn().mockReturnValue(execMock);
207
- await expect(() => getProjectPackageJsonLocations()).rejects.toThrowError(
208
- /This command depends on npm, install/
209
- );
210
- });
211
-
212
- it('should throw an error if the project directory does not exist', async () => {
213
- existsSync.mockReturnValueOnce(false);
214
- await expect(() => getProjectPackageJsonLocations()).rejects.toThrowError(
215
- `No dependencies to install. The project ${projectName} folder might be missing component or subcomponent files. Learn how to create a project from scratch.: https://developers.hubspot.com/beta-docs/guides/crm/intro/create-a-project`
216
- );
217
- });
218
-
219
- it('should ignore package.json files in certain directories', async () => {
220
- const nodeModulesDir = path.join(appDir, 'node_modules');
221
- const viteDir = path.join(appDir, '.vite');
222
- const installLocations = [
223
- path.join(appFunctionsDir, 'package.json'),
224
- path.join(extensionsDir, 'package.json'),
225
- path.join(viteDir, 'package.json'),
226
- path.join(nodeModulesDir, 'package.json'),
227
- ];
228
-
229
- walk.mockResolvedValue(installLocations);
230
-
231
- const actual = await getProjectPackageJsonLocations();
232
- expect(actual).toEqual([appFunctionsDir, extensionsDir]);
233
- });
234
-
235
- it('should throw an error if no package.json files are found', async () => {
236
- walk.mockResolvedValue([]);
237
-
238
- await expect(() => getProjectPackageJsonLocations()).rejects.toThrowError(
239
- `No dependencies to install. The project ${projectName} folder might be missing component or subcomponent files. Learn how to create a project from scratch.: https://developers.hubspot.com/beta-docs/guides/crm/intro/create-a-project`
240
- );
241
- });
242
- });
243
- });
@@ -1,31 +0,0 @@
1
- jest.mock('@hubspot/local-dev-lib/api/projects', () => ({
2
- fetchProjects: jest.fn().mockResolvedValue({
3
- data: { results: [] },
4
- }),
5
- }));
6
-
7
- jest.mock('@hubspot/local-dev-lib/config', () => ({
8
- getAccountId: jest.fn().mockImplementation(() => 123456789),
9
- }));
10
-
11
- jest.mock('../prompts/promptUtils');
12
-
13
- const { downloadProjectPrompt } = require('../prompts/downloadProjectPrompt');
14
- const { getAccountId } = require('@hubspot/local-dev-lib/config');
15
- const { fetchProjects } = require('@hubspot/local-dev-lib/api/projects');
16
-
17
- describe('downloadProjectPrompt', () => {
18
- it('should honor the account passed as an option', async () => {
19
- const account = 'Prod';
20
- await downloadProjectPrompt({ account });
21
- expect(getAccountId).toHaveBeenCalledTimes(1);
22
- expect(getAccountId).toHaveBeenCalledWith(account);
23
- });
24
-
25
- it('should fetch the projects for the correct accountId', async () => {
26
- const account = 'Prod';
27
- await downloadProjectPrompt({ account });
28
- expect(fetchProjects).toHaveBeenCalledTimes(1);
29
- expect(fetchProjects).toHaveBeenCalledWith(123456789);
30
- });
31
- });
@@ -1,212 +0,0 @@
1
- jest.mock('../projects');
2
- jest.mock('@hubspot/local-dev-lib/api/projects');
3
-
4
- const ProjectLogsManager = require('../projectLogsManager');
5
- const { getProjectConfig, ensureProjectExists } = require('../projects');
6
- const {
7
- fetchProjectComponentsMetadata,
8
- } = require('@hubspot/local-dev-lib/api/projects');
9
-
10
- describe('cli/lib/projectLogsManager', () => {
11
- const accountId = 12345678;
12
- const appId = 999999;
13
- const projectName = 'super cool test project';
14
- const projectConfig = { projectConfig: { name: projectName } };
15
- const projectId = 987654321;
16
- const projectDetails = {
17
- project: {
18
- id: projectId,
19
- deployedBuild: {
20
- subbuildStatuses: {},
21
- },
22
- },
23
- };
24
-
25
- const function1 = {
26
- componentName: 'function1',
27
- type: {
28
- name: 'APP_FUNCTION',
29
- },
30
- deployOutput: {
31
- appId,
32
- },
33
- };
34
- const functions = [
35
- function1,
36
- {
37
- componentName: 'function2',
38
- type: {
39
- name: 'APP_FUNCTION',
40
- },
41
- deployOutput: {
42
- appId,
43
- },
44
- },
45
- ];
46
-
47
- beforeEach(() => {
48
- ProjectLogsManager.reset();
49
-
50
- getProjectConfig.mockResolvedValue(projectConfig);
51
- ensureProjectExists.mockResolvedValue(projectDetails);
52
- fetchProjectComponentsMetadata.mockResolvedValue({
53
- data: {
54
- topLevelComponentMetadata: [
55
- {
56
- type: {
57
- name: 'PRIVATE_APP',
58
- },
59
- deployOutput: {
60
- appId,
61
- },
62
- featureComponents: [
63
- ...functions,
64
- {
65
- type: {
66
- name: 'NOT_AN_APP_FUNCTION',
67
- },
68
- },
69
- ],
70
- },
71
- ],
72
- },
73
- });
74
- });
75
-
76
- describe('init', () => {
77
- it('should load the project config', async () => {
78
- await ProjectLogsManager.init(accountId);
79
- expect(getProjectConfig).toHaveBeenCalledTimes(1);
80
- });
81
-
82
- it('should throw an error if there is a problem with the config', async () => {
83
- getProjectConfig.mockResolvedValue({});
84
- await expect(async () =>
85
- ProjectLogsManager.init(accountId)
86
- ).rejects.toThrow(
87
- 'No project detected. Run this command again from a project directory.'
88
- );
89
- expect(getProjectConfig).toHaveBeenCalledTimes(1);
90
- });
91
-
92
- it('should ensure the project exists', async () => {
93
- await ProjectLogsManager.init(accountId);
94
- expect(ensureProjectExists).toHaveBeenCalledTimes(1);
95
- expect(ensureProjectExists).toHaveBeenCalledWith(accountId, projectName, {
96
- allowCreate: false,
97
- });
98
- });
99
-
100
- it('should throw an error if there is data missing from the project details', async () => {
101
- ensureProjectExists.mockResolvedValue({});
102
- await expect(async () =>
103
- ProjectLogsManager.init(accountId)
104
- ).rejects.toThrow(/There was an error fetching project details/);
105
- });
106
-
107
- it('should set all of the expected fields correctly', async () => {
108
- await ProjectLogsManager.init(accountId);
109
- expect(ProjectLogsManager.projectId).toEqual(projectId);
110
- expect(ProjectLogsManager.projectName).toEqual(projectName);
111
- expect(ProjectLogsManager.accountId).toEqual(accountId);
112
- expect(ProjectLogsManager.functions).toEqual(functions);
113
- });
114
- });
115
-
116
- describe('fetchFunctionDetails', () => {
117
- it('should throw an error if the projectId is null when the method is called', async () => {
118
- await expect(async () =>
119
- ProjectLogsManager.fetchFunctionDetails()
120
- ).rejects.toThrow(
121
- 'No project detected. Run this command again from a project directory.'
122
- );
123
- });
124
-
125
- it('should fetch the component metadata', async () => {
126
- ProjectLogsManager.projectId = projectId;
127
- ProjectLogsManager.accountId = accountId;
128
- await ProjectLogsManager.fetchFunctionDetails();
129
- expect(fetchProjectComponentsMetadata).toHaveBeenCalledTimes(1);
130
- expect(fetchProjectComponentsMetadata).toHaveBeenCalledWith(
131
- accountId,
132
- projectId
133
- );
134
- });
135
-
136
- it('should set the functions correctly', async () => {
137
- ProjectLogsManager.projectId = projectId;
138
- ProjectLogsManager.accountId = accountId;
139
- await ProjectLogsManager.fetchFunctionDetails();
140
- expect(ProjectLogsManager.functions).toEqual(functions);
141
- });
142
- });
143
-
144
- describe('getFunctionNames', () => {
145
- it('should return an empty array if functions is nullable', async () => {
146
- ProjectLogsManager.functions = undefined;
147
- expect(ProjectLogsManager.getFunctionNames()).toEqual([]);
148
- });
149
-
150
- it('should return an array of the componentNames', async () => {
151
- ProjectLogsManager.functions = functions;
152
- expect(ProjectLogsManager.getFunctionNames()).toEqual([
153
- 'function1',
154
- 'function2',
155
- ]);
156
- });
157
- });
158
-
159
- describe('setFunction', () => {
160
- it('should throw an error when functions is nullable', async () => {
161
- ProjectLogsManager.functions = undefined;
162
- expect(() => ProjectLogsManager.setFunction('foo')).toThrow(
163
- `There aren't any functions in this project`
164
- );
165
- });
166
-
167
- it('should throw an error when the provided function is invalid', async () => {
168
- ProjectLogsManager.functions = functions;
169
- const badName = 'foo';
170
- expect(() => ProjectLogsManager.setFunction(badName)).toThrow(
171
- `No function with name "${badName}"`
172
- );
173
- });
174
-
175
- it('should set the data correctly for public functions', async () => {
176
- const functionToChoose = {
177
- componentName: 'function1',
178
- type: {
179
- name: 'APP_FUNCTION',
180
- },
181
- deployOutput: {
182
- endpoint: { path: 'yooooooo', method: ['GET'] },
183
- },
184
- };
185
- ProjectLogsManager.functions = [functionToChoose];
186
- ProjectLogsManager.setFunction('function1');
187
- expect(ProjectLogsManager.functionName).toEqual('function1');
188
- expect(ProjectLogsManager.endpointName).toEqual('yooooooo');
189
- expect(ProjectLogsManager.selectedFunction).toEqual(functionToChoose);
190
- expect(ProjectLogsManager.method).toEqual(['GET']);
191
- expect(ProjectLogsManager.isPublicFunction).toEqual(true);
192
- });
193
-
194
- it('should set the data correctly for public functions', async () => {
195
- ProjectLogsManager.functions = functions;
196
- ProjectLogsManager.setFunction('function1');
197
- expect(ProjectLogsManager.selectedFunction).toEqual(function1);
198
- expect(ProjectLogsManager.functionName).toEqual('function1');
199
- expect(ProjectLogsManager.isPublicFunction).toEqual(false);
200
- });
201
- });
202
-
203
- describe('reset', () => {
204
- it('should reset all the values', async () => {
205
- ProjectLogsManager.someRandomField = 'value';
206
- expect(ProjectLogsManager.someRandomField).toBeDefined();
207
-
208
- ProjectLogsManager.reset();
209
- expect(ProjectLogsManager.isPublicFunction).toBeUndefined();
210
- });
211
- });
212
- });
@@ -1,140 +0,0 @@
1
- jest.mock('@hubspot/local-dev-lib/logger');
2
-
3
- const fs = require('fs');
4
- const os = require('os');
5
- const path = require('path');
6
- const { EXIT_CODES } = require('../enums/exitCodes');
7
- const projects = require('../projects');
8
- const { logger } = require('@hubspot/local-dev-lib/logger');
9
-
10
- describe('@hubspot/cli/lib/projects', () => {
11
- describe('validateProjectConfig()', () => {
12
- let realProcess;
13
- let projectDir;
14
- let exitMock;
15
-
16
- beforeAll(() => {
17
- projectDir = fs.mkdtempSync(path.join(os.tmpdir(), 'projects-'));
18
- fs.mkdirSync(path.join(projectDir, 'src'));
19
-
20
- realProcess = process;
21
- });
22
-
23
- beforeEach(() => {
24
- exitMock = jest.fn();
25
- global.process = { ...realProcess, exit: exitMock };
26
- });
27
-
28
- afterAll(() => {
29
- global.process = realProcess;
30
- });
31
-
32
- it('rejects undefined configuration', () => {
33
- projects.validateProjectConfig(null, projectDir);
34
-
35
- expect(exitMock).toHaveBeenCalledWith(EXIT_CODES.ERROR);
36
- expect(logger.error).toHaveBeenCalledWith(
37
- expect.stringMatching(/.*config not found.*/)
38
- );
39
- });
40
-
41
- it('rejects configuration with missing name', () => {
42
- projects.validateProjectConfig({ srcDir: '.' }, projectDir);
43
-
44
- expect(exitMock).toHaveBeenCalledWith(EXIT_CODES.ERROR);
45
- expect(logger.error).toHaveBeenCalledWith(
46
- expect.stringMatching(/.*missing required fields*/)
47
- );
48
- });
49
-
50
- it('rejects configuration with missing srcDir', () => {
51
- projects.validateProjectConfig({ name: 'hello' }, projectDir);
52
-
53
- expect(exitMock).toHaveBeenCalledWith(EXIT_CODES.ERROR);
54
- expect(logger.error).toHaveBeenCalledWith(
55
- expect.stringMatching(/.*missing required fields.*/)
56
- );
57
- });
58
-
59
- describe('rejects configuration with srcDir outside project directory', () => {
60
- it('for parent directory', () => {
61
- projects.validateProjectConfig(
62
- { name: 'hello', srcDir: '..' },
63
- projectDir
64
- );
65
-
66
- expect(exitMock).toHaveBeenCalledWith(EXIT_CODES.ERROR);
67
- expect(logger.error).toHaveBeenCalledWith(
68
- expect.stringContaining('srcDir: ".."')
69
- );
70
- });
71
-
72
- it('for root directory', () => {
73
- projects.validateProjectConfig(
74
- { name: 'hello', srcDir: '/' },
75
- projectDir
76
- );
77
-
78
- expect(exitMock).toHaveBeenCalledWith(EXIT_CODES.ERROR);
79
- expect(logger.error).toHaveBeenCalledWith(
80
- expect.stringContaining('srcDir: "/"')
81
- );
82
- });
83
-
84
- it('for complicated directory', () => {
85
- const srcDir = './src/././../src/../../src';
86
-
87
- projects.validateProjectConfig({ name: 'hello', srcDir }, projectDir);
88
-
89
- expect(exitMock).toHaveBeenCalledWith(EXIT_CODES.ERROR);
90
- expect(logger.error).toHaveBeenCalledWith(
91
- expect.stringContaining(`srcDir: "${srcDir}"`)
92
- );
93
- });
94
- });
95
-
96
- it('rejects configuration with srcDir that does not exist', () => {
97
- projects.validateProjectConfig(
98
- { name: 'hello', srcDir: 'foo' },
99
- projectDir
100
- );
101
-
102
- expect(exitMock).toHaveBeenCalledWith(EXIT_CODES.ERROR);
103
- expect(logger.error).toHaveBeenCalledWith(
104
- expect.stringMatching(/.*could not be found in.*/)
105
- );
106
- });
107
-
108
- describe('accepts configuration with valid srcDir', () => {
109
- it('for current directory', () => {
110
- projects.validateProjectConfig(
111
- { name: 'hello', srcDir: '.' },
112
- projectDir
113
- );
114
-
115
- expect(exitMock).not.toHaveBeenCalled();
116
- expect(logger.error).not.toHaveBeenCalled();
117
- });
118
-
119
- it('for relative directory', () => {
120
- projects.validateProjectConfig(
121
- { name: 'hello', srcDir: './src' },
122
- projectDir
123
- );
124
-
125
- expect(exitMock).not.toHaveBeenCalled();
126
- expect(logger.error).not.toHaveBeenCalled();
127
- });
128
-
129
- it('for implied relative directory', () => {
130
- projects.validateProjectConfig(
131
- { name: 'hello', srcDir: 'src' },
132
- projectDir
133
- );
134
-
135
- expect(exitMock).not.toHaveBeenCalled();
136
- expect(logger.error).not.toHaveBeenCalled();
137
- });
138
- });
139
- });
140
- });