import { IActionContext , IAzureQuickPickItem , IAzureQuickPickOptions } from 'vscode-azureextensionui' ; import { localize } from './localize' ; import { openUrl } from './utils/openUrl' ; export enum FuncVersion { v1 = '~1' , v2 = '~2' , v3 = '~3' , v4 = '~4' } export const latestGAVersion = FuncVersion . v4 ; export async function promptForFuncVersion ( context , message ? ) { const recommended = localize ( 'recommended' , '(Recommended)' ) ; let picks = [ { label : 'Azure Functions v4' , description : recommended , data : FuncVersion . v4 } , { label : 'Azure Functions v3' , data : FuncVersion . v3 } , { label : 'Azure Functions v2' , data : FuncVersion . v2 } , { label : 'Azure Functions v1' , data : FuncVersion . v1 } ] ; picks = picks . filter ( p => osSupportsVersion ( p . data ) ) ; picks . push ( { label : localize ( 'learnMore' , '$(link-external) Learn more...' ) , description : '' , data : undefined } ) ; const options = { placeHolder : message || localize ( 'selectVersion' , 'Select a version' ) , stepName : 'funcVersion' , suppressPersistence : true } ; while ( true ) { const version = ( await context . ui . showQuickPick ( picks , options ) ) . data ; if ( version === undefined ) { await openUrl ( 'https://aka.ms/AA1tpij' ) ; } else { return version ; } } } export function tryParseFuncVersion ( data ) { if ( data ) { const majorVersion = tryGetMajorVersion ( data ) ; if ( majorVersion ) { return Object . values ( FuncVersion ) . find ( v => v === '~' + majorVersion ) ; } } return undefined ; } function osSupportsVersion ( version ) { return version !== FuncVersion . v1 || process . platform === 'win32' ; } export function getMajorVersion ( data ) { const majorVersion = tryGetMajorVersion ( data ) ; if ( ! majorVersion ) { throw new Error ( localize ( 'invalidVersion' , 'Invalid version "{0}".' , data ) ) ; } return majorVersion ; } function tryGetMajorVersion ( data ) { const match = data . match ( /^[~v]?([0-9]+)/i ) ; return match ? match [ 1 ] : undefined ; }