@@ -2,7 +2,7 @@ import * as vscode from 'vscode';
2
2
import open from 'open' ;
3
3
4
4
import { forEachAsyncParallel } from '@vlocode/util' ;
5
- import { DeployResult , DeployStatus , RetrieveDeltaStrategy , SalesforceDeployment , SalesforcePackage , SalesforcePackageBuilder , SalesforcePackageType } from '@vlocode/salesforce' ;
5
+ import { DeployResult , RetrieveDeltaStrategy , SalesforceDeployment , SalesforcePackage , SalesforcePackageBuilder , SalesforcePackageType } from '@vlocode/salesforce' ;
6
6
7
7
import { VlocodeCommand } from '../../constants' ;
8
8
import { ActivityProgress } from '../../lib/vlocodeActivity' ;
@@ -17,6 +17,11 @@ import { container } from '@vlocode/core';
17
17
@vscodeCommand ( VlocodeCommand . deployDeltaMetadata , { focusLog : true , showProductionWarning : true , executeParams : [ VlocodeCommand . deployDeltaMetadata ] } )
18
18
export default class DeployMetadataCommand extends MetadataCommand {
19
19
20
+ protected deployStatusLabels = {
21
+ 'InProgress' : 'In Progress' ,
22
+ 'SucceededPartial' : 'Partially Deployed'
23
+ } ;
24
+
20
25
/**
21
26
* In order to prevent double deployment keep a list of pending deploy ops
22
27
*/
@@ -132,12 +137,15 @@ export default class DeployMetadataCommand extends MetadataCommand {
132
137
if ( ! deployPackage ) {
133
138
break ;
134
139
}
140
+ const deployment = new SalesforceDeployment ( deployPackage ) ;
135
141
await this . vlocode . withActivity ( {
136
142
progressTitle : `Deploy ${ deployPackage . componentsDescription } ` ,
137
143
location : vscode . ProgressLocation . Notification ,
138
144
propagateExceptions : false ,
139
145
cancellable : true
140
- } , this . getDeploymentActivity ( deployPackage ) ) ;
146
+ } , async ( progress : ActivityProgress , token : vscode . CancellationToken ) => {
147
+ await this . monitorDeployment ( deployment , progress , token ) ;
148
+ } ) ;
141
149
}
142
150
} finally {
143
151
this . deploymentRunning = false ;
@@ -146,51 +154,39 @@ export default class DeployMetadataCommand extends MetadataCommand {
146
154
} , 250 ) ;
147
155
}
148
156
149
- private getDeploymentActivity ( sfPackage : SalesforcePackage ) {
150
- return async ( progress : ActivityProgress , token : vscode . CancellationToken ) => {
151
- progress . report ( { message : `scheduling` } ) ;
152
-
153
- // start deployment
154
- const deployment = new SalesforceDeployment ( sfPackage ) ;
155
- const progressReporter = deployment . on ( 'progress' , result => {
156
- if ( deployment . isServerSideCancelled ) {
157
- progress . report ( { message : 'Server-side cancellation requested' } ) ;
158
- progressReporter . dispose ( ) ;
159
- } else {
160
- progress . report ( {
161
- message : `${ this . getStatusLabel ( result . status ) } ${ result . total ? `${ result . deployed } /${ result . total } ` : '' } ` ,
162
- progress : result . deployed ,
163
- total : result . total
164
- } ) ;
165
- }
166
- } ) ;
157
+ protected async monitorDeployment ( deployment : SalesforceDeployment , progress : ActivityProgress , token : vscode . CancellationToken ) {
158
+ progress . report ( { message : `scheduling` } ) ;
167
159
168
- token . onCancellationRequested ( ( ) => {
169
- progress . report ( { message : 'Cancellation in progress' } ) ;
160
+ // start deployment
161
+ const progressReporter = deployment . on ( 'progress' , result => {
162
+ if ( deployment . isServerSideCancelled ) {
163
+ progress . report ( { message : 'Server-side cancellation requested' } ) ;
170
164
progressReporter . dispose ( ) ;
171
- deployment . cancel ( ) ;
172
- } ) ;
173
-
174
- await deployment . start ( { ignoreWarnings : true } ) ;
175
- this . logger . info ( `Deployment details: ${ await this . vlocode . salesforceService . getPageUrl ( deployment . setupUrl ) } ` ) ;
176
- const result = await deployment . getResult ( ) ;
177
-
178
- if ( deployment . isCancelled ) {
179
- return ;
165
+ } else {
166
+ progress . report ( {
167
+ message : `${ this . deployStatusLabels [ result . status ] ?? result . status } ${ result . total ? `${ result . deployed } /${ result . total } ` : '' } ` ,
168
+ progress : result . deployed ,
169
+ total : result . total
170
+ } ) ;
180
171
}
172
+ } ) ;
181
173
182
- this . outputDeployResult ( sfPackage . components ( ) , result ) ;
183
- return this . onDeploymentComplete ( deployment , result ) ;
184
- } ;
185
- }
174
+ token . onCancellationRequested ( ( ) => {
175
+ progress . report ( { message : 'Cancellation in progress' } ) ;
176
+ progressReporter . dispose ( ) ;
177
+ deployment . cancel ( ) ;
178
+ } ) ;
179
+
180
+ await deployment . start ( { ignoreWarnings : true } ) ;
181
+ this . logger . info ( `Deployment details: ${ await this . vlocode . salesforceService . getPageUrl ( deployment . setupUrl ) } ` ) ;
182
+ const result = await deployment . getResult ( ) ;
186
183
187
- private getStatusLabel ( status : DeployStatus ) {
188
- if ( status === 'InProgress' ) {
189
- return 'In Progress' ;
190
- } else if ( status === 'SucceededPartial' ) {
191
- return 'Partially Deployed' ;
184
+ if ( deployment . isCancelled ) {
185
+ return ;
192
186
}
193
- return status ;
187
+
188
+ this . outputDeployResult ( deployment . deploymentPackage . components ( ) , result ) ;
189
+ return this . onDeploymentComplete ( deployment , result ) ;
194
190
}
195
191
196
192
private onDeploymentComplete ( deployment : SalesforceDeployment , result : DeployResult ) {
0 commit comments