From c81f08371081018457d9e864cf7fa02b144bf9b1 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Mon, 29 Aug 2022 10:52:31 -0600 Subject: [PATCH] fix: only required refactoring - waiting on packaging to enable na40 to convert --- src/commands/force/package/beta/convert.ts | 62 ++++++++++++++++++++-- 1 file changed, 58 insertions(+), 4 deletions(-) diff --git a/src/commands/force/package/beta/convert.ts b/src/commands/force/package/beta/convert.ts index 6f4f742d..cfb5f9f7 100644 --- a/src/commands/force/package/beta/convert.ts +++ b/src/commands/force/package/beta/convert.ts @@ -8,10 +8,20 @@ import * as os from 'os'; import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command'; import { Duration } from '@salesforce/kit'; -import { Messages } from '@salesforce/core'; +import { Lifecycle, Messages, SfProject } from '@salesforce/core'; +import { + convertCamelCaseStringToSentence, + INSTALL_URL_BASE, + Package, + PackageVersionCreateEventData, + PackageVersionCreateRequestResult, + PackagingSObjects, +} from '@salesforce/packaging'; +import Package2VersionStatus = PackagingSObjects.Package2VersionStatus; Messages.importMessagesDirectory(__dirname); const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_convert'); +const pvcMessages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_version_create'); export class PackageConvert extends SfdxCommand { public static readonly description = messages.getMessage('cliDescription'); @@ -52,8 +62,52 @@ export class PackageConvert extends SfdxCommand { }), }; - // eslint-disable-next-line @typescript-eslint/require-await - public async run(): Promise { - throw new Error('Beta command not yet implemented'); + public async run(): Promise { + // eslint-disable-next-line @typescript-eslint/require-await + Lifecycle.getInstance().on(Package2VersionStatus.inProgress, async (data: PackageVersionCreateEventData) => { + this.ux.log( + `Request in progress. Sleeping 30 seconds. Will wait a total of ${ + data.timeRemaining.seconds + } more seconds before timing out. Current Status='${convertCamelCaseStringToSentence( + data.packageVersionCreateRequestResult.Status + )}'` + ); + }); + + // eslint-disable-next-line @typescript-eslint/require-await + Lifecycle.getInstance().on(Package2VersionStatus.success, async () => { + this.ux.log('SUCCESS'); + }); + + const pkg = new Package({ connection: this.hubOrg.getConnection() }); + const result = await pkg.convert( + this.flags.package, + { + wait: this.flags.wait as Duration, + installationKey: this.flags.installationkey as string, + installationKeyBypass: this.flags.installationkeybypass as boolean, + buildInstance: this.flags.buildinstance as string, + }, + SfProject.getInstance() + ); + + switch (result.Status) { + case 'Error': + throw result.Error.length > 0 ? result.Error.join('\n') : pvcMessages.getMessage('unknownError'); + case 'Success': + this.ux.log( + pvcMessages.getMessage(result.Status, [ + result.Id, + result.SubscriberPackageVersionId, + INSTALL_URL_BASE.toString(), + result.SubscriberPackageVersionId, + ]) + ); + break; + default: + this.ux.log(pvcMessages.getMessage('InProgress', [convertCamelCaseStringToSentence(result.Status), result.Id])); + } + + return result; } }