import { Progress , Uri , window , workspace } from "vscode" ; import { AzureWizardExecuteStep } from "vscode-azureextensionui" ; import { IFunctionBinding , IFunctionJson } from "../../funcConfig/function" ; import { IBindingTemplate } from "../../templates/IBindingTemplate" ; import { confirmEditJsonFile } from '../../utils/fs' ; import { nonNullProp } from "../../utils/nonNull" ; import { verifyExtensionBundle } from "../../utils/verifyExtensionBundle" ; import { getBindingSetting } from "../createFunction/IFunctionWizardContext" ; import { IBindingWizardContext } from "./IBindingWizardContext" ; export class BindingCreateStep extends AzureWizardExecuteStep < IBindingWizardContext > { public priority : number = 220 ; public async execute ( context , _progress ) { const bindingTemplate = nonNullProp ( context , 'bindingTemplate' ) ; context . telemetry . properties . bindingType = bindingTemplate . type ; context . telemetry . properties . bindingDirection = bindingTemplate . direction ; const binding = { } ; binding . type = bindingTemplate . type ; binding . direction = bindingTemplate . direction ; for ( const b of bindingTemplate . settings ) { binding [ b . name ] = getBindingSetting ( context , b ) ; } await confirmEditJsonFile ( context , context . functionJsonPath , ( functionJson ) => { functionJson . bindings = functionJson . bindings || [ ] ; functionJson . bindings . push ( binding ) ; return functionJson ; } ) ; context . binding = binding ; await verifyExtensionBundle ( context , bindingTemplate ) ; await window . showTextDocument ( await workspace . openTextDocument ( Uri . file ( context . functionJsonPath ) ) ) ; } public shouldExecute ( context ) { return ! ! context . bindingTemplate && ! context . binding ; } }