file copyright author Vivek M. Chawla <@VivekMChawla>
 *  summary description version license import { SfdxFalconResult } from '../../../../sfdx-falcon-result' ; import { SfdxFalconResultOptions } from '../../../../sfdx-falcon-result' ; import { SfdxFalconResultType } from '../../../../sfdx-falcon-result' ; import { executeSfdxCommand } from '../../../executors/sfdx' ; import { SfdxCommandDefinition } from '../../../executors/sfdx' ; import { AppxEngineActionContext } from '../../appx' ; import { AppxEngineAction } from '../../appx/actions' ; import { SfdxCliActionResultDetail } from '../../appx/actions' ; import { ActionOptions } from '../../../types/' ; import { ExecutorMessages } from '../../../types/' ; import { SfdxFalconActionType } from '../../../types/' ; const dbgNs = 'ACTION:delete-scratch-org:' ; interface extends SfdxCliActionResultDetail description class extends AppxEngineAction description public export class DeleteScratchOrgAction extends AppxEngineAction { method returns { void } description protected protected initializeAction ( ) { this . actionType = SfdxFalconActionType . SFDX_CLI ; this . actionName = 'delete-scratch-org' ; this . description = 'Delete Scratch Org' ; this . successDelay = 2 ; this . errorDelay = 2 ; this . progressDelay = 1000 ; } method param { ActionOptions } actionOptions returns { void } description private protected validateActionOptions ( actionOptions ) { if ( typeof actionOptions . scratchOrgAlias === 'undefined' ) throw new Error ( `ERROR_MISSING_OPTION: 'scratchOrgAlias'` ) ; } method param { ActionOptions } actionOptions returns { Promise < SfdxFalconResult > } description version protected async protected async executeAction ( actionContext , actionOptions = { } ) { const actionResult = this . createActionResult ( actionContext , actionOptions , { startNow : true , bubbleError : true , bubbleFailure : false , failureIsError : false } as SfdxFalconResultOptions ) ; actionResult . detail = { ... actionResult . detail , ... { executorMessages : null , sfdxCommandDef : null } } as SfdxCliActionResultDetail ; actionResult . debugResult ( `Initialized` , `${ dbgNs }executeAction:` ) ; const actionResultDetail = actionResult . detail as SfdxCliActionResultDetail ; const executorMessages = { progressMsg : `Marking scratch org '${ actionOptions . scratchOrgAlias }' for deletion` , errorMsg : `Request to mark scratch org '${ actionOptions . scratchOrgAlias }' for deletion failed` , successMsg : `Scratch org '${ actionOptions . scratchOrgAlias }' successfully marked for deletion` } as ExecutorMessages ; actionResultDetail . executorMessages = executorMessages ; actionResult . debugResult ( `Executor Messages Set` , `${ dbgNs }executeAction:` ) ; const sfdxCommandDef = { command : 'force:org:delete' , progressMsg : executorMessages . progressMsg , errorMsg : executorMessages . errorMsg , successMsg : executorMessages . successMsg , observer : actionContext . listrExecOptions . observer , commandArgs : new Array < string > ( ) , commandFlags : { FLAG_TARGETUSERNAME : actionContext . targetOrg . alias , FLAG_TARGETDEVHUBUSERNAME : actionContext . devHubAlias , FLAG_NOPROMPT : true , FLAG_JSON : true , FLAG_LOGLEVEL : actionContext . logLevel } } as SfdxCommandDefinition ; actionResultDetail . sfdxCommandDef = sfdxCommandDef ; actionResult . debugResult ( `SFDX Command Definition Created` , `${ dbgNs }executeAction:` ) ; return await executeSfdxCommand ( sfdxCommandDef ) . catch ( rejectedPromise => actionResult . addRejectedChild ( rejectedPromise , SfdxFalconResultType . EXECUTOR , `sfdx:executeSfdxCommand` ) ) . then ( resolvedPromise => { if ( resolvedPromise === actionResult ) { return actionResult ; } return actionResult . addResolvedChild ( resolvedPromise , SfdxFalconResultType . EXECUTOR , `sfdx:executeSfdxCommand` ) ; } ) ; } }