import { HeftConfiguration , HeftSession , IHeftPlugin , IHeftFlagParameter , IHeftStringParameter , IHeftIntegerParameter , IHeftStringListParameter , IHeftChoiceParameter , IHeftChoiceListParameter , IBuildStageContext , ICompileSubstage } from '@rushstack/heft' ; import { FileSystem } from '@rushstack/node-core-library' ; class HeftParameterPlugin implements IHeftPlugin { public readonly pluginName : string = 'heft-action-plugin' ; public apply ( heftSession , heftConfiguration ) { const customParameter = heftSession . commandLine . registerFlagParameter ( { associatedActionNames : [ 'build' , 'test' , 'start' ] , parameterLongName : '--custom-parameter' , description : 'Test running a custom parameter' } ) ; const customStringParameter = heftSession . commandLine . registerStringParameter ( { associatedActionNames : [ 'build' , 'test' , 'start' ] , parameterLongName : '--custom-string-parameter' , description : 'Test running a custom string parameter' , argumentName : 'TEXT' , required : true } ) ; const customNumberParameter = heftSession . commandLine . registerIntegerParameter ( { associatedActionNames : [ 'build' , 'test' , 'start' ] , parameterLongName : '--custom-number-parameter' , description : 'Test running a custom number parameter' , argumentName : 'NUMBER' } ) ; const customStringListParameter = heftSession . commandLine . registerStringListParameter ( { associatedActionNames : [ 'build' , 'test' , 'start' ] , parameterShortName : '-x' , parameterLongName : '--custom-string-list-parameter' , description : 'Test running a custom string list parameter' , argumentName : 'LIST_ITEM' } ) ; const customChoiceParameter = heftSession . commandLine . registerChoiceParameter ( { associatedActionNames : [ 'build' , 'test' , 'start' ] , parameterLongName : '--custom-choice-parameter' , alternatives : [ 'red' , 'blue' ] , description : 'Test running a custom choice parameter' } ) ; const customChoiceListParameter = heftSession . commandLine . registerChoiceListParameter ( { associatedActionNames : [ 'build' , 'test' , 'start' ] , parameterShortName : '-y' , parameterLongName : '--custom-choice-list-parameter' , alternatives : [ 'totodile' , 'jynx' , 'gudetama' , 'impidimp' , 'wobbuffet' ] , description : 'Test running a custom choice list parameter' } ) ; const { buildFolder } = heftConfiguration ; heftSession . hooks . build . tap ( this . pluginName , ( build ) => { build . hooks . compile . tap ( this . pluginName , ( compile ) => { compile . hooks . run . tapPromise ( this . pluginName , async ( ) => { if ( customParameter . actionAssociated && customParameter . value ) { const customContent = `customIntegerParameter: ${ customNumberParameter . value }\n` + `customStringParameter: ${ customStringParameter . value }\n` + `customStringListParameter: ${ customStringListParameter . value ?. join ( ', ' ) }\n` + `customChoiceParameter: ${ customChoiceParameter . value }\n` + `customChoiceListParameter: ${ customChoiceListParameter . value ?. join ( ', ' ) }` ; await FileSystem . writeFileAsync ( `${ buildFolder }/lib/custom_output.txt` , customContent , { ensureFolderExists : true } ) ; } } ) ; } ) ; } ) ; } } export default new HeftParameterPlugin ( ) ;