@hubspot/cli 5.2.1-beta.8 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/commands/auth.js +2 -4
  2. package/commands/functions/deploy.js +2 -2
  3. package/commands/init.js +2 -4
  4. package/commands/module/marketplace-validate.js +1 -1
  5. package/commands/project/__tests__/deploy.test.js +432 -0
  6. package/commands/project/cloneApp.js +208 -0
  7. package/commands/project/deploy.js +82 -27
  8. package/commands/project/listBuilds.js +1 -1
  9. package/commands/project/logs.js +1 -1
  10. package/commands/project/migrateApp.js +85 -30
  11. package/commands/project/upload.js +1 -1
  12. package/commands/project.js +15 -12
  13. package/commands/sandbox/create.js +17 -48
  14. package/commands/sandbox/delete.js +5 -2
  15. package/commands/sandbox/sync.js +12 -2
  16. package/commands/sandbox.js +2 -1
  17. package/commands/theme/marketplace-validate.js +1 -1
  18. package/lang/en.lyaml +77 -76
  19. package/lib/LocalDevManager.js +59 -11
  20. package/lib/buildAccount.js +3 -3
  21. package/lib/constants.js +3 -1
  22. package/lib/interpolationHelpers.js +3 -0
  23. package/lib/localDev.js +21 -11
  24. package/lib/marketplace-validate.js +11 -3
  25. package/lib/polling.js +16 -10
  26. package/lib/projects.js +143 -100
  27. package/lib/prompts/accountNamePrompt.js +78 -0
  28. package/lib/prompts/activeInstallConfirmationPrompt.js +20 -0
  29. package/lib/prompts/createProjectPrompt.js +12 -2
  30. package/lib/prompts/deployBuildIdPrompt.js +22 -0
  31. package/lib/prompts/installPublicAppPrompt.js +13 -4
  32. package/lib/prompts/personalAccessKeyPrompt.js +2 -2
  33. package/lib/prompts/sandboxesPrompt.js +12 -41
  34. package/lib/prompts/selectPublicAppPrompt.js +41 -22
  35. package/lib/sandboxSync.js +49 -68
  36. package/lib/sandboxes.js +8 -149
  37. package/lib/serverlessLogs.js +2 -2
  38. package/lib/ui/index.js +74 -0
  39. package/package.json +5 -4
  40. package/lib/prompts/buildIdPrompt.js +0 -35
  41. package/lib/prompts/developerTestAccountNamePrompt.js +0 -29
  42. package/lib/prompts/enterAccountNamePrompt.js +0 -33
  43. package/lib/ui/CliProgressMultibarManager.js +0 -66
package/commands/auth.js CHANGED
@@ -31,9 +31,7 @@ const {
31
31
  personalAccessKeyPrompt,
32
32
  OAUTH_FLOW,
33
33
  } = require('../lib/prompts/personalAccessKeyPrompt');
34
- const {
35
- enterAccountNamePrompt,
36
- } = require('../lib/prompts/enterAccountNamePrompt');
34
+ const { cliAccountNamePrompt } = require('../lib/prompts/accountNamePrompt');
37
35
  const {
38
36
  setAsDefaultAccountPrompt,
39
37
  } = require('../lib/prompts/setAsDefaultAccountPrompt');
@@ -129,7 +127,7 @@ exports.handler = async options => {
129
127
  validName = updatedConfig.name;
130
128
 
131
129
  if (!validName) {
132
- const { name: namePrompt } = await enterAccountNamePrompt(defaultName);
130
+ const { name: namePrompt } = await cliAccountNamePrompt(defaultName);
133
131
  validName = namePrompt;
134
132
  }
135
133
 
@@ -75,13 +75,13 @@ exports.handler = async options => {
75
75
  );
76
76
  } catch (e) {
77
77
  spinner && spinner.stop && spinner.stop();
78
- if (e.statusCode === 404) {
78
+ if (e.response && e.response.status === 404) {
79
79
  logger.error(
80
80
  i18n(`${i18nKey}.errors.noPackageJson`, {
81
81
  functionPath,
82
82
  })
83
83
  );
84
- } else if (e.statusCode === 400) {
84
+ } else if (e.response && e.response.status === 400) {
85
85
  logger.error(e.error.message);
86
86
  } else if (e.status === 'ERROR') {
87
87
  await outputBuildLog(e.cdnUrl);
package/commands/init.js CHANGED
@@ -40,9 +40,7 @@ const {
40
40
  OAUTH_FLOW,
41
41
  personalAccessKeyPrompt,
42
42
  } = require('../lib/prompts/personalAccessKeyPrompt');
43
- const {
44
- enterAccountNamePrompt,
45
- } = require('../lib/prompts/enterAccountNamePrompt');
43
+ const { cliAccountNamePrompt } = require('../lib/prompts/accountNamePrompt');
46
44
  const { logDebugInfo } = require('../lib/debugInfo');
47
45
  const { authenticateWithOauth } = require('../lib/oauth');
48
46
  const { EXIT_CODES } = require('../lib/enums/exitCodes');
@@ -63,7 +61,7 @@ const personalAccessKeyConfigCreationFlow = async (env, account) => {
63
61
  try {
64
62
  const token = await getAccessToken(personalAccessKey, env);
65
63
  const defaultName = token.hubName ? toKebabCase(token.hubName) : null;
66
- const { name } = await enterAccountNamePrompt(defaultName);
64
+ const { name } = await cliAccountNamePrompt(defaultName);
67
65
 
68
66
  updatedConfig = updateConfigWithAccessToken(
69
67
  token,
@@ -48,7 +48,7 @@ exports.handler = async options => {
48
48
  accountId,
49
49
  validationId
50
50
  );
51
- processValidationErrors(validationResults);
51
+ processValidationErrors(i18nKey, validationResults);
52
52
  displayValidationResults(i18nKey, validationResults);
53
53
 
54
54
  process.exit();
@@ -0,0 +1,432 @@
1
+ jest.mock('../../../lib/commonOpts');
2
+ jest.mock('yargs');
3
+ jest.mock('@hubspot/local-dev-lib/logger');
4
+ jest.mock('@hubspot/local-dev-lib/api/projects');
5
+ jest.mock('../../../lib/validation');
6
+ jest.mock('../../../lib/projects');
7
+ jest.mock('../../../lib/prompts/projectNamePrompt');
8
+ jest.mock('../../../lib/prompts/deployBuildIdPrompt');
9
+ jest.mock('@hubspot/local-dev-lib/config');
10
+ jest.mock('../../../lib/usageTracking');
11
+ jest.mock('../../../lib/ui');
12
+
13
+ const libUi = jest.requireActual('../../../lib/ui');
14
+ const {
15
+ uiCommandReference,
16
+ uiAccountDescription,
17
+ uiBetaTag,
18
+ uiLink,
19
+ } = require('../../../lib/ui');
20
+
21
+ uiBetaTag.mockImplementation(libUi.uiBetaTag);
22
+
23
+ const {
24
+ handler,
25
+ describe: deployDescribe,
26
+ command,
27
+ builder,
28
+ } = require('../deploy');
29
+
30
+ const {
31
+ addAccountOptions,
32
+ addConfigOptions,
33
+ getAccountId,
34
+ addUseEnvironmentOptions,
35
+ } = require('../../../lib/commonOpts');
36
+
37
+ const {
38
+ deployProject,
39
+ fetchProject,
40
+ } = require('@hubspot/local-dev-lib/api/projects');
41
+ const { loadAndValidateOptions } = require('../../../lib/validation');
42
+ const {
43
+ getProjectConfig,
44
+ pollDeployStatus,
45
+ getProjectDetailUrl,
46
+ } = require('../../../lib/projects');
47
+ const { projectNamePrompt } = require('../../../lib/prompts/projectNamePrompt');
48
+ const {
49
+ deployBuildIdPrompt,
50
+ } = require('../../../lib/prompts/deployBuildIdPrompt');
51
+ const { getAccountConfig } = require('@hubspot/local-dev-lib/config');
52
+
53
+ const yargs = require('yargs');
54
+ const { trackCommandUsage } = require('../../../lib/usageTracking');
55
+ const { logger } = require('@hubspot/local-dev-lib/logger');
56
+ const { EXIT_CODES } = require('../../../lib/enums/exitCodes');
57
+ const { AxiosError, HttpStatusCode } = require('axios');
58
+
59
+ const chalk = require('chalk');
60
+
61
+ describe('commands/project/deploy', () => {
62
+ const projectFlag = 'project';
63
+ const buildFlag = 'build';
64
+ const buildAliases = ['buildId'];
65
+
66
+ describe('describe', () => {
67
+ it('should contain the beta tag', () => {
68
+ expect(deployDescribe).toContain('[BETA]');
69
+ });
70
+ it('should provide an accurate description of what the command is doing', () => {
71
+ expect(deployDescribe).toMatch(/Deploy a project build/);
72
+ });
73
+ });
74
+
75
+ describe('command', () => {
76
+ it('should the correct command structure', () => {
77
+ expect(command).toEqual('deploy');
78
+ });
79
+ });
80
+
81
+ describe('builder', () => {
82
+ it('should add the correct options', () => {
83
+ builder(yargs);
84
+ expect(yargs.options).toHaveBeenCalledTimes(1);
85
+ expect(yargs.options).toHaveBeenCalledWith({
86
+ [projectFlag]: {
87
+ describe: 'Project name',
88
+ type: 'string',
89
+ },
90
+ [buildFlag]: {
91
+ alias: buildAliases,
92
+ describe: 'Project build ID to be deployed',
93
+ type: 'number',
94
+ },
95
+ });
96
+ });
97
+
98
+ it('should add the correct examples', () => {
99
+ builder(yargs);
100
+ expect(yargs.example).toHaveBeenCalledTimes(1);
101
+ expect(yargs.example).toHaveBeenCalledWith([
102
+ ['$0 project deploy', 'Deploy the latest build of the current project'],
103
+ [
104
+ `$0 project deploy --${projectFlag}="my-project" --${buildFlag}=5`,
105
+ 'Deploy build 5 of the project my-project',
106
+ ],
107
+ ]);
108
+ });
109
+
110
+ it('should add the config options', () => {
111
+ builder(yargs);
112
+ expect(addConfigOptions).toHaveBeenCalledTimes(1);
113
+ expect(addConfigOptions).toHaveBeenCalledWith(yargs);
114
+ });
115
+
116
+ it('should add the account options', () => {
117
+ builder(yargs);
118
+ expect(addAccountOptions).toHaveBeenCalledTimes(1);
119
+ expect(addAccountOptions).toHaveBeenCalledWith(yargs);
120
+ });
121
+
122
+ it('should add the environment options', () => {
123
+ builder(yargs);
124
+ expect(addUseEnvironmentOptions).toHaveBeenCalledTimes(1);
125
+ expect(addUseEnvironmentOptions).toHaveBeenCalledWith(yargs);
126
+ });
127
+
128
+ it('should the yargs object it is passed', () => {
129
+ expect(builder(yargs)).toEqual(yargs);
130
+ });
131
+ });
132
+
133
+ describe('handler', () => {
134
+ let projectConfig;
135
+ let processExitSpy;
136
+ const accountId = 1234567890;
137
+ const accountType = 'STANDARD';
138
+ let options;
139
+ const projectDetails = {
140
+ latestBuild: { buildId: 8 },
141
+ deployedBuildId: 1,
142
+ };
143
+ const deployDetails = {
144
+ id: 123,
145
+ };
146
+ const projectDetailUrl = 'http://project-details-page-url.com';
147
+ const viewProjectsInHubSpot = 'View project builds in HubSpot';
148
+
149
+ beforeEach(() => {
150
+ options = {
151
+ project: 'project name from options',
152
+ buildId: 2,
153
+ accountId,
154
+ };
155
+ projectConfig = {
156
+ name: 'project name from config',
157
+ };
158
+ getProjectConfig.mockResolvedValue({ projectConfig });
159
+ projectNamePrompt.mockResolvedValue({ projectName: 'fooo' });
160
+ getProjectDetailUrl.mockReturnValue(projectDetailUrl);
161
+ uiLink.mockImplementation(text => {
162
+ return text;
163
+ });
164
+ getAccountId.mockReturnValue(accountId);
165
+ getAccountConfig.mockReturnValue({ accountType });
166
+ fetchProject.mockResolvedValue(projectDetails);
167
+ deployProject.mockResolvedValue(deployDetails);
168
+ deployBuildIdPrompt.mockResolvedValue({
169
+ buildId: projectDetails.latestBuild.buildId,
170
+ });
171
+
172
+ // Spy on process.exit so our tests don't close when it's called
173
+ processExitSpy = jest.spyOn(process, 'exit').mockImplementation(() => {});
174
+ });
175
+
176
+ it('should load and validate the options', async () => {
177
+ await handler(options);
178
+ expect(loadAndValidateOptions).toHaveBeenCalledTimes(1);
179
+ expect(loadAndValidateOptions).toHaveBeenCalledWith(options);
180
+ });
181
+
182
+ it('should get the account id from the options', async () => {
183
+ await handler(options);
184
+ expect(getAccountId).toHaveBeenCalledTimes(1);
185
+ expect(getAccountId).toHaveBeenCalledWith(options);
186
+ });
187
+
188
+ it('should load the account config for the correct account id', async () => {
189
+ await handler(options);
190
+ expect(getAccountConfig).toHaveBeenCalledTimes(1);
191
+ expect(getAccountConfig).toHaveBeenCalledWith(accountId);
192
+ });
193
+
194
+ it('should track the command usage', async () => {
195
+ await handler(options);
196
+ expect(trackCommandUsage).toHaveBeenCalledTimes(1);
197
+ expect(trackCommandUsage).toHaveBeenCalledWith(
198
+ 'project-deploy',
199
+ { type: accountType },
200
+ accountId
201
+ );
202
+ });
203
+
204
+ it('should load the project config', async () => {
205
+ await handler(options);
206
+ expect(getProjectConfig).toHaveBeenCalledTimes(1);
207
+ expect(getProjectConfig).toHaveBeenCalledWith();
208
+ });
209
+
210
+ it('should load the project config', async () => {
211
+ await handler(options);
212
+ expect(getProjectConfig).toHaveBeenCalledTimes(1);
213
+ expect(getProjectConfig).toHaveBeenCalledWith();
214
+ });
215
+
216
+ it('should prompt for the project name', async () => {
217
+ await handler(options);
218
+ expect(projectNamePrompt).toHaveBeenCalledTimes(1);
219
+ expect(projectNamePrompt).toHaveBeenCalledWith(accountId, {
220
+ project: options.project,
221
+ });
222
+ });
223
+
224
+ it('should use the project name from the config is a project options is not provided', async () => {
225
+ delete options.project;
226
+ await handler(options);
227
+ expect(projectNamePrompt).toHaveBeenCalledTimes(1);
228
+ expect(projectNamePrompt).toHaveBeenCalledWith(accountId, {
229
+ project: projectConfig.name,
230
+ });
231
+ });
232
+
233
+ it('should fetch the project details', async () => {
234
+ await handler(options);
235
+ expect(fetchProject).toHaveBeenCalledTimes(1);
236
+ expect(fetchProject).toHaveBeenCalledWith(accountId, options.project);
237
+ });
238
+
239
+ it('should use the name from the prompt if no others are defined', async () => {
240
+ delete options.project;
241
+ const promptProjectName = 'project name from the prompt';
242
+ projectNamePrompt.mockReturnValue({ projectName: promptProjectName });
243
+ getProjectConfig.mockResolvedValue({});
244
+
245
+ await handler(options);
246
+
247
+ expect(projectNamePrompt).toHaveBeenCalledTimes(1);
248
+ expect(projectNamePrompt).toHaveBeenCalledWith(accountId, {});
249
+ expect(fetchProject).toHaveBeenCalledTimes(1);
250
+ expect(fetchProject).toHaveBeenCalledWith(accountId, promptProjectName);
251
+ });
252
+
253
+ it('should log an error and exit when latest build is not defined', async () => {
254
+ fetchProject.mockResolvedValue({});
255
+ await handler(options);
256
+ expect(logger.error).toHaveBeenCalledTimes(1);
257
+ expect(logger.error).toHaveBeenCalledWith(
258
+ 'Deploy error: no builds for this project were found.'
259
+ );
260
+ expect(processExitSpy).toHaveBeenCalledTimes(1);
261
+ expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
262
+ });
263
+
264
+ it('should log an error and exit when buildId option is not a valid build', async () => {
265
+ options.buildId = projectDetails.latestBuild.buildId + 1;
266
+ await handler(options);
267
+ expect(uiLink).toHaveBeenCalledTimes(1);
268
+ expect(uiLink).toHaveBeenCalledWith(
269
+ viewProjectsInHubSpot,
270
+ projectDetailUrl
271
+ );
272
+ expect(logger.error).toHaveBeenCalledTimes(1);
273
+ expect(logger.error).toHaveBeenCalledWith(
274
+ `Build ${options.buildId} does not exist for project ${options.project}. ${viewProjectsInHubSpot}`
275
+ );
276
+ expect(processExitSpy).toHaveBeenCalledTimes(1);
277
+ expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
278
+ });
279
+
280
+ it('should log an error and exit when buildId option is already deployed', async () => {
281
+ options.buildId = projectDetails.deployedBuildId;
282
+ await handler(options);
283
+ expect(uiLink).toHaveBeenCalledTimes(1);
284
+ expect(uiLink).toHaveBeenCalledWith(
285
+ viewProjectsInHubSpot,
286
+ projectDetailUrl
287
+ );
288
+ expect(logger.error).toHaveBeenCalledTimes(1);
289
+ expect(logger.error).toHaveBeenCalledWith(
290
+ `Build ${options.buildId} is already deployed. ${viewProjectsInHubSpot}`
291
+ );
292
+ expect(processExitSpy).toHaveBeenCalledTimes(1);
293
+ expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
294
+ });
295
+
296
+ it('should prompt for build id if no option is provided', async () => {
297
+ delete options.buildId;
298
+ await handler(options);
299
+ expect(deployBuildIdPrompt).toHaveBeenCalledTimes(1);
300
+ expect(deployBuildIdPrompt).toHaveBeenCalledWith(
301
+ projectDetails.latestBuild.buildId,
302
+ projectDetails.deployedBuildId,
303
+ expect.any(Function)
304
+ );
305
+ });
306
+
307
+ it('should log an error and exit if the prompted value is invalid', async () => {
308
+ delete options.buildId;
309
+ deployBuildIdPrompt.mockReturnValue({});
310
+
311
+ await handler(options);
312
+
313
+ expect(deployBuildIdPrompt).toHaveBeenCalledTimes(1);
314
+ expect(logger.error).toHaveBeenCalledTimes(1);
315
+ expect(logger.error).toHaveBeenCalledWith(
316
+ 'You must specify a build to deploy'
317
+ );
318
+ expect(processExitSpy).toHaveBeenCalledTimes(1);
319
+ expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
320
+ });
321
+
322
+ it('should deploy the project', async () => {
323
+ await handler(options);
324
+ expect(deployProject).toHaveBeenCalledTimes(1);
325
+ expect(deployProject).toHaveBeenCalledWith(
326
+ accountId,
327
+ options.project,
328
+ options.buildId
329
+ );
330
+ });
331
+
332
+ it('should log an error and exit when the deploy fails', async () => {
333
+ const errorMessage = `Just wasn't feeling it`;
334
+ deployProject.mockResolvedValue({
335
+ error: { message: errorMessage },
336
+ });
337
+
338
+ await handler(options);
339
+ expect(logger.error).toHaveBeenCalledTimes(1);
340
+ expect(logger.error).toHaveBeenCalledWith(
341
+ `Deploy error: ${errorMessage}`
342
+ );
343
+ expect(processExitSpy).toHaveBeenCalledTimes(1);
344
+ expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
345
+ });
346
+
347
+ it('should poll the deploy status', async () => {
348
+ await handler(options);
349
+ expect(pollDeployStatus).toHaveBeenCalledTimes(1);
350
+ expect(pollDeployStatus).toHaveBeenCalledWith(
351
+ accountId,
352
+ options.project,
353
+ deployDetails.id,
354
+ options.buildId
355
+ );
356
+ });
357
+
358
+ it('log an error and exit if a 404 status is returned', async () => {
359
+ const commandReference = 'hs project upload';
360
+ const accountDescription = 'SuperCoolTestAccount';
361
+ uiCommandReference.mockReturnValue(commandReference);
362
+ uiAccountDescription.mockReturnValue(accountDescription);
363
+ fetchProject.mockImplementation(() => {
364
+ throw new AxiosError(
365
+ 'OH NO',
366
+ '',
367
+ {},
368
+ {},
369
+ { status: HttpStatusCode.NotFound }
370
+ );
371
+ });
372
+ await handler(options);
373
+
374
+ expect(logger.error).toHaveBeenCalledTimes(1);
375
+ expect(logger.error).toHaveBeenCalledWith(
376
+ `The project ${chalk.bold(
377
+ options.project
378
+ )} does not exist in account ${accountDescription}. Run ${commandReference} to upload your project files to HubSpot.`
379
+ );
380
+ expect(processExitSpy).toHaveBeenCalledTimes(1);
381
+ expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
382
+ });
383
+
384
+ it('log an error and exit if a 400 status is returned', async () => {
385
+ const commandReference = 'hs project upload';
386
+ const accountDescription = 'SuperCoolTestAccount';
387
+ uiCommandReference.mockReturnValue(commandReference);
388
+ uiAccountDescription.mockReturnValue(accountDescription);
389
+ const errorMessage = 'Something bad happened';
390
+ fetchProject.mockImplementation(() => {
391
+ throw new AxiosError(
392
+ errorMessage,
393
+ '',
394
+ {},
395
+ {},
396
+ { status: HttpStatusCode.BadRequest }
397
+ );
398
+ });
399
+ await handler(options);
400
+
401
+ expect(logger.error).toHaveBeenCalledTimes(1);
402
+ expect(logger.error).toHaveBeenCalledWith(errorMessage);
403
+ expect(processExitSpy).toHaveBeenCalledTimes(1);
404
+ expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
405
+ });
406
+
407
+ it('log an error another unexpected status code is returned', async () => {
408
+ const commandReference = 'hs project upload';
409
+ const accountDescription = 'SuperCoolTestAccount';
410
+ uiCommandReference.mockReturnValue(commandReference);
411
+ uiAccountDescription.mockReturnValue(accountDescription);
412
+ const errorMessage = 'Something bad happened';
413
+ fetchProject.mockImplementation(() => {
414
+ throw new AxiosError(
415
+ errorMessage,
416
+ '',
417
+ {},
418
+ {},
419
+ { status: HttpStatusCode.MethodNotAllowed }
420
+ );
421
+ });
422
+ await handler(options);
423
+
424
+ expect(logger.error).toHaveBeenCalledTimes(1);
425
+ expect(logger.error).toHaveBeenCalledWith(
426
+ `The request in account ${accountId} failed due to a client error.`
427
+ );
428
+ expect(processExitSpy).toHaveBeenCalledTimes(1);
429
+ expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
430
+ });
431
+ });
432
+ });