@salesforce/plugin-packaging
Version:
SF plugin that support Salesforce Packaging Platform
80 lines • 3.33 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 path from 'node:path';
import { Flags, loglevel, orgApiVersionFlagWithDeprecations, requiredHubFlagWithDeprecations, SfCommand, } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core/messages';
import { Package } from '@salesforce/packaging';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_version_retrieve');
export class PackageVersionRetrieveCommand extends SfCommand {
static hidden = true;
static summary = messages.getMessage('summary');
static description = messages.getMessage('description');
static examples = messages.getMessages('examples');
static requiresProject = true;
static flags = {
loglevel,
'api-version': orgApiVersionFlagWithDeprecations,
'target-dev-hub': requiredHubFlagWithDeprecations,
package: Flags.string({
char: 'p',
summary: messages.getMessage('flags.package.summary'),
required: true,
}),
'output-dir': Flags.directory({
char: 'd',
summary: messages.getMessage('flags.output-dir.summary'),
default: 'force-app',
}),
};
async run() {
const { flags } = await this.parse(PackageVersionRetrieveCommand);
const connection = flags['target-dev-hub'].getConnection(flags['api-version']);
const options = {
subscriberPackageVersionId: flags.package ?? '',
destinationFolder: flags['output-dir'],
};
const result = await Package.downloadPackageVersionMetadata(this.project, options, connection);
const results = [];
result.converted?.forEach((component) => {
if (component.xml) {
results.push({
fullName: component.fullName,
type: component.type.name,
filePath: path.relative('.', component.xml),
});
}
if (component.content) {
results.push({
fullName: component.fullName,
type: component.type.name,
filePath: path.relative('.', component.content),
});
}
});
this.table({
data: results,
columns: [
{ key: 'fullName', name: messages.getMessage('headers.fullName') },
{ key: 'type', name: messages.getMessage('headers.type') },
{ key: 'filePath', name: messages.getMessage('headers.filePath') },
],
overflow: 'wrap',
});
return results;
}
}
//# sourceMappingURL=retrieve.js.map