Skip to content

Commit da05b38

Browse files
feat: added package version list
1 parent 366694b commit da05b38

File tree

7 files changed

+419
-1
lines changed

7 files changed

+419
-1
lines changed

command-snapshot.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@
7575
"alias": ["force:package:bundle:version:create"],
7676
"command": "package:bundle:version:create",
7777
"flagAliases": ["apiversion", "target-hub-org", "targetdevhubusername"],
78-
"flagChars": ["b", "p", "v", "w"],
78+
"flagChars": ["b", "d", "p", "v", "w"],
7979
"flags": [
8080
"api-version",
8181
"bundle",
8282
"definition-file",
83+
"description",
8384
"flags-dir",
8485
"json",
8586
"loglevel",
@@ -115,6 +116,14 @@
115116
"flags": ["api-version", "flags-dir", "json", "loglevel", "package-create-request-id", "target-dev-hub"],
116117
"plugin": "@salesforce/plugin-packaging"
117118
},
119+
{
120+
"alias": ["force:package:bundle:version:list"],
121+
"command": "package:bundle:version:list",
122+
"flagAliases": ["apiversion", "target-hub-org", "targetdevhubusername"],
123+
"flagChars": ["v"],
124+
"flags": ["api-version", "flags-dir", "json", "loglevel", "target-dev-hub", "verbose"],
125+
"plugin": "@salesforce/plugin-packaging"
126+
},
118127
{
119128
"alias": ["force:package:convert"],
120129
"command": "package:convert",

messages/bundle_version_create.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ Show verbose output of the command execution.
3232

3333
Show detailed information about the bundle version creation process.
3434

35+
# flags.description.summary
36+
37+
Description of the package bundle version.
38+
3539
# bundleVersionCreateWaitingStatus
3640

3741
Waiting for bundle version creation to complete. %s minutes remaining. Current status: %s

messages/bundle_version_list.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# summary
2+
3+
List all package bundle versions in the Dev Hub org.
4+
5+
# examples
6+
7+
List all package bundle versions in the specified Dev Hub org; uses the Dev Hub org with the username [email protected]:
8+
9+
sf package bundle version list --target-dev-hub <dev_hub_alias>
10+
11+
# namespace
12+
13+
Namespace Prefix
14+
15+
# name
16+
17+
Name
18+
19+
# id
20+
21+
Id
22+
23+
# bundle-id
24+
25+
Package Bundle Id
26+
27+
# alias
28+
29+
Alias
30+
31+
# description
32+
33+
Description
34+
35+
# flags.verbose.summary
36+
37+
Display extended bundle detail.
38+
39+
# error-notification-username
40+
41+
Error Notification Username
42+
43+
# createdBy
44+
45+
Created By
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$ref": "#/definitions/PackageBundleVersionResults",
4+
"definitions": {
5+
"PackageBundleVersionResults": {
6+
"type": "array",
7+
"items": {
8+
"$ref": "#/definitions/BundleSObjects.BundleVersion"
9+
}
10+
},
11+
"BundleSObjects.BundleVersion": {
12+
"type": "object",
13+
"properties": {
14+
"Id": {
15+
"type": "string"
16+
},
17+
"PackageBundle": {
18+
"$ref": "#/definitions/BundleSObjects.Bundle"
19+
},
20+
"VersionName": {
21+
"type": "string"
22+
},
23+
"MajorVersion": {
24+
"type": "string"
25+
},
26+
"MinorVersion": {
27+
"type": "string"
28+
},
29+
"Ancestor": {
30+
"anyOf": [
31+
{
32+
"$ref": "#/definitions/BundleSObjects.BundleVersion"
33+
},
34+
{
35+
"type": "null"
36+
}
37+
]
38+
},
39+
"IsReleased": {
40+
"type": "boolean"
41+
},
42+
"CreatedDate": {
43+
"type": "string"
44+
},
45+
"CreatedById": {
46+
"type": "string"
47+
},
48+
"LastModifiedDate": {
49+
"type": "string"
50+
},
51+
"LastModifiedById": {
52+
"type": "string"
53+
}
54+
},
55+
"required": [
56+
"Id",
57+
"PackageBundle",
58+
"VersionName",
59+
"MajorVersion",
60+
"MinorVersion",
61+
"IsReleased",
62+
"CreatedDate",
63+
"CreatedById",
64+
"LastModifiedDate",
65+
"LastModifiedById"
66+
],
67+
"additionalProperties": false
68+
},
69+
"BundleSObjects.Bundle": {
70+
"type": "object",
71+
"properties": {
72+
"BundleName": {
73+
"type": "string"
74+
},
75+
"Description": {
76+
"type": "string"
77+
},
78+
"Id": {
79+
"type": "string"
80+
},
81+
"IsDeleted": {
82+
"type": "boolean"
83+
},
84+
"CreatedDate": {
85+
"type": "string"
86+
},
87+
"CreatedById": {
88+
"type": "string"
89+
},
90+
"LastModifiedDate": {
91+
"type": "string"
92+
},
93+
"LastModifiedById": {
94+
"type": "string"
95+
},
96+
"SystemModstamp": {
97+
"type": "string"
98+
}
99+
},
100+
"required": [
101+
"BundleName",
102+
"Id",
103+
"IsDeleted",
104+
"CreatedDate",
105+
"CreatedById",
106+
"LastModifiedDate",
107+
"LastModifiedById",
108+
"SystemModstamp"
109+
],
110+
"additionalProperties": false
111+
}
112+
}
113+
}

src/commands/package/bundle/version/create.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ export class PackageBundlesCreate extends SfCommand<BundleSObjects.PackageBundle
3434
summary: messages.getMessage('flags.bundle.summary'),
3535
required: true,
3636
}),
37+
description: Flags.string({
38+
char: 'd',
39+
summary: messages.getMessage('flags.description.summary'),
40+
}),
3741
'definition-file': Flags.string({
3842
char: 'p',
3943
summary: messages.getMessage('flags.definition-file.summary'),
@@ -58,6 +62,7 @@ export class PackageBundlesCreate extends SfCommand<BundleSObjects.PackageBundle
5862
project: this.project!,
5963
PackageBundle: flags.bundle,
6064
BundleVersionComponentsPath: flags['definition-file'],
65+
Description: flags.description,
6166
MajorVersion: '',
6267
MinorVersion: '',
6368
Ancestor: '',
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* Copyright (c) 2022, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
import { Flags, loglevel, orgApiVersionFlagWithDeprecations, SfCommand } from '@salesforce/sf-plugins-core';
9+
import { Connection, Messages } from '@salesforce/core';
10+
import { PackageVersion, getPackageVersionNumber, BundleSObjects, PackageBundleVersion } from '@salesforce/packaging';
11+
import chalk from 'chalk';
12+
import { requiredHubFlag } from '../../../../utils/hubFlag.js';
13+
14+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
15+
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'bundle_version_list');
16+
17+
export type PackageBundleVersionResults = BundleSObjects.BundleVersion[];
18+
19+
export class PackageBundleVersionListCommand extends SfCommand<PackageBundleVersionResults> {
20+
public static readonly summary = messages.getMessage('summary');
21+
public static readonly description = messages.getMessage('description');
22+
public static readonly examples = messages.getMessages('examples');
23+
public static readonly deprecateAliases = true;
24+
public static readonly aliases = ['force:package:bundle:version:list'];
25+
public static readonly flags = {
26+
loglevel,
27+
'target-dev-hub': requiredHubFlag,
28+
'api-version': orgApiVersionFlagWithDeprecations,
29+
verbose: Flags.boolean({
30+
summary: messages.getMessage('flags.verbose.summary'),
31+
}),
32+
};
33+
34+
private connection!: Connection;
35+
36+
public async run(): Promise<PackageBundleVersionResults> {
37+
const { flags } = await this.parse(PackageBundleVersionListCommand);
38+
this.connection = flags['target-dev-hub'].getConnection(flags['api-version']);
39+
let results = await PackageBundleVersion.list(this.connection);
40+
41+
if (results.length === 0) {
42+
this.warn('No results found');
43+
} else {
44+
if (flags.verbose) {
45+
try {
46+
results = await this.fetchVerboseData(results);
47+
} catch (err) {
48+
const errMsg = typeof err === 'string' ? err : err instanceof Error ? err.message : 'unknown error';
49+
this.warn(`error when retrieving verbose data (package name and version) due to: ${errMsg}`);
50+
}
51+
}
52+
53+
const data = results.map((r) => ({
54+
'Bundle Name': r.PackageBundle.BundleName ?? 'N/A',
55+
'Bundle Id': r.PackageBundle.Id ?? 'N/A',
56+
'Bundle Version Number': String(r.MajorVersion ?? 'N/A') + '.' + String(r.MinorVersion ?? 'N/A'),
57+
'Bundle Version Id': r.Id ?? 'N/A',
58+
'Bundle Version Name': r.VersionName ?? 'N/A',
59+
'Bundle Version Description': r.PackageBundle.Description ?? 'N/A',
60+
...(flags.verbose
61+
? {
62+
'Ancestor Id': r.Ancestor?.Id ?? 'N/A',
63+
'Ancestor Name': r.Ancestor?.PackageBundle.BundleName ?? 'N/A',
64+
'Ancestor Version Name': r.Ancestor?.VersionName ?? 'N/A',
65+
'Ancestor Version':
66+
String(r.Ancestor?.MajorVersion ?? 'N/A') + '.' + String(r.Ancestor?.MinorVersion ?? 'N/A'),
67+
'Created Date': r.CreatedDate ?? 'N/A',
68+
'Created By': r.CreatedById ?? 'N/A',
69+
'Last Modified Date': r.LastModifiedDate ?? 'N/A',
70+
'Last Modified By': r.LastModifiedById ?? 'N/A',
71+
}
72+
: {}),
73+
}));
74+
75+
this.table({
76+
data,
77+
overflow: 'wrap',
78+
title: chalk.blue(`Package Bundle Version List [${results.length}]`),
79+
});
80+
}
81+
82+
return results;
83+
}
84+
85+
// Queries Package2Version for the name and version number of the packages and adds that data
86+
// to the results.
87+
private async fetchVerboseData(results: PackageBundleVersionResults): Promise<PackageBundleVersionResults> {
88+
type VersionDataMap = {
89+
[id: string]: { name: string; version: string };
90+
};
91+
92+
// Filter out any results without a valid PackageBundleVersionId
93+
const validResults = results.filter((r) => r?.Id);
94+
if (validResults.length === 0) {
95+
return results;
96+
}
97+
98+
// Query for the version name and number data
99+
const versionData = await PackageVersion.queryPackage2Version(this.connection, {
100+
fields: [
101+
'Id',
102+
'Name',
103+
'MajorVersion',
104+
'MinorVersion',
105+
'PatchVersion',
106+
'BuildNumber',
107+
'CreatedDate',
108+
'CreatedById',
109+
'LastModifiedDate',
110+
'LastModifiedById',
111+
'SystemModstamp',
112+
],
113+
whereClause: "WHERE Id IN ('%IDS%')",
114+
whereClauseItems: validResults.map((pvcrr) => pvcrr.Id),
115+
});
116+
117+
const vDataMap: VersionDataMap = {};
118+
versionData.forEach((vData) => {
119+
if (vData?.Id) {
120+
const version = getPackageVersionNumber(vData, true);
121+
vDataMap[vData.Id] = { name: vData.Name, version };
122+
}
123+
});
124+
125+
return results.map((pvcrr) => {
126+
if (pvcrr?.Id && vDataMap[pvcrr.Id]) {
127+
return {
128+
...pvcrr,
129+
...{
130+
VersionName: vDataMap[pvcrr.Id].name,
131+
VersionNumber: vDataMap[pvcrr.Id].version,
132+
},
133+
};
134+
}
135+
return pvcrr;
136+
});
137+
}
138+
}

0 commit comments

Comments
 (0)