@hubspot/cli 7.6.0-beta.4 → 7.6.0-beta.5
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.
- package/commands/__tests__/getStarted.test.js +0 -10
- package/commands/getStarted.js +12 -27
- package/commands/project/__tests__/deploy.test.js +21 -25
- package/commands/project/__tests__/devUnifiedFlow.test.js +20 -16
- package/commands/project/deploy.d.ts +2 -2
- package/commands/project/deploy.js +43 -48
- package/commands/project/dev/unifiedFlow.js +7 -6
- package/commands/testAccount/create.js +8 -34
- package/lang/en.d.ts +21 -17
- package/lang/en.js +21 -17
- package/lang/en.lyaml +0 -26
- package/lib/__tests__/buildAccount.test.js +30 -2
- package/lib/buildAccount.d.ts +7 -1
- package/lib/buildAccount.js +54 -4
- package/lib/errorHandlers/index.js +0 -8
- package/lib/projects/localDev/DevServerManager.js +0 -2
- package/lib/projects/localDev/DevServerManagerV2.js +0 -2
- package/lib/projects/localDev/helpers.d.ts +1 -1
- package/lib/projects/localDev/helpers.js +2 -2
- package/lib/prompts/createDeveloperTestAccountConfigPrompt.d.ts +1 -1
- package/lib/prompts/createDeveloperTestAccountConfigPrompt.js +9 -10
- package/lib/prompts/promptUtils.js +66 -56
- package/package.json +4 -4
|
@@ -108,9 +108,6 @@ describe('commands/get-started', () => {
|
|
|
108
108
|
promptUtils_1.promptUser
|
|
109
109
|
.mockResolvedValueOnce({
|
|
110
110
|
default: constants_1.GET_STARTED_OPTIONS.APP,
|
|
111
|
-
})
|
|
112
|
-
.mockResolvedValueOnce({
|
|
113
|
-
shouldInstallDependencies: true,
|
|
114
111
|
})
|
|
115
112
|
.mockResolvedValueOnce({
|
|
116
113
|
shouldUpload: true,
|
|
@@ -149,13 +146,6 @@ describe('commands/get-started', () => {
|
|
|
149
146
|
}),
|
|
150
147
|
]);
|
|
151
148
|
});
|
|
152
|
-
it('should skip upload when user declines', async () => {
|
|
153
|
-
promptUtils_1.promptUser
|
|
154
|
-
.mockResolvedValueOnce({ shouldInstallDependencies: false })
|
|
155
|
-
.mockResolvedValueOnce({ shouldUpload: false });
|
|
156
|
-
await getStarted_1.default.handler(mockArgs);
|
|
157
|
-
expect(process.exit).toHaveBeenCalledWith(exitCodes_1.EXIT_CODES.SUCCESS);
|
|
158
|
-
});
|
|
159
149
|
});
|
|
160
150
|
describe('tracking', () => {
|
|
161
151
|
it('should track command usage', async () => {
|
package/commands/getStarted.js
CHANGED
|
@@ -127,35 +127,20 @@ async function handler(args) {
|
|
|
127
127
|
logger_1.uiLogger.log(' ');
|
|
128
128
|
logger_1.uiLogger.log(en_1.commands.getStarted.prompts.projectCreated.description);
|
|
129
129
|
logger_1.uiLogger.log(' ');
|
|
130
|
-
// 5. Install dependencies
|
|
130
|
+
// 5. Install dependencies
|
|
131
131
|
const installLocations = await (0, dependencyManagement_1.getProjectPackageJsonLocations)(projectDest);
|
|
132
|
-
|
|
133
|
-
{
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
]);
|
|
140
|
-
if (shouldInstallDependencies) {
|
|
141
|
-
try {
|
|
142
|
-
await (0, dependencyManagement_1.installPackages)({
|
|
143
|
-
installLocations: installLocations,
|
|
144
|
-
});
|
|
145
|
-
logger_1.uiLogger.log(' ');
|
|
146
|
-
logger_1.uiLogger.success(en_1.commands.getStarted.logs.dependenciesInstalled);
|
|
147
|
-
logger_1.uiLogger.log(' ');
|
|
148
|
-
}
|
|
149
|
-
catch (err) {
|
|
150
|
-
logger_1.uiLogger.log(' ');
|
|
151
|
-
logger_1.uiLogger.error(en_1.commands.getStarted.errors.installDepsFailed);
|
|
152
|
-
(0, errorHandlers_1.logError)(err);
|
|
153
|
-
logger_1.uiLogger.log(' ');
|
|
154
|
-
}
|
|
132
|
+
try {
|
|
133
|
+
await (0, dependencyManagement_1.installPackages)({
|
|
134
|
+
installLocations: installLocations,
|
|
135
|
+
});
|
|
136
|
+
logger_1.uiLogger.log(' ');
|
|
137
|
+
logger_1.uiLogger.success(en_1.commands.getStarted.logs.dependenciesInstalled);
|
|
138
|
+
logger_1.uiLogger.log(' ');
|
|
155
139
|
}
|
|
156
|
-
|
|
140
|
+
catch (err) {
|
|
157
141
|
logger_1.uiLogger.log(' ');
|
|
158
|
-
logger_1.uiLogger.
|
|
142
|
+
logger_1.uiLogger.error(en_1.commands.getStarted.errors.installDepsFailed);
|
|
143
|
+
(0, errorHandlers_1.logError)(err);
|
|
159
144
|
logger_1.uiLogger.log(' ');
|
|
160
145
|
}
|
|
161
146
|
// 6. Ask user if they want to upload the project
|
|
@@ -217,7 +202,7 @@ async function handler(args) {
|
|
|
217
202
|
targetAccountId: derivedAccountId,
|
|
218
203
|
env: env,
|
|
219
204
|
appId: lastCreatedApp.id,
|
|
220
|
-
}), { url: true });
|
|
205
|
+
}) + '&tourId=get-started', { url: true });
|
|
221
206
|
logger_1.uiLogger.log(' ');
|
|
222
207
|
logger_1.uiLogger.success(en_1.commands.getStarted.openedDeveloperOverview);
|
|
223
208
|
}
|
|
@@ -39,8 +39,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
const axios_1 = require("axios");
|
|
40
40
|
const yargs_1 = __importDefault(require("yargs"));
|
|
41
41
|
const chalk_1 = __importDefault(require("chalk"));
|
|
42
|
-
const configUtils = __importStar(require("@hubspot/local-dev-lib/config"));
|
|
43
42
|
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
43
|
+
const configUtils = __importStar(require("@hubspot/local-dev-lib/config"));
|
|
44
44
|
const projectApiUtils = __importStar(require("@hubspot/local-dev-lib/api/projects"));
|
|
45
45
|
const ui = __importStar(require("../../../lib/ui"));
|
|
46
46
|
const commonOpts_1 = require("../../../lib/commonOpts");
|
|
@@ -54,7 +54,7 @@ const exitCodes_1 = require("../../../lib/enums/exitCodes");
|
|
|
54
54
|
const exampleProject_json_1 = __importDefault(require("./fixtures/exampleProject.json"));
|
|
55
55
|
const testUtils_1 = require("../../../lib/testUtils");
|
|
56
56
|
const deploy_1 = __importDefault(require("../deploy"));
|
|
57
|
-
|
|
57
|
+
const logger_2 = require("../../../lib/ui/logger");
|
|
58
58
|
vi.mock('@hubspot/local-dev-lib/api/projects');
|
|
59
59
|
vi.mock('@hubspot/local-dev-lib/config');
|
|
60
60
|
vi.mock('../../../lib/commonOpts');
|
|
@@ -65,8 +65,9 @@ vi.mock('../../../lib/projects/buildAndDeploy');
|
|
|
65
65
|
vi.mock('../../../lib/prompts/projectNamePrompt');
|
|
66
66
|
vi.mock('../../../lib/prompts/promptUtils');
|
|
67
67
|
vi.mock('../../../lib/usageTracking');
|
|
68
|
+
vi.mock('../../../lib/ui/logger');
|
|
69
|
+
vi.mock('@hubspot/local-dev-lib/logger');
|
|
68
70
|
vi.spyOn(ui, 'uiLine');
|
|
69
|
-
const uiLinkSpy = vi.spyOn(ui, 'uiLink').mockImplementation(text => text);
|
|
70
71
|
const uiCommandReferenceSpy = vi.spyOn(ui, 'uiCommandReference');
|
|
71
72
|
const uiAccountDescriptionSpy = vi.spyOn(ui, 'uiAccountDescription');
|
|
72
73
|
const getProjectConfigSpy = vi.spyOn(projectUtils, 'getProjectConfig');
|
|
@@ -139,6 +140,8 @@ describe('commands/project/deploy', () => {
|
|
|
139
140
|
expect(commonOpts_1.addAccountOptions).toHaveBeenCalledWith(yargs_1.default);
|
|
140
141
|
expect(commonOpts_1.addUseEnvironmentOptions).toHaveBeenCalledTimes(1);
|
|
141
142
|
expect(commonOpts_1.addUseEnvironmentOptions).toHaveBeenCalledWith(yargs_1.default);
|
|
143
|
+
expect(commonOpts_1.addJSONOutputOptions).toHaveBeenCalledTimes(1);
|
|
144
|
+
expect(commonOpts_1.addJSONOutputOptions).toHaveBeenCalledWith(yargs_1.default);
|
|
142
145
|
});
|
|
143
146
|
it('should provide examples', () => {
|
|
144
147
|
deploy_1.default.builder(yargs_1.default);
|
|
@@ -152,9 +155,9 @@ describe('commands/project/deploy', () => {
|
|
|
152
155
|
const projectNameFromPrompt = 'project name from prompt';
|
|
153
156
|
const deployDetails = {
|
|
154
157
|
id: 123,
|
|
158
|
+
buildResultType: 'DEPLOY_QUEUED',
|
|
155
159
|
};
|
|
156
160
|
const projectDetailUrl = 'http://project-details-page-url.com';
|
|
157
|
-
const viewProjectsInHubSpot = 'View project builds in HubSpot';
|
|
158
161
|
beforeEach(() => {
|
|
159
162
|
args = {
|
|
160
163
|
project: 'project name from options',
|
|
@@ -174,9 +177,6 @@ describe('commands/project/deploy', () => {
|
|
|
174
177
|
projectName: projectNameFromPrompt,
|
|
175
178
|
});
|
|
176
179
|
getProjectDetailUrlSpy.mockReturnValue(projectDetailUrl);
|
|
177
|
-
uiLinkSpy.mockImplementation(text => {
|
|
178
|
-
return text;
|
|
179
|
-
});
|
|
180
180
|
getAccountConfigSpy.mockReturnValue({ accountType, env: 'qa' });
|
|
181
181
|
fetchProjectSpy.mockReturnValue((0, testUtils_1.mockHubSpotHttpResponse)(exampleProject_json_1.default));
|
|
182
182
|
deployProjectSpy.mockReturnValue((0, testUtils_1.mockHubSpotHttpResponse)(deployDetails));
|
|
@@ -239,28 +239,24 @@ describe('commands/project/deploy', () => {
|
|
|
239
239
|
it('should log an error and exit when latest build is not defined', async () => {
|
|
240
240
|
fetchProjectSpy.mockReturnValue((0, testUtils_1.mockHubSpotHttpResponse)({}));
|
|
241
241
|
await deploy_1.default.handler(args);
|
|
242
|
-
expect(
|
|
243
|
-
expect(
|
|
242
|
+
expect(logger_2.uiLogger.error).toHaveBeenCalledTimes(1);
|
|
243
|
+
expect(logger_2.uiLogger.error).toHaveBeenCalledWith('Deploy error: no builds for this project were found.');
|
|
244
244
|
expect(processExitSpy).toHaveBeenCalledTimes(1);
|
|
245
245
|
expect(processExitSpy).toHaveBeenCalledWith(exitCodes_1.EXIT_CODES.ERROR);
|
|
246
246
|
});
|
|
247
247
|
it('should log an error and exit when buildId option is not a valid build', async () => {
|
|
248
248
|
args.buildId = exampleProject_json_1.default.latestBuild.buildId + 1;
|
|
249
249
|
await deploy_1.default.handler(args);
|
|
250
|
-
expect(
|
|
251
|
-
expect(
|
|
252
|
-
expect(logger_1.logger.error).toHaveBeenCalledTimes(1);
|
|
253
|
-
expect(logger_1.logger.error).toHaveBeenCalledWith(`Build ${args.buildId} does not exist for project ${projectNameFromPrompt}. ${viewProjectsInHubSpot}`);
|
|
250
|
+
expect(logger_2.uiLogger.error).toHaveBeenCalledTimes(1);
|
|
251
|
+
expect(logger_2.uiLogger.error).toHaveBeenCalledWith(expect.stringMatching(`Build ${args.buildId} does not exist for project`));
|
|
254
252
|
expect(processExitSpy).toHaveBeenCalledTimes(1);
|
|
255
253
|
expect(processExitSpy).toHaveBeenCalledWith(exitCodes_1.EXIT_CODES.ERROR);
|
|
256
254
|
});
|
|
257
255
|
it('should log an error and exit when buildId option is already deployed', async () => {
|
|
258
256
|
args.buildId = exampleProject_json_1.default.deployedBuildId;
|
|
259
257
|
await deploy_1.default.handler(args);
|
|
260
|
-
expect(
|
|
261
|
-
expect(
|
|
262
|
-
expect(logger_1.logger.error).toHaveBeenCalledTimes(1);
|
|
263
|
-
expect(logger_1.logger.error).toHaveBeenCalledWith(`Build ${args.buildId} is already deployed. ${viewProjectsInHubSpot}`);
|
|
258
|
+
expect(logger_2.uiLogger.error).toHaveBeenCalledTimes(1);
|
|
259
|
+
expect(logger_2.uiLogger.error).toHaveBeenCalledWith(expect.stringMatching(`Build ${args.buildId} is already deployed. View project builds in HubSpot.`));
|
|
264
260
|
expect(processExitSpy).toHaveBeenCalledTimes(1);
|
|
265
261
|
expect(processExitSpy).toHaveBeenCalledWith(exitCodes_1.EXIT_CODES.ERROR);
|
|
266
262
|
});
|
|
@@ -277,8 +273,8 @@ describe('commands/project/deploy', () => {
|
|
|
277
273
|
promptUserSpy.mockResolvedValue({});
|
|
278
274
|
await deploy_1.default.handler(args);
|
|
279
275
|
expect(promptUserSpy).toHaveBeenCalledTimes(1);
|
|
280
|
-
expect(
|
|
281
|
-
expect(
|
|
276
|
+
expect(logger_2.uiLogger.error).toHaveBeenCalledTimes(1);
|
|
277
|
+
expect(logger_2.uiLogger.error).toHaveBeenCalledWith('You must specify a build to deploy');
|
|
282
278
|
expect(processExitSpy).toHaveBeenCalledTimes(1);
|
|
283
279
|
expect(processExitSpy).toHaveBeenCalledWith(exitCodes_1.EXIT_CODES.ERROR);
|
|
284
280
|
});
|
|
@@ -291,8 +287,8 @@ describe('commands/project/deploy', () => {
|
|
|
291
287
|
// @ts-expect-error Testing an edge case where the response is empty
|
|
292
288
|
deployProjectSpy.mockResolvedValue({});
|
|
293
289
|
await deploy_1.default.handler(args);
|
|
294
|
-
expect(
|
|
295
|
-
expect(
|
|
290
|
+
expect(logger_2.uiLogger.error).toHaveBeenCalledTimes(1);
|
|
291
|
+
expect(logger_2.uiLogger.error).toHaveBeenCalledWith(`Deploy error: an unknown error occurred.`);
|
|
296
292
|
expect(processExitSpy).toHaveBeenCalledTimes(1);
|
|
297
293
|
expect(processExitSpy).toHaveBeenCalledWith(exitCodes_1.EXIT_CODES.ERROR);
|
|
298
294
|
});
|
|
@@ -313,8 +309,8 @@ describe('commands/project/deploy', () => {
|
|
|
313
309
|
});
|
|
314
310
|
});
|
|
315
311
|
await deploy_1.default.handler(args);
|
|
316
|
-
expect(
|
|
317
|
-
expect(
|
|
312
|
+
expect(logger_2.uiLogger.error).toHaveBeenCalledTimes(1);
|
|
313
|
+
expect(logger_2.uiLogger.error).toHaveBeenCalledWith(`The project ${chalk_1.default.bold(projectNameFromPrompt)} does not exist in account ${accountDescription}. Run ${commandReference} to upload your project files to HubSpot.`);
|
|
318
314
|
expect(processExitSpy).toHaveBeenCalledTimes(1);
|
|
319
315
|
expect(processExitSpy).toHaveBeenCalledWith(exitCodes_1.EXIT_CODES.ERROR);
|
|
320
316
|
});
|
|
@@ -327,8 +323,8 @@ describe('commands/project/deploy', () => {
|
|
|
327
323
|
});
|
|
328
324
|
});
|
|
329
325
|
await deploy_1.default.handler(args);
|
|
330
|
-
expect(
|
|
331
|
-
expect(
|
|
326
|
+
expect(logger_2.uiLogger.error).toHaveBeenCalledTimes(1);
|
|
327
|
+
expect(logger_2.uiLogger.error).toHaveBeenCalledWith('The request was bad.');
|
|
332
328
|
expect(processExitSpy).toHaveBeenCalledTimes(1);
|
|
333
329
|
expect(processExitSpy).toHaveBeenCalledWith(exitCodes_1.EXIT_CODES.ERROR);
|
|
334
330
|
});
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const path_1 = __importDefault(require("path"));
|
|
7
7
|
const config_1 = require("@hubspot/local-dev-lib/constants/config");
|
|
8
8
|
const project_parsing_lib_1 = require("@hubspot/project-parsing-lib");
|
|
9
|
+
// import { HsProfileFile } from '@hubspot/project-parsing-lib/src/lib/types';
|
|
9
10
|
const config_2 = require("@hubspot/local-dev-lib/config");
|
|
10
11
|
const environment_1 = require("@hubspot/local-dev-lib/environment");
|
|
11
12
|
const errorHandlers_1 = require("../../../lib/errorHandlers");
|
|
@@ -69,9 +70,9 @@ describe('unifiedProjectDevFlow', () => {
|
|
|
69
70
|
const mockProjectDir = '/test/project';
|
|
70
71
|
const mockTargetProjectAccountId = 123;
|
|
71
72
|
const mockProvidedTargetTestingAccountId = 456;
|
|
72
|
-
const mockProfileConfig = {
|
|
73
|
-
|
|
74
|
-
};
|
|
73
|
+
// const mockProfileConfig: HsProfileFile = {
|
|
74
|
+
// accountId: 789,
|
|
75
|
+
// };
|
|
75
76
|
const mockAccountConfig = {
|
|
76
77
|
accountId: 123,
|
|
77
78
|
name: 'test-account',
|
|
@@ -157,18 +158,21 @@ describe('unifiedProjectDevFlow', () => {
|
|
|
157
158
|
expect(mockLocalDevWatcher.start).toHaveBeenCalled();
|
|
158
159
|
expect(mockWebsocketServer.start).toHaveBeenCalled();
|
|
159
160
|
});
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
161
|
+
// TODO: Restore test once we've switched back to using profile account for testing
|
|
162
|
+
// it('should complete successfully with profile config', async () => {
|
|
163
|
+
// await unifiedProjectDevFlow({
|
|
164
|
+
// args: mockArgs,
|
|
165
|
+
// targetProjectAccountId: mockTargetProjectAccountId,
|
|
166
|
+
// projectConfig: mockProjectConfig,
|
|
167
|
+
// projectDir: mockProjectDir,
|
|
168
|
+
// profileConfig: mockProfileConfig,
|
|
169
|
+
// });
|
|
170
|
+
// expect(LocalDevProcess).toHaveBeenCalledWith(
|
|
171
|
+
// expect.objectContaining({
|
|
172
|
+
// targetTestingAccountId: mockProfileConfig.accountId,
|
|
173
|
+
// })
|
|
174
|
+
// );
|
|
175
|
+
// });
|
|
172
176
|
it('should use target project account as testing account when it is a test account', async () => {
|
|
173
177
|
accountTypes_1.isTestAccountOrSandbox.mockReturnValue(true);
|
|
174
178
|
await (0, unifiedFlow_1.unifiedProjectDevFlow)({
|
|
@@ -258,7 +262,7 @@ describe('unifiedProjectDevFlow', () => {
|
|
|
258
262
|
projectConfig: mockProjectConfig,
|
|
259
263
|
projectDir: mockProjectDir,
|
|
260
264
|
});
|
|
261
|
-
expect(helpers_1.createDeveloperTestAccountForLocalDev).toHaveBeenCalledWith(mockTargetProjectAccountId, mockAccountConfig, environments_1.ENVIRONMENTS.PROD);
|
|
265
|
+
expect(helpers_1.createDeveloperTestAccountForLocalDev).toHaveBeenCalledWith(mockTargetProjectAccountId, mockAccountConfig, environments_1.ENVIRONMENTS.PROD, true);
|
|
262
266
|
expect(LocalDevProcess_1.default).toHaveBeenCalledWith(expect.objectContaining({
|
|
263
267
|
targetTestingAccountId: 999,
|
|
264
268
|
}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CommonArgs, ConfigArgs, AccountArgs, EnvironmentArgs, YargsCommandModule } from '../../types/Yargs';
|
|
2
|
-
export type ProjectDeployArgs = CommonArgs & ConfigArgs & AccountArgs & EnvironmentArgs & {
|
|
1
|
+
import { CommonArgs, ConfigArgs, AccountArgs, EnvironmentArgs, JSONOutputArgs, YargsCommandModule } from '../../types/Yargs';
|
|
2
|
+
export type ProjectDeployArgs = CommonArgs & ConfigArgs & AccountArgs & EnvironmentArgs & JSONOutputArgs & {
|
|
3
3
|
project?: string;
|
|
4
4
|
build?: number;
|
|
5
5
|
buildId?: number;
|
|
@@ -1,65 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
7
3
|
const projects_1 = require("@hubspot/local-dev-lib/api/projects");
|
|
8
4
|
const config_1 = require("@hubspot/local-dev-lib/config");
|
|
9
|
-
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
10
5
|
const index_1 = require("@hubspot/local-dev-lib/errors/index");
|
|
11
6
|
const buildAndDeploy_1 = require("../../lib/projects/buildAndDeploy");
|
|
12
7
|
const usageTracking_1 = require("../../lib/usageTracking");
|
|
13
8
|
const index_2 = require("../../lib/errorHandlers/index");
|
|
14
9
|
const config_2 = require("../../lib/projects/config");
|
|
15
10
|
const buildAndDeploy_2 = require("../../lib/projects/buildAndDeploy");
|
|
16
|
-
const urls_1 = require("../../lib/projects/urls");
|
|
17
11
|
const projectNamePrompt_1 = require("../../lib/prompts/projectNamePrompt");
|
|
18
12
|
const promptUtils_1 = require("../../lib/prompts/promptUtils");
|
|
19
|
-
const lang_1 = require("../../lib/lang");
|
|
20
13
|
const ui_1 = require("../../lib/ui");
|
|
21
14
|
const exitCodes_1 = require("../../lib/enums/exitCodes");
|
|
22
|
-
const
|
|
15
|
+
const logger_1 = require("../../lib/ui/logger");
|
|
23
16
|
const yargsUtils_1 = require("../../lib/yargsUtils");
|
|
24
17
|
const projectProfiles_1 = require("../../lib/projectProfiles");
|
|
25
18
|
const constants_1 = require("../../lib/constants");
|
|
19
|
+
const en_1 = require("../../lang/en");
|
|
26
20
|
const command = 'deploy';
|
|
27
|
-
const describe = (0, ui_1.uiBetaTag)(
|
|
21
|
+
const describe = (0, ui_1.uiBetaTag)(en_1.commands.project.deploy.describe, false);
|
|
28
22
|
function validateBuildId(buildId, deployedBuildId, latestBuildId, projectName, accountId) {
|
|
29
23
|
if (Number(buildId) > latestBuildId) {
|
|
30
|
-
return
|
|
31
|
-
buildId: buildId,
|
|
32
|
-
projectName: projectName,
|
|
33
|
-
linkToProject: (0, ui_1.uiLink)((0, lang_1.i18n)(`commands.project.subcommands.deploy.errors.viewProjectsBuilds`), (0, urls_1.getProjectDetailUrl)(projectName, accountId)),
|
|
34
|
-
});
|
|
24
|
+
return en_1.commands.project.deploy.errors.buildIdDoesNotExist(accountId, buildId, projectName);
|
|
35
25
|
}
|
|
36
26
|
if (Number(buildId) === deployedBuildId) {
|
|
37
|
-
return
|
|
38
|
-
buildId: buildId,
|
|
39
|
-
linkToProject: (0, ui_1.uiLink)((0, lang_1.i18n)(`commands.project.subcommands.deploy.errors.viewProjectsBuilds`), (0, urls_1.getProjectDetailUrl)(projectName, accountId)),
|
|
40
|
-
});
|
|
27
|
+
return en_1.commands.project.deploy.errors.buildAlreadyDeployed(accountId, buildId, projectName);
|
|
41
28
|
}
|
|
42
29
|
return true;
|
|
43
30
|
}
|
|
44
31
|
function logDeployErrors(errorData) {
|
|
45
|
-
logger_1.
|
|
32
|
+
logger_1.uiLogger.error(errorData.message);
|
|
46
33
|
errorData.errors.forEach(err => {
|
|
47
34
|
if (err.subCategory === constants_1.PROJECT_ERROR_TYPES.DEPLOY_CONTAINS_REMOVALS) {
|
|
48
|
-
logger_1.
|
|
49
|
-
componentName: err.context.COMPONENT_NAME,
|
|
50
|
-
forceFlag: (0, ui_2.uiCommandReference)('--force'),
|
|
51
|
-
}));
|
|
35
|
+
logger_1.uiLogger.log(en_1.commands.project.deploy.errors.deployContainsRemovals(err.context.COMPONENT_NAME));
|
|
52
36
|
}
|
|
53
37
|
else {
|
|
54
|
-
logger_1.
|
|
38
|
+
logger_1.uiLogger.log(err.message);
|
|
55
39
|
}
|
|
56
40
|
});
|
|
57
41
|
}
|
|
58
42
|
async function handler(args) {
|
|
59
|
-
const { derivedAccountId, project: projectOption, buildId: buildIdOption, force: forceOption, deployLatestBuild: deployLatestBuildOption, } = args;
|
|
43
|
+
const { derivedAccountId, project: projectOption, buildId: buildIdOption, force: forceOption, deployLatestBuild: deployLatestBuildOption, json: formatOutputAsJson, } = args;
|
|
60
44
|
const accountConfig = (0, config_1.getAccountConfig)(derivedAccountId);
|
|
61
45
|
const accountType = accountConfig && accountConfig.accountType;
|
|
62
46
|
let targetAccountId;
|
|
47
|
+
const jsonOutput = {};
|
|
63
48
|
const { projectConfig, projectDir } = await (0, config_2.getProjectConfig)();
|
|
64
49
|
if ((0, buildAndDeploy_1.useV3Api)(projectConfig?.platformVersion)) {
|
|
65
50
|
if (args.profile) {
|
|
@@ -90,16 +75,17 @@ async function handler(args) {
|
|
|
90
75
|
});
|
|
91
76
|
projectName = namePromptResponse.projectName;
|
|
92
77
|
let buildIdToDeploy = buildIdOption;
|
|
78
|
+
let deploySuccess = false;
|
|
93
79
|
try {
|
|
94
80
|
const { data: { latestBuild, deployedBuildId }, } = await (0, projects_1.fetchProject)(targetAccountId, projectName);
|
|
95
81
|
if (!latestBuild || !latestBuild.buildId) {
|
|
96
|
-
logger_1.
|
|
82
|
+
logger_1.uiLogger.error(en_1.commands.project.deploy.errors.noBuilds);
|
|
97
83
|
return process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
98
84
|
}
|
|
99
85
|
if (buildIdToDeploy) {
|
|
100
86
|
const validationResult = validateBuildId(buildIdToDeploy, deployedBuildId, latestBuild.buildId, projectName, targetAccountId);
|
|
101
87
|
if (validationResult !== true) {
|
|
102
|
-
logger_1.
|
|
88
|
+
logger_1.uiLogger.error(validationResult.toString());
|
|
103
89
|
return process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
104
90
|
}
|
|
105
91
|
}
|
|
@@ -110,7 +96,7 @@ async function handler(args) {
|
|
|
110
96
|
else {
|
|
111
97
|
const deployBuildIdPromptResponse = await (0, promptUtils_1.promptUser)({
|
|
112
98
|
name: 'buildId',
|
|
113
|
-
message:
|
|
99
|
+
message: en_1.commands.project.deploy.deployBuildIdPrompt,
|
|
114
100
|
default: latestBuild.buildId === deployedBuildId
|
|
115
101
|
? undefined
|
|
116
102
|
: latestBuild.buildId,
|
|
@@ -120,30 +106,32 @@ async function handler(args) {
|
|
|
120
106
|
}
|
|
121
107
|
}
|
|
122
108
|
if (!buildIdToDeploy) {
|
|
123
|
-
logger_1.
|
|
109
|
+
logger_1.uiLogger.error(en_1.commands.project.deploy.errors.noBuildId);
|
|
124
110
|
return process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
125
111
|
}
|
|
126
112
|
const { data: deployResp } = await (0, projects_1.deployProject)(targetAccountId, projectName, buildIdToDeploy, (0, buildAndDeploy_1.useV3Api)(projectConfig?.platformVersion), forceOption);
|
|
127
|
-
if (!deployResp) {
|
|
128
|
-
logger_1.
|
|
113
|
+
if (!deployResp || deployResp.buildResultType !== 'DEPLOY_QUEUED') {
|
|
114
|
+
logger_1.uiLogger.error(en_1.commands.project.deploy.errors.deploy);
|
|
129
115
|
return process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
130
116
|
}
|
|
131
|
-
|
|
117
|
+
else if (formatOutputAsJson) {
|
|
118
|
+
jsonOutput.deployId = Number(deployResp.id);
|
|
119
|
+
}
|
|
120
|
+
const deployResult = await (0, buildAndDeploy_2.pollDeployStatus)(targetAccountId, projectName, Number(deployResp.id), buildIdToDeploy);
|
|
121
|
+
if (deployResult.status === constants_1.PROJECT_DEPLOY_TEXT.STATES.SUCCESS) {
|
|
122
|
+
deploySuccess = true;
|
|
123
|
+
}
|
|
132
124
|
}
|
|
133
125
|
catch (e) {
|
|
134
126
|
if ((0, index_1.isHubSpotHttpError)(e) && e.status === 404) {
|
|
135
|
-
logger_1.
|
|
136
|
-
projectName: chalk_1.default.bold(projectName),
|
|
137
|
-
accountIdentifier: (0, ui_2.uiAccountDescription)(targetAccountId),
|
|
138
|
-
command: (0, ui_2.uiCommandReference)('hs project upload'),
|
|
139
|
-
}));
|
|
127
|
+
logger_1.uiLogger.error(en_1.commands.project.deploy.errors.projectNotFound(targetAccountId, projectName));
|
|
140
128
|
}
|
|
141
129
|
else if ((0, index_1.isHubSpotHttpError)(e) && e.status === 400) {
|
|
142
130
|
if (e.data?.message && e.data?.errors) {
|
|
143
131
|
logDeployErrors(e.data);
|
|
144
132
|
}
|
|
145
133
|
else {
|
|
146
|
-
logger_1.
|
|
134
|
+
logger_1.uiLogger.error(e.message);
|
|
147
135
|
}
|
|
148
136
|
}
|
|
149
137
|
else {
|
|
@@ -154,33 +142,42 @@ async function handler(args) {
|
|
|
154
142
|
}
|
|
155
143
|
return process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
156
144
|
}
|
|
145
|
+
if (formatOutputAsJson) {
|
|
146
|
+
logger_1.uiLogger.json(jsonOutput);
|
|
147
|
+
}
|
|
148
|
+
if (deploySuccess) {
|
|
149
|
+
process.exit(exitCodes_1.EXIT_CODES.SUCCESS);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
153
|
+
}
|
|
157
154
|
}
|
|
158
155
|
function projectDeployBuilder(yargs) {
|
|
159
156
|
yargs.options({
|
|
160
157
|
project: {
|
|
161
|
-
describe:
|
|
158
|
+
describe: en_1.commands.project.deploy.options.project,
|
|
162
159
|
type: 'string',
|
|
163
160
|
},
|
|
164
161
|
build: {
|
|
165
162
|
alias: ['build-id'],
|
|
166
|
-
describe:
|
|
163
|
+
describe: en_1.commands.project.deploy.options.build,
|
|
167
164
|
type: 'number',
|
|
168
165
|
},
|
|
169
166
|
deployLatestBuild: {
|
|
170
167
|
alias: ['deploy-latest-build'],
|
|
171
|
-
describe:
|
|
168
|
+
describe: en_1.commands.project.deploy.options.deployLatestBuild,
|
|
172
169
|
default: false,
|
|
173
170
|
type: 'boolean',
|
|
174
171
|
},
|
|
175
172
|
profile: {
|
|
176
173
|
alias: ['p'],
|
|
177
|
-
describe:
|
|
174
|
+
describe: en_1.commands.project.deploy.options.profile,
|
|
178
175
|
type: 'string',
|
|
179
176
|
hidden: true,
|
|
180
177
|
},
|
|
181
178
|
force: {
|
|
182
179
|
alias: ['f'],
|
|
183
|
-
describe:
|
|
180
|
+
describe: en_1.commands.project.deploy.options.force,
|
|
184
181
|
default: false,
|
|
185
182
|
type: 'boolean',
|
|
186
183
|
},
|
|
@@ -188,13 +185,10 @@ function projectDeployBuilder(yargs) {
|
|
|
188
185
|
yargs.conflicts('profile', 'project');
|
|
189
186
|
yargs.conflicts('profile', 'account');
|
|
190
187
|
yargs.example([
|
|
191
|
-
[
|
|
192
|
-
'$0 project deploy',
|
|
193
|
-
(0, lang_1.i18n)(`commands.project.subcommands.deploy.examples.default`),
|
|
194
|
-
],
|
|
188
|
+
['$0 project deploy', en_1.commands.project.deploy.examples.default],
|
|
195
189
|
[
|
|
196
190
|
'$0 project deploy --project="my-project" --build=5',
|
|
197
|
-
|
|
191
|
+
en_1.commands.project.deploy.examples.withOptions,
|
|
198
192
|
],
|
|
199
193
|
]);
|
|
200
194
|
return yargs;
|
|
@@ -204,6 +198,7 @@ const builder = (0, yargsUtils_1.makeYargsBuilder)(projectDeployBuilder, command
|
|
|
204
198
|
useConfigOptions: true,
|
|
205
199
|
useAccountOptions: true,
|
|
206
200
|
useEnvironmentOptions: true,
|
|
201
|
+
useJSONOutputOptions: true,
|
|
207
202
|
});
|
|
208
203
|
const projectDeployCommand = {
|
|
209
204
|
command,
|
|
@@ -64,11 +64,12 @@ async function unifiedProjectDevFlow({ args, targetProjectAccountId, providedTar
|
|
|
64
64
|
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
65
65
|
}
|
|
66
66
|
let targetTestingAccountId = providedTargetTestingAccountId;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
// Temporarily removing logic to use profile account as testing account
|
|
68
|
+
// if (profileConfig) {
|
|
69
|
+
// // Bypass the prompt for the testing account if the user has a profile configured
|
|
70
|
+
// targetTestingAccountId = profileConfig.accountId;
|
|
71
|
+
// } else
|
|
72
|
+
if (
|
|
72
73
|
// Bypass the prompt for the testing account if default account is already a test account
|
|
73
74
|
!targetTestingAccountId &&
|
|
74
75
|
targetProjectAccountIsTestAccountOrSandbox) {
|
|
@@ -93,7 +94,7 @@ async function unifiedProjectDevFlow({ args, targetProjectAccountId, providedTar
|
|
|
93
94
|
}
|
|
94
95
|
else if (devAccountPromptResponse.createNestedAccount) {
|
|
95
96
|
// Create a new developer test account and automatically add it to the CLI config
|
|
96
|
-
targetTestingAccountId = await (0, helpers_1.createDeveloperTestAccountForLocalDev)(targetProjectAccountId, targetProjectAccountConfig, env);
|
|
97
|
+
targetTestingAccountId = await (0, helpers_1.createDeveloperTestAccountForLocalDev)(targetProjectAccountId, targetProjectAccountConfig, env, true);
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
else if (accountType === config_1.HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX) {
|
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const developerTestAccounts_1 = require("@hubspot/local-dev-lib/api/developerTestAccounts");
|
|
9
8
|
const path_2 = require("@hubspot/local-dev-lib/path");
|
|
10
9
|
const yargsUtils_1 = require("../../lib/yargsUtils");
|
|
11
10
|
const promptUtils_1 = require("../../lib/prompts/promptUtils");
|
|
@@ -16,8 +15,8 @@ const validation_1 = require("../../lib/validation");
|
|
|
16
15
|
const en_1 = require("../../lang/en");
|
|
17
16
|
const createDeveloperTestAccountConfigPrompt_1 = require("../../lib/prompts/createDeveloperTestAccountConfigPrompt");
|
|
18
17
|
const errorHandlers_1 = require("../../lib/errorHandlers");
|
|
19
|
-
const polling_1 = require("../../lib/polling");
|
|
20
18
|
const SpinniesManager_1 = __importDefault(require("../../lib/ui/SpinniesManager"));
|
|
19
|
+
const buildAccount_1 = require("../../lib/buildAccount");
|
|
21
20
|
const command = 'create';
|
|
22
21
|
const describe = en_1.commands.testAccount.create.describe;
|
|
23
22
|
async function handler(args) {
|
|
@@ -73,45 +72,20 @@ async function handler(args) {
|
|
|
73
72
|
text: en_1.commands.testAccount.create.polling.start(testAccountConfig.accountName),
|
|
74
73
|
});
|
|
75
74
|
try {
|
|
76
|
-
const
|
|
75
|
+
const result = await (0, buildAccount_1.createDeveloperTestAccountV3)(derivedAccountId, testAccountConfig);
|
|
77
76
|
if (formatOutputAsJson) {
|
|
78
|
-
jsonOutput.accountName =
|
|
79
|
-
jsonOutput.accountId =
|
|
77
|
+
jsonOutput.accountName = result.accountName;
|
|
78
|
+
jsonOutput.accountId = result.accountId;
|
|
79
|
+
jsonOutput.personalAccessKey = result.personalAccessKey;
|
|
80
80
|
}
|
|
81
|
-
testAccountId =
|
|
81
|
+
testAccountId = result.accountId;
|
|
82
82
|
}
|
|
83
83
|
catch (err) {
|
|
84
84
|
(0, errorHandlers_1.logError)(err);
|
|
85
|
-
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
86
|
-
}
|
|
87
|
-
SpinniesManager_1.default.update('createTestAccount', {
|
|
88
|
-
text: en_1.commands.testAccount.create.polling.syncing,
|
|
89
|
-
});
|
|
90
|
-
try {
|
|
91
|
-
await (0, polling_1.poll)(() => (0, developerTestAccounts_1.fetchDeveloperTestAccountGateSyncStatus)(derivedAccountId, testAccountId), {
|
|
92
|
-
successStates: ['SUCCESS'],
|
|
93
|
-
errorStates: [],
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
catch (err) {
|
|
97
|
-
(0, errorHandlers_1.debugError)(err);
|
|
98
85
|
SpinniesManager_1.default.fail('createTestAccount', {
|
|
99
|
-
text: en_1.commands.testAccount.create.polling.
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
// HACK: The status endpoint sometimes returns an early success status.
|
|
103
|
-
// Sleep for an extra 5 seconds to make sure the sync is actually complete.
|
|
104
|
-
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
105
|
-
try {
|
|
106
|
-
// Attempt to generate a new personal access key for the test account now that gate sync is complete.
|
|
107
|
-
const { data } = await (0, developerTestAccounts_1.generateDeveloperTestAccountPersonalAccessKey)(derivedAccountId, testAccountId);
|
|
108
|
-
jsonOutput.personalAccessKey = data.personalAccessKey;
|
|
109
|
-
}
|
|
110
|
-
catch (err) {
|
|
111
|
-
(0, errorHandlers_1.debugError)(err);
|
|
112
|
-
SpinniesManager_1.default.fail('createTestAccount', {
|
|
113
|
-
text: en_1.commands.testAccount.create.polling.failure,
|
|
86
|
+
text: en_1.commands.testAccount.create.polling.createFailure,
|
|
114
87
|
});
|
|
88
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
115
89
|
}
|
|
116
90
|
SpinniesManager_1.default.succeed('createTestAccount', {
|
|
117
91
|
text: en_1.commands.testAccount.create.polling.success(testAccountConfig.accountName, testAccountId),
|