Skip to content

Commit 8786aa3

Browse files
committed
feat: use DeployStages on all deploy commands
1 parent 75fd0c3 commit 8786aa3

File tree

7 files changed

+32
-114
lines changed

7 files changed

+32
-114
lines changed

src/commands/project/delete/source.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
requiredOrgFlagWithDeprecations,
3434
SfCommand,
3535
} from '@salesforce/sf-plugins-core';
36+
import { DeployStages } from '../../../utils/deployStages.js';
3637
import { writeConflictTable } from '../../../utils/conflicts.js';
3738
import { isNonDecomposedCustomLabel, isNonDecomposedCustomLabelsOrCustomLabel } from '../../../utils/metadataTypes.js';
3839
import { getFileResponseSuccessProps, tableHeader } from '../../../utils/output.js';
@@ -41,7 +42,6 @@ import { getPackageDirs, getSourceApiVersion } from '../../../utils/project.js';
4142
import { resolveApi, validateTests } from '../../../utils/deploy.js';
4243
import { DeployResultFormatter } from '../../../formatters/deployResultFormatter.js';
4344
import { DeleteResultFormatter } from '../../../formatters/deleteResultFormatter.js';
44-
import { DeployProgress } from '../../../utils/progressBar.js';
4545
import { DeployCache } from '../../../utils/deployCache.js';
4646
import { testLevelFlag, testsFlag } from '../../../utils/flags.js';
4747
const testFlags = 'Test';
@@ -244,8 +244,14 @@ export class Source extends SfCommand<DeleteSourceJson> {
244244

245245
// fire predeploy event for the delete
246246
await Lifecycle.getInstance().emit('predeploy', this.components);
247+
248+
const stages = new DeployStages({
249+
title: 'Deleting Metadata',
250+
jsonEnabled: this.jsonEnabled(),
251+
});
252+
247253
const isRest = (await resolveApi()) === API['REST'];
248-
this.log(`*** Deleting with ${isRest ? 'REST' : 'SOAP'} API ***`);
254+
stages.update({ message: `Deleting with ${isRest ? 'REST' : 'SOAP'} API` });
249255

250256
const deploy = await this.componentSet.deploy({
251257
usernameOrConnection: this.org.getUsername() as string,
@@ -257,7 +263,7 @@ export class Source extends SfCommand<DeleteSourceJson> {
257263
},
258264
});
259265

260-
new DeployProgress(deploy, this.jsonEnabled()).start();
266+
stages.start({ deploy, username: this.org.getUsername() });
261267
this.deployResult = await deploy.pollStatus({ timeout: this.flags.wait });
262268
if (!deploy.id) {
263269
throw new SfError('The deploy id is not available.');

src/commands/project/deploy/report.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import { Messages, Org, SfProject } from '@salesforce/core';
99
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
1010
import { ComponentSet, DeployResult, MetadataApiDeploy, RequestStatus } from '@salesforce/source-deploy-retrieve';
11+
import { DeployStages } from '../../../utils/deployStages.js';
1112
import { buildComponentSet } from '../../../utils/deploy.js';
12-
import { DeployProgress } from '../../../utils/progressBar.js';
1313
import { DeployCache } from '../../../utils/deployCache.js';
1414
import { DeployReportResultFormatter } from '../../../formatters/deployReportResultFormatter.js';
1515
import { API, DeployResultJson } from '../../../utils/types.js';
@@ -124,7 +124,10 @@ export default class DeployMetadataReport extends SfCommand<DeployResultJson> {
124124
if (wait) {
125125
// poll for deploy results
126126
try {
127-
new DeployProgress(mdapiDeploy, this.jsonEnabled()).start();
127+
new DeployStages({
128+
title: 'Deploying Metadata',
129+
jsonEnabled: this.jsonEnabled(),
130+
}).start({ deploy: mdapiDeploy, username: org.getUsername() });
128131
result = await mdapiDeploy.pollStatus(500, wait.seconds);
129132
} catch (error) {
130133
if (error instanceof Error && error.message.includes('The client has timed out')) {

src/commands/project/deploy/resume.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,11 @@ export default class DeployMetadataResume extends SfCommand<DeployResultJson> {
123123
jobId
124124
);
125125

126-
const stages = new DeployStages({
126+
new DeployStages({
127127
title: 'Resuming Deploy',
128128
jsonEnabled: this.jsonEnabled(),
129-
});
129+
}).start({ deploy, username: deployOpts['target-org'] });
130130

131-
stages.start({ deploy, username: deployOpts['target-org'] });
132131
result = await deploy.pollStatus(500, wait.seconds);
133132

134133
if (!deploy.id) {

src/commands/project/deploy/start.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export default class DeployMetadata extends SfCommand<DeployResultJson> {
218218
lifecycle.on('apiVersionDeploy', async (apiData: DeployVersionData) =>
219219
Promise.resolve(
220220
this.stages.update({
221-
apiMessage: messages.getMessage('apiVersionMsgDetailed', [
221+
message: messages.getMessage('apiVersionMsgDetailed', [
222222
flags['dry-run'] ? 'Deploying (dry-run)' : 'Deploying',
223223
// technically manifestVersion can be undefined, but only on raw mdapi deployments.
224224
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions

src/commands/project/deploy/validate.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import { EnvironmentVariable, Lifecycle, Messages, OrgConfigProperties, SfError
1111
import { CodeCoverageWarnings, DeployVersionData, RequestStatus } from '@salesforce/source-deploy-retrieve';
1212
import { Duration, ensureArray } from '@salesforce/kit';
1313
import { SfCommand, toHelpSection, Flags } from '@salesforce/sf-plugins-core';
14+
import { DeployStages } from '../../../utils/deployStages.js';
1415
import { AsyncDeployResultFormatter } from '../../../formatters/asyncDeployResultFormatter.js';
1516
import { DeployResultFormatter } from '../../../formatters/deployResultFormatter.js';
16-
import { DeployProgress } from '../../../utils/progressBar.js';
1717
import { DeployResultJson, TestLevel } from '../../../utils/types.js';
1818
import { executeDeploy, resolveApi, determineExitCode, validateTests } from '../../../utils/deploy.js';
1919
import { DEPLOY_STATUS_CODES_DESCRIPTIONS } from '../../../utils/errorCodes.js';
@@ -195,15 +195,18 @@ export default class DeployMetadataValidate extends SfCommand<DeployResultJson>
195195
if (!deploy.id) {
196196
throw new SfError('The deploy id is not available.');
197197
}
198-
this.log(`Deploy ID: ${ansis.bold(deploy.id)}`);
199198

200199
if (flags.async) {
200+
this.log(`Deploy ID: ${ansis.bold(deploy.id)}`);
201201
const asyncFormatter = new AsyncDeployResultFormatter(deploy.id);
202202
if (!this.jsonEnabled()) asyncFormatter.display();
203203
return asyncFormatter.getJson();
204204
}
205205

206-
new DeployProgress(deploy, this.jsonEnabled()).start();
206+
new DeployStages({
207+
title: 'Validating Deployment',
208+
jsonEnabled: this.jsonEnabled(),
209+
}).start({ deploy, username });
207210

208211
const result = await deploy.pollStatus(500, flags.wait?.seconds);
209212
process.exitCode = determineExitCode(result);

src/utils/deployStages.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Data = {
2121
mdapiDeploy: MetadataApiDeployStatus;
2222
sourceMemberPolling: SourceMemberPollingEvent;
2323
status: string;
24-
apiMessage: string;
24+
message: string;
2525
username: string;
2626
id: string;
2727
};
@@ -53,7 +53,7 @@ export class DeployStages {
5353
preStagesBlock: [
5454
{
5555
type: 'message',
56-
get: (data): string | undefined => data?.apiMessage,
56+
get: (data): string | undefined => data?.message,
5757
},
5858
],
5959
postStagesBlock: [
@@ -139,8 +139,13 @@ export class DeployStages {
139139
});
140140

141141
deploy.onFinish((data) => {
142-
this.ms.goto('Done', { mdapiDeploy: data.response, status: mdTransferMessages.getMessage(data.response.status) });
143-
this.ms.stop();
142+
this.ms.updateData({ mdapiDeploy: data.response, status: mdTransferMessages.getMessage(data.response.status) });
143+
if (data.response.status === RequestStatus.Failed) {
144+
this.ms.stop(new Error('Failed to deploy metadata'));
145+
} else {
146+
this.ms.goto('Done');
147+
this.ms.stop();
148+
}
144149
});
145150

146151
deploy.onCancel((data) => {

src/utils/progressBar.ts

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)