import * as path from 'path' ; import { IActionContext } from 'vscode-azureextensionui' ; import { ext } from '../../../extensionVariables' ; import { FuncVersion } from '../../../FuncVersion' ; import { executeDotnetTemplateCommand , validateDotnetInstalled } from '../../../templates/dotnet/executeDotnetTemplateCommand' ; import { IFunctionTemplate } from '../../../templates/IFunctionTemplate' ; import { cpUtils } from '../../../utils/cpUtils' ; import { nonNullProp } from '../../../utils/nonNull' ; import { FunctionCreateStepBase } from '../FunctionCreateStepBase' ; import { getBindingSetting } from '../IFunctionWizardContext' ; import { getFileExtension , IDotnetFunctionWizardContext } from './IDotnetFunctionWizardContext' ; export class DotnetFunctionCreateStep extends FunctionCreateStepBase < IDotnetFunctionWizardContext > { private constructor ( ) { super ( ) ; } public static async createStep ( context ) { await validateDotnetInstalled ( context ) ; return new DotnetFunctionCreateStep ( ) ; } public async executeCore ( context ) { const template = nonNullProp ( context , 'functionTemplate' ) ; const functionName = nonNullProp ( context , 'functionName' ) ; const args = [ ] ; args . push ( '--arg:name' ) ; args . push ( cpUtils . wrapArgInQuotes ( functionName ) ) ; args . push ( '--arg:namespace' ) ; args . push ( cpUtils . wrapArgInQuotes ( nonNullProp ( context , 'namespace' ) ) ) ; for ( const setting of template . userPromptedSettings ) { const value = getBindingSetting ( context , setting ) ; if ( value !== undefined ) { args . push ( `--arg:${ setting . name }` ) ; args . push ( cpUtils . wrapArgInQuotes ( value ) ) ; } } const version = nonNullProp ( context , 'version' ) ; let projectTemplateKey = context . projectTemplateKey ; if ( ! projectTemplateKey ) { const templateProvider = ext . templateProvider . get ( context ) ; projectTemplateKey = await templateProvider . getProjectTemplateKey ( context , context . projectPath , nonNullProp ( context , 'language' ) , context . version , undefined ) ; } await executeDotnetTemplateCommand ( context , version , projectTemplateKey , context . projectPath , 'create' , '--identity' , template . id , ... args ) ; return path . join ( context . projectPath , functionName + getFileExtension ( context ) ) ; } }