file copyright author Vivek M. Chawla <@VivekMChawla>
 *  summary description version license import { flags } from '@salesforce/command' ; import { SfdxError } from '@salesforce/core' ; import { Messages } from '@salesforce/core' ; import { AnyJson } from '@salesforce/ts-types' ; import { isEmpty } from 'lodash' ; import * as path from 'path' ; import { SfdxFalconCommand } from '../../../modules/sfdx-falcon-command' ; import { SfdxFalconError } from '../../../modules/sfdx-falcon-error' ; import { SfdxFalconProject } from '../../../modules/sfdx-falcon-project' ; import { SfdxFalconResult } from '../../../modules/sfdx-falcon-result' ; import { SfdxFalconResultType } from '../../../modules/sfdx-falcon-result' ; import { SfdxFalconCommandType } from '../../../modules/sfdx-falcon-command' ; import { CoreActionResultDetail } from '../../../modules/sfdx-falcon-recipe/engines/appx/actions' ; Messages . importMessagesDirectory ( __dirname ) ; const baseMessages = Messages . loadMessages ( 'sfdx-falcon' , 'sfdxFalconCommand' ) ; const commandMessages = Messages . loadMessages ( 'sfdx-falcon' , 'falconAdkInstall' ) ; class extends SfdxFalconCommand summary description version public export default class FalconDemoInstall extends SfdxFalconCommand { public static description = commandMessages . getMessage ( 'commandDescription' ) ; public static hidden = false ; public static examples = [ `$ sfdx falcon:adk:install` , `$ sfdx falcon:adk:install --projectdir ~/demos/adk-projects/my-adk-project` , `$ sfdx falcon:adk:install --projectdir ~/demos/adk-projects/my-adk-project \\\n` + `                         --configfile my-alternate-demo-config.json` ] ; protected static flagsConfig = { projectdir : flags . directory ( { char : 'd' , required : false , description : baseMessages . getMessage ( 'projectdir_FlagDescription' ) , default : '.' , hidden : false } ) , recipefile : flags . string ( { char : 'f' , required : false , description : baseMessages . getMessage ( 'recipefile_FlagDescription' ) , default : '' , hidden : false } ) , extendedoptions : flags . string ( { char : 'x' , required : false , description : baseMessages . getMessage ( 'extendedoptions_FlagDescription' ) , default : '{}' , hidden : false } ) , ... SfdxFalconCommand . falconBaseflagsConfig } ; protected static requiresProject = false ; protected static requiresUsername = false ; protected static requiresDevhubUsername = false ; protected static supportsUsername = false ; protected static supportsDevhubUsername = false ; function returns { Promise < AnyJson > } description version public async public async run ( ) { this . sfdxFalconCommandInit ( 'falcon:adk:install' , SfdxFalconCommandType . APPX_DEMO ) ; const projectPath = path . resolve ( this . projectDirectory ) ; const sfdxFalconProject = await SfdxFalconProject . resolve ( projectPath ) ; const compileOptions = this . extendedOptions ; if ( this . recipeFile ) { await sfdxFalconProject . runSpecifiedRecipe ( this . recipeFile ) . then ( async ( falconRecipeResult ) => { await this . onSuccess ( falconRecipeResult ) ; } ) . catch ( async ( falconRecipeResult ) => { await this . onError ( falconRecipeResult ) ; } ) ; } else { await sfdxFalconProject . runDefaultRecipe ( compileOptions ) . then ( async ( falconRecipeResult ) => { await this . onSuccess ( falconRecipeResult ) ; } ) . catch ( async ( falconRecipeResult ) => { await this . onError ( falconRecipeResult ) ; } ) ; } return this . falconJsonResponse as unknown as AnyJson ; } method param { SfdxFalconError } cmdError returns { SfdxError } description protected protected buildFinalError ( cmdError ) { let actionError = cmdError ; while ( actionError && ( isEmpty ( actionError ) === false ) ) { if ( actionError . data && actionError . data . sfdxFalconResult ) { if ( actionError . data . sfdxFalconResult . type === SfdxFalconResultType . ACTION ) { const actionResult = actionError . data . sfdxFalconResult as SfdxFalconResult ; const actionDetail = actionResult . detail as CoreActionResultDetail ; let errorMessage = '' ; try { const stepName = actionDetail . actionContext . listrExecOptions . listrTask . _task . title ; errorMessage = `The step "${ stepName }" has failed. Its action, "${ actionDetail . actionName }", returned the following error:` ; } catch ( err ) { errorMessage = `A step with the action "${ actionDetail . actionName }" has failed with the following error:` ; } const finalError = new SfdxError ( `${ errorMessage }\n` + `${ actionError . rootCause . name }: ${ actionError . rootCause . message }` , `FailedCommand` , actionError . rootCause . actions , 1 , cmdError ) ; finalError . commandName = `falcon:adk:install` ; return finalError ; } } actionError = actionError . cause as SfdxFalconError ; } return cmdError ; } }