generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
report.ts
131 lines (120 loc) · 4.73 KB
/
report.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* Copyright (c) 2022, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { Flags, loglevel, orgApiVersionFlagWithDeprecations, SfCommand } from '@salesforce/sf-plugins-core';
import { Messages, Org } from '@salesforce/core';
import pkgUtils from '@salesforce/packaging';
import { PackageVersion, PackageVersionCreateRequestResult } from '@salesforce/packaging';
import chalk from 'chalk';
import { camelCaseToTitleCase } from '@salesforce/kit';
import { requiredHubFlag } from '../../../../utils/hubFlag.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_version_create_report');
const pvclMessages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_version_create_list');
const pvlMessages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_version_list');
const plMessages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_list');
const ERROR_LIMIT = 12;
export type ReportCommandResult = PackageVersionCreateRequestResult[];
export class PackageVersionCreateReportCommand extends SfCommand<ReportCommandResult> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');
public static readonly deprecateAliases = true;
public static readonly aliases = ['force:package:version:create:report'];
public static readonly flags = {
loglevel,
'target-dev-hub': requiredHubFlag,
'api-version': orgApiVersionFlagWithDeprecations,
// eslint-disable-next-line sf-plugin/id-flag-suggestions
'package-create-request-id': Flags.salesforceId({
length: 'both',
deprecateAliases: true,
aliases: ['packagecreaterequestid'],
char: 'i',
summary: messages.getMessage('flags.package-create-request-id.summary'),
required: true,
}),
};
public async run(): Promise<ReportCommandResult> {
const { flags } = await this.parse(PackageVersionCreateReportCommand);
const result = await PackageVersion.getCreateStatus(
flags['package-create-request-id'],
flags['target-dev-hub'].getConnection(flags['api-version'])
);
this.display(result, flags['package-create-request-id'], flags['target-dev-hub']);
return [result];
}
private display(record: PackageVersionCreateRequestResult, requestId: string, devOrg: Org): void {
const installUrlValue =
record.Status.toString() === 'Success'
? `${pkgUtils.INSTALL_URL_BASE.toString()}${record.SubscriberPackageVersionId}`
: '';
const data = [
{
key: pvclMessages.getMessage('id'),
value: record.Id,
},
{
key: pvclMessages.getMessage('status'),
value: camelCaseToTitleCase(record.Status),
},
{
key: pvclMessages.getMessage('package-id'),
value: record.Package2Id,
},
{
key: pvclMessages.getMessage('packageVersionId'),
value: record.Package2VersionId,
},
{
key: pvclMessages.getMessage('subscriberPackageVersionId'),
value: record.SubscriberPackageVersionId,
},
{
key: pvclMessages.getMessage('tag'),
value: record.Tag,
},
{
key: pvclMessages.getMessage('branch'),
value: record.Branch,
},
{ key: 'Created Date', value: record.CreatedDate },
{
key: pvclMessages.getMessage('installUrl'),
value: installUrlValue,
},
{
key: plMessages.getMessage('createdBy'),
value: record.CreatedBy,
},
];
if (record.ConvertedFromVersionId) {
data.push({
key: pvlMessages.getMessage('convertedFromVersionId'),
value: record.ConvertedFromVersionId,
});
}
this.styledHeader(chalk.blue('Package Version Create Request'));
this.table(data, {
key: { header: 'Name' },
value: { header: 'Value' },
});
if (record.Error?.length > 0) {
this.log('');
const errors: string[] = [];
record.Error.slice(0, ERROR_LIMIT).forEach((error: string) => {
errors.push(`(${errors.length + 1}) ${error}`);
});
this.styledHeader(chalk.red('Errors'));
this.warn(errors.join('\n'));
// Check if errors were truncated. If so, inform the user with
// instructions on how to retrieve the remaining errors.
if (record.Error.length > ERROR_LIMIT) {
this.warn(messages.getMessage('truncatedErrors', [this.config.bin, requestId, devOrg.getUsername() as string]));
}
}
}
}