|
| 1 | +/* |
| 2 | + * Copyright (c) 2023, 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 { Messages } from '@salesforce/core/messages'; |
| 10 | +import { PackageBundle, BundleSObjects } from '@salesforce/packaging'; |
| 11 | +import chalk from 'chalk'; |
| 12 | +import { requiredHubFlag } from '../../../utils/hubFlag.js'; |
| 13 | + |
| 14 | +// This is a near copy of the package list command, but with the package bundle class and messages. |
| 15 | +// If you are looking to copy this command, mabye make an abstract class for the commands that are similar.(please) |
| 16 | +Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); |
| 17 | +const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'bundle_list'); |
| 18 | + |
| 19 | +export type BundleListCommandResult = BundleSObjects.Bundle; |
| 20 | +export type BundleListCommandResults = BundleListCommandResult[]; |
| 21 | + |
| 22 | +export class BundleListCommand extends SfCommand<BundleListCommandResults> { |
| 23 | + public static readonly summary = messages.getMessage('summary'); |
| 24 | + public static readonly examples = messages.getMessages('examples'); |
| 25 | + public static readonly deprecateAliases = true; |
| 26 | + public static readonly aliases = ['force:package:bundle:list']; |
| 27 | + public static readonly flags = { |
| 28 | + loglevel, |
| 29 | + 'target-dev-hub': requiredHubFlag, |
| 30 | + 'api-version': orgApiVersionFlagWithDeprecations, |
| 31 | + verbose: Flags.boolean({ |
| 32 | + summary: messages.getMessage('flags.verbose.summary'), |
| 33 | + }), |
| 34 | + }; |
| 35 | + |
| 36 | + public async run(): Promise<BundleListCommandResults> { |
| 37 | + const { flags } = await this.parse(BundleListCommand); |
| 38 | + const connection = flags['target-dev-hub'].getConnection(flags['api-version']); |
| 39 | + const results = await PackageBundle.list(connection); |
| 40 | + this.displayResults(results, flags.verbose); |
| 41 | + return results; |
| 42 | + } |
| 43 | + |
| 44 | + private displayResults(results: BundleListCommandResults, verbose = false): void { |
| 45 | + const data = results.map((r) => ({ |
| 46 | + 'Package Bundle Name': r.BundleName, |
| 47 | + Id: r.Id, |
| 48 | + Description: r.Description, |
| 49 | + ...(verbose |
| 50 | + ? { |
| 51 | + 'Created Date': r.CreatedDate, |
| 52 | + 'Created By': r.CreatedById, |
| 53 | + 'Last Modified Date': r.LastModifiedDate, |
| 54 | + 'Last Modified By': r.LastModifiedById, |
| 55 | + 'System Modstamp': r.SystemModstamp, |
| 56 | + 'Is Deleted': r.IsDeleted, |
| 57 | + } |
| 58 | + : {}), |
| 59 | + })); |
| 60 | + this.table({ data, title: chalk.blue(`Package Bundles [${results.length}]`) }); |
| 61 | + } |
| 62 | +} |
0 commit comments