@salesforce/plugin-packaging
Version:
SF plugin that support Salesforce Packaging Platform
109 lines • 4.78 kB
JavaScript
/*
* Copyright 2025, Salesforce, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Flags, loglevel, orgApiVersionFlagWithDeprecations, requiredHubFlagWithDeprecations, requiredOrgFlagWithDeprecations, SfCommand, } from '@salesforce/sf-plugins-core';
import { BundleSObjects, PackageBundleInstall } from '@salesforce/packaging';
import { Messages, Lifecycle } from '@salesforce/core';
import { camelCaseToTitleCase, Duration } from '@salesforce/kit';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'bundle_install');
export class PackageBundlesInstall extends SfCommand {
static hidden = true;
static state = 'beta';
static summary = messages.getMessage('summary');
static description = messages.getMessage('description');
static examples = messages.getMessages('examples');
static requiresProject = true;
static flags = {
loglevel,
bundle: Flags.string({
char: 'b',
summary: messages.getMessage('flags.bundle.summary'),
required: true,
}),
'target-org': requiredOrgFlagWithDeprecations,
'api-version': orgApiVersionFlagWithDeprecations,
'target-dev-hub': requiredHubFlagWithDeprecations,
wait: Flags.integer({
char: 'w',
summary: messages.getMessage('flags.wait.summary'),
default: 0,
}),
verbose: Flags.boolean({
summary: messages.getMessage('flags.verbose.summary'),
}),
};
async run() {
const { flags } = await this.parse(PackageBundlesInstall);
// Get the target org connection
const targetOrg = flags['target-org'];
const targetDevHub = flags['target-dev-hub'];
const connection = targetOrg.getConnection(flags['api-version']);
const devHubOrgId = targetDevHub.getOrgId();
const options = {
connection,
project: this.project,
PackageBundleVersion: flags.bundle,
DevelopmentOrganization: devHubOrgId,
};
// Set up lifecycle events for progress tracking
Lifecycle.getInstance().on('bundle-install-progress',
// no async methods
// eslint-disable-next-line @typescript-eslint/require-await
async (data) => {
if (data.InstallStatus !== BundleSObjects.PkgBundleVersionInstallReqStatus.success &&
data.InstallStatus !== BundleSObjects.PkgBundleVersionInstallReqStatus.error) {
const status = messages.getMessage('bundleInstallWaitingStatus', [
data.remainingWaitTime.minutes,
data.InstallStatus,
]);
if (flags.verbose) {
this.log(status);
}
else {
this.spinner.status = status;
}
}
});
const result = await PackageBundleInstall.installBundle(connection, this.project, {
...options,
...(flags.wait && flags.wait > 0
? { polling: { timeout: Duration.minutes(flags.wait), frequency: Duration.seconds(5) } }
: undefined),
});
const finalStatusMsg = messages.getMessage('bundleInstallFinalStatus', [result.InstallStatus]);
if (flags.verbose) {
this.log(finalStatusMsg);
}
else {
this.spinner.stop(finalStatusMsg);
}
switch (result.InstallStatus) {
case BundleSObjects.PkgBundleVersionInstallReqStatus.error:
throw messages.createError('bundleInstallError', [result.ValidationError || 'Unknown error']);
case BundleSObjects.PkgBundleVersionInstallReqStatus.success:
this.log(messages.getMessage('bundleInstallSuccess', [result.Id]));
break;
default:
this.log(messages.getMessage('bundleInstallInProgress', [
camelCaseToTitleCase(result.InstallStatus),
result.Id,
targetOrg.getUsername() ?? '',
]));
}
return result;
}
}
//# sourceMappingURL=install.js.map