UNPKG

@salesforce/plugin-packaging

Version:

SF plugin that support Salesforce Packaging Platform

83 lines 3.67 kB
/* * 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, SfCommand } from '@salesforce/sf-plugins-core'; import { Messages } from '@salesforce/core/messages'; import { Package } from '@salesforce/packaging'; import chalk from 'chalk'; import { requiredHubFlag } from '../../utils/hubFlag.js'; Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_list'); export class PackageListCommand extends SfCommand { static summary = messages.getMessage('summary'); static description = messages.getMessage('description'); static examples = messages.getMessages('examples'); static deprecateAliases = true; static aliases = ['force:package:list']; static flags = { loglevel, 'target-dev-hub': requiredHubFlag, 'api-version': orgApiVersionFlagWithDeprecations, verbose: Flags.boolean({ summary: messages.getMessage('flags.verbose.summary'), }), }; async run() { const { flags } = await this.parse(PackageListCommand); const connection = flags['target-dev-hub'].getConnection(flags['api-version']); const queryResult = await Package.list(connection); const results = mapRecordsToResults(queryResult); this.displayResults(results, flags.verbose, connection.getApiVersion()); return results; } displayResults(results, verbose = false, apiVersion) { const data = results.map((r) => ({ 'Namespace Prefix': r.NamespacePrefix, Name: r.Name, Id: r.Id, Alias: r.Alias, Description: r.Description, ContainerOptions: r.ContainerOptions, ...(verbose ? { 'Package Id': r.SubscriberPackageId, 'Converted From Package Id': r.ConvertedFromPackageId, 'Org-Dependent Unlocked Package': r.IsOrgDependent, 'Error Notification Username': r.PackageErrorUsername, 'Created By': r.CreatedBy, ...(parseInt(apiVersion, 10) >= 59 ? { 'App Analytics Enabled': r.AppAnalyticsEnabled } : {}), } : {}), })); this.table({ data, title: chalk.blue(`Packages [${results.length}]`) }); } } const mapRecordsToResults = (records, project) => records .filter((record) => record.IsDeprecated === false) .map(({ Id, SubscriberPackageId, Name, Description, NamespacePrefix, ContainerOptions, ConvertedFromPackageId, IsOrgDependent, PackageErrorUsername, AppAnalyticsEnabled, CreatedById, }) => ({ Id, SubscriberPackageId, Name, Description, NamespacePrefix, ContainerOptions, ConvertedFromPackageId, Alias: project ? project.getAliasesFromPackageId(Id).join() : '', IsOrgDependent: ContainerOptions === 'Managed' ? 'N/A' : IsOrgDependent ? 'Yes' : 'No', PackageErrorUsername, AppAnalyticsEnabled, CreatedBy: CreatedById, })); //# sourceMappingURL=list.js.map