file copyright author Vivek M. Chawla <@VivekMChawla>
 *  summary description version license import * as path from 'path' ; 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:import-data-tree:' ; interface extends SfdxCliActionResultDetail description class extends AppxEngineAction description public export class ImportDataTreeAction extends AppxEngineAction { method returns { void } description protected protected initializeAction ( ) { this . actionType = SfdxFalconActionType . SFDX_CLI ; this . actionName = 'import-data-tree' ; this . description = 'Import Data Tree' ; this . successDelay = 2 ; this . errorDelay = 2 ; this . progressDelay = 1000 ; } method param { ActionOptions } actionOptions returns { void } description protected protected validateActionOptions ( actionOptions ) { if ( typeof actionOptions . plan === 'undefined' ) throw new Error ( `ERROR_MISSING_OPTION: 'plan'` ) ; } method param { ActionOptions } actionOptions returns { Promise < SfdxFalconResult > } description protected async protected async executeAction ( actionContext , actionOptions = { } ) { const actionResult = this . createActionResult ( actionContext , actionOptions , { startNow : true , bubbleError : true , bubbleFailure : true , failureIsError : true } 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 : `Importing data based on ${ actionOptions . plan }` , errorMsg : `Data tree import failed for plan ${ actionOptions . plan }` , successMsg : `Data tree import succeeded for plan '${ actionOptions . plan }'` } as ExecutorMessages ; actionResultDetail . executorMessages = executorMessages ; actionResult . debugResult ( `Executor Messages Set` , `${ dbgNs }executeAction:` ) ; const sfdxCommandDef = { command : 'force:data:tree:import' , progressMsg : executorMessages . progressMsg , errorMsg : executorMessages . errorMsg , successMsg : executorMessages . successMsg , observer : actionContext . listrExecOptions . observer , commandArgs : new Array < string > ( ) , commandFlags : { FLAG_TARGETUSERNAME : actionContext . targetOrg . alias , FLAG_PLAN : path . join ( actionContext . projectContext . dataPath , actionOptions . plan as string ) , FLAG_CONTENTTYPE : 'json' , 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` ) ; } ) ; } }