7
7
8
8
import * as os from 'os' ;
9
9
import { flags , FlagsConfig , SfdxCommand } from '@salesforce/command' ;
10
- import { Messages } from '@salesforce/core' ;
10
+ import { Messages , SfProject } from '@salesforce/core' ;
11
11
import { CliUx } from '@oclif/core' ;
12
12
import {
13
13
getContainerOptions ,
@@ -18,18 +18,37 @@ import {
18
18
PackageVersion ,
19
19
} from '@salesforce/packaging' ;
20
20
import { PackageVersionListResult } from '@salesforce/packaging/src/interfaces' ;
21
+ import { Optional } from '@salesforce/ts-types' ;
21
22
22
23
Messages . importMessagesDirectory ( __dirname ) ;
23
24
const messages = Messages . loadMessages ( '@salesforce/plugin-packaging' , 'package_version_list' ) ;
24
25
const packaging = Messages . loadMessages ( '@salesforce/plugin-packaging' , 'packaging' ) ;
25
26
26
27
type PackageVersionListCommandResult = Omit <
27
28
PackageVersionListResult ,
28
- 'HasMetadataRemoved' | 'IsReleased' | 'IsPasswordProtected'
29
+ | 'HasMetadataRemoved'
30
+ | 'IsReleased'
31
+ | 'IsPasswordProtected'
32
+ | 'HasPassedCodeCoverageCheck'
33
+ | 'CreatedById'
34
+ | 'BuildDurationInSeconds'
35
+ | 'CodeCoverage'
36
+ | 'Package2'
29
37
> & {
30
38
HasMetadataRemoved : string ;
31
39
IsPasswordProtected : string | boolean ;
32
40
IsReleased : string | boolean ;
41
+ HasPassedCodeCoverageCheck : string | boolean ;
42
+ BuildDurationInSeconds : string ;
43
+ CodeCoverage : string ;
44
+ NamespacePrefix : string ;
45
+ Package2Name : string ;
46
+ Version : string ;
47
+ InstallUrl : string ;
48
+ AncestorVersion : string ;
49
+ Alias : string ;
50
+ IsOrgDependent : 'N/A' | 'Yes' | 'No' ;
51
+ CreatedBy : string ;
33
52
} ;
34
53
35
54
export class PackageVersionListCommand extends SfdxCommand {
@@ -75,12 +94,12 @@ export class PackageVersionListCommand extends SfdxCommand {
75
94
} ;
76
95
77
96
public async run ( ) : Promise < PackageVersionListCommandResult [ ] > {
97
+ const project = SfProject . getInstance ( ) ;
78
98
const pv = new PackageVersion ( { connection : this . hubOrg . getConnection ( ) , project : undefined } ) ;
79
99
const packageIdOrAliases = ( this . flags . packages as string [ ] ) || [ ] ;
80
100
// resolve any passed in values from aliases or IDs
81
- const packages = packageIdOrAliases . map ( ( p ) => getPackageIdFromAlias ( p , this . project ) ?? p ) ;
101
+ const packages = packageIdOrAliases . map ( ( p ) => getPackageIdFromAlias ( p , project ) ?? p ) ;
82
102
const records = await pv . list ( {
83
- connection : this . hubOrg . getConnection ( ) ,
84
103
createdLastDays : this . flags . createdlastdays as number ,
85
104
concise : this . flags . concise as boolean ,
86
105
modifiedLastDays : this . flags . modifiedlastdays as number ,
@@ -93,8 +112,7 @@ export class PackageVersionListCommand extends SfdxCommand {
93
112
const results : PackageVersionListCommandResult [ ] = [ ] ;
94
113
95
114
if ( records ?. length > 0 ) {
96
- let ancestorVersionsMap ;
97
- let containerOptionsMap ;
115
+ let ancestorVersionsMap : Optional < Map < string , string > > ;
98
116
// lookup ancestorVersions if ancestorIds are present
99
117
const ancestorIds = records . filter ( ( record ) => record . AncestorId ) . map ( ( record ) => record . AncestorId ) ;
100
118
if ( ancestorIds ?. length > 0 ) {
@@ -103,21 +121,21 @@ export class PackageVersionListCommand extends SfdxCommand {
103
121
104
122
// Get the container options for each package version. We need this for determining if the version is OrgDependent
105
123
const recordIds = [ ...new Set ( records . map ( ( record ) => record . Package2Id ) ) ] ;
106
- containerOptionsMap = await getContainerOptions ( recordIds , this . hubOrg . getConnection ( ) ) ;
124
+ const containerOptionsMap = await getContainerOptions ( recordIds , this . hubOrg . getConnection ( ) ) ;
107
125
108
126
records . forEach ( ( record ) => {
109
127
const ids = [ record . Id , record . SubscriberPackageVersionId ] ;
110
128
const aliases = [ ] ;
111
129
ids . forEach ( ( id ) => {
112
- const matches = getPackageAliasesFromId ( id , this . project ) ;
130
+ const matches = getPackageAliasesFromId ( id , project ) ;
113
131
if ( matches . length > 0 ) {
114
132
aliases . push ( matches ) ;
115
133
}
116
134
} ) ;
117
135
const AliasStr = aliases . length > 0 ? aliases . join ( ) : '' ;
118
136
119
137
// set Ancestor display values
120
- let ancestorVersion = null ;
138
+ let ancestorVersion : Optional < string > = null ;
121
139
if ( record . AncestorId ) {
122
140
ancestorVersion = ancestorVersionsMap . get ( record . AncestorId ) ;
123
141
} else if ( containerOptionsMap . get ( record . Package2Id ) !== 'Managed' ) {
@@ -129,7 +147,7 @@ export class PackageVersionListCommand extends SfdxCommand {
129
147
const codeCoverage =
130
148
record . CodeCoverage != null
131
149
? `${ record . CodeCoverage . ApexCodeCoveragePercentage } %`
132
- : record . Package2 . IsOrgDependent === true || record . ValidationSkipped === true
150
+ : record . Package2 . IsOrgDependent || record . ValidationSkipped
133
151
? 'N/A'
134
152
: '' ;
135
153
@@ -141,16 +159,12 @@ export class PackageVersionListCommand extends SfdxCommand {
141
159
const isOrgDependent =
142
160
containerOptionsMap . get ( record . Package2Id ) === 'Managed'
143
161
? 'N/A'
144
- : record . Package2 . IsOrgDependent === true
162
+ : record . Package2 . IsOrgDependent
145
163
? 'Yes'
146
164
: 'No' ;
147
165
148
166
const hasMetadataRemoved =
149
- containerOptionsMap . get ( record . Package2Id ) !== 'Managed'
150
- ? 'N/A'
151
- : record . HasMetadataRemoved === true
152
- ? 'Yes'
153
- : 'No' ;
167
+ containerOptionsMap . get ( record . Package2Id ) !== 'Managed' ? 'N/A' : record . HasMetadataRemoved ? 'Yes' : 'No' ;
154
168
155
169
results . push ( {
156
170
Package2Id : record . Package2Id ,
@@ -175,7 +189,7 @@ export class PackageVersionListCommand extends SfdxCommand {
175
189
LastModifiedDate : record . LastModifiedDate , // moment(record.LastModifiedDate).format('YYYY-MM-DD HH:mm'),
176
190
// CreatedDate: moment(record.CreatedDate).format('YYYY-MM-DD HH:mm'),
177
191
// LastModifiedDate: moment(record.LastModifiedDate).format('YYYY-MM-DD HH:mm'),
178
- InstallUrl : INSTALL_URL_BASE + record . SubscriberPackageVersionId ,
192
+ InstallUrl : INSTALL_URL_BASE . toString ( ) + record . SubscriberPackageVersionId ,
179
193
CodeCoverage : codeCoverage ,
180
194
HasPassedCodeCoverageCheck : hasPassedCodeCoverageCheck ,
181
195
ValidationSkipped : record . ValidationSkipped ,
@@ -184,16 +198,17 @@ export class PackageVersionListCommand extends SfdxCommand {
184
198
Alias : AliasStr ,
185
199
IsOrgDependent : isOrgDependent ,
186
200
ReleaseVersion : record . ReleaseVersion == null ? '' : Number . parseFloat ( record . ReleaseVersion ) . toFixed ( 1 ) ,
187
- BuildDurationInSeconds : record . BuildDurationInSeconds == null ? '' : record . BuildDurationInSeconds ,
201
+ BuildDurationInSeconds : record . BuildDurationInSeconds == null ? '' : record . BuildDurationInSeconds . toString ( ) ,
188
202
HasMetadataRemoved : hasMetadataRemoved ,
189
203
CreatedBy : record . CreatedById ,
190
204
} ) ;
191
205
} ) ;
206
+ this . ux . styledHeader ( `Package Versions [${ results . length } ]` ) ;
207
+ this . ux . table ( results , this . getColumnData ( ) , { 'no-truncate' : true } ) ;
208
+ } else {
209
+ this . ux . log ( 'No results found' ) ;
192
210
}
193
211
194
- this . ux . styledHeader ( `Package Versions [${ results . length } ]` ) ;
195
- this . ux . table ( results , this . getColumnData ( ) ) ;
196
-
197
212
return results ;
198
213
}
199
214
@@ -208,26 +223,29 @@ export class PackageVersionListCommand extends SfdxCommand {
208
223
IsReleased : { header : 'Released' } ,
209
224
} ;
210
225
}
226
+ const defaultCols = {
227
+ Package2Name : { header : 'Package Name' } ,
228
+ NamespacePrefix : { header : 'Namespace' } ,
229
+ Name : { header : 'Version Name' } ,
230
+ Version : { header : messages . getMessage ( 'version' ) } ,
231
+ SubscriberPackageVersionId : {
232
+ header : messages . getMessage ( 'subscriberPackageVersionId' ) ,
233
+ } ,
234
+ Alias : { header : messages . getMessage ( 'alias' ) } ,
235
+ IsPasswordProtected : { header : messages . getMessage ( 'installKey' ) } ,
236
+ IsReleased : { header : 'Released' } ,
237
+ ValidationSkipped : { header : messages . getMessage ( 'validationSkipped' ) } ,
238
+ AncestorId : { header : 'Ancestor' } ,
239
+ AncestorVersion : { header : 'Ancestor Version' } ,
240
+ Branch : { header : messages . getMessage ( 'packageBranch' ) } ,
241
+ } ;
211
242
212
243
if ( ! this . flags . verbose ) {
213
- return {
214
- Package2Name : { header : 'Package Name' } ,
215
- NamespacePrefix : { header : 'Namespace' } ,
216
- Name : { header : 'Version Name' } ,
217
- Version : { header : messages . getMessage ( 'version' ) } ,
218
- SubscriberPackageVersionId : {
219
- header : messages . getMessage ( 'subscriberPackageVersionId' ) ,
220
- } ,
221
- Alias : { header : messages . getMessage ( 'alias' ) } ,
222
- IsPasswordProtected : { header : messages . getMessage ( 'installKey' ) } ,
223
- IsReleased : { header : 'Released' } ,
224
- ValidationSkipped : { header : messages . getMessage ( 'validationSkipped' ) } ,
225
- AncestorId : { header : 'Ancestor' } ,
226
- AncestorVersion : { header : 'Ancestor Version' } ,
227
- Branch : { header : messages . getMessage ( 'packageBranch' ) } ,
228
- } ;
244
+ return defaultCols ;
229
245
} else {
246
+ // add additional columns for verbose output
230
247
return {
248
+ ...defaultCols ,
231
249
Package2Id : { header : messages . getMessage ( 'packageId' ) } ,
232
250
InstallUrl : { header : messages . getMessage ( 'installUrl' ) } ,
233
251
Id : { header : messages . getMessage ( 'id' ) } ,
0 commit comments