file copyright author Vivek M. Chawla <@VivekMChawla>
 *  summary description version license import { AnyJson } from '@salesforce/ts-types' ; import { SfdxFalconCommand } from '../sfdx-falcon-command' ; import { SfdxFalconCommandType } from '../sfdx-falcon-command' ; import { SfdxFalconError } from '../sfdx-falcon-error' ; import { SfdxFalconResult } from '../sfdx-falcon-result' ; import { SfdxFalconResultType } from '../sfdx-falcon-result' ; import { GeneratorStatus } from '../sfdx-falcon-util/yeoman' ; const yeoman = require ( 'yeoman-environment' ) ; const dbgNs = 'COMMAND:sfdx-falcon-yeoman-command:' ; interface description export interface GeneratorOptions { commandName ? : string ; commandResult ? : SfdxFalconResult ; generatorType ? : string ; generatorStatus ? : GeneratorStatus ; generatorResult ? : SfdxFalconResult ; [ key ] : AnyJson | GeneratorStatus | SfdxFalconResult | string | number ; } class extends SfdxFalconCommand summary description public abstract export abstract class SfdxFalconYeomanCommand extends SfdxFalconCommand { function param { unknown } rejectedPromise param { boolean } showErrorDebug param { boolean } promptUser returns { Promise < void > } description protected async protected async onError ( rejectedPromise , showErrorDebug = true , promptUser = true ) { return super . onError ( rejectedPromise , showErrorDebug , promptUser ) ; } function param { unknown } resolvedPromise returns { Promise < void > } description protected asnyc protected async onSuccess ( resolvedPromise ) { return super . onSuccess ( resolvedPromise ) ; } function param { GeneratorOptions } generatorOptions returns { Promise < SfdxFalconResult > } description protected async protected async runYeomanGenerator ( generatorOptions ) { if ( ! generatorOptions . generatorType ) { throw new SfdxFalconError ( `A valid generator type must be provided to runYeomanGenerator(). You provided '${ generatorOptions . generatorType }'.` , `InvalidGeneratorType` , `${ dbgNs }runYeomanGenerator` ) ; } const generatorResult = new SfdxFalconResult ( generatorOptions . generatorType , SfdxFalconResultType . GENERATOR , { startNow : true , bubbleError : true , bubbleFailure : false } ) ; const resolvedGeneratorOptions = { commandName : this . falconCommandName , generatorResult : generatorResult , options : [ ] , ... generatorOptions } as GeneratorOptions ; const generatorType = resolvedGeneratorOptions . generatorType ; const yeomanEnv = yeoman . createEnv ( ) ; yeomanEnv . register ( require . resolve ( `../../generators/${ generatorType }` ) , `sfdx-falcon:${ generatorType }` ) ; return new Promise ( ( resolve , reject ) => { yeomanEnv . run ( `sfdx-falcon:${ generatorType }` , resolvedGeneratorOptions , generatorError => { if ( generatorError ) { generatorResult . error ( generatorError ) ; reject ( generatorResult ) ; } else { generatorResult . success ( ) ; resolve ( generatorResult ) ; } } ) ; } ) as Promise < SfdxFalconResult > ; } function param { string } commandName param { SfdxFalconCommandType } commandType returns { void } description protected protected sfdxFalconCommandInit ( commandName = 'UNSPECIFIED_FALCON_YEOMAN_COMMAND' , commandType ) { super . sfdxFalconCommandInit ( commandName , commandType ) ; } }