import * as semver from 'semver' ; import { IActionContext } from 'vscode-azureextensionui' ; import { ext , TemplateSource } from '../extensionVariables' ; import { FuncVersion , getMajorVersion } from '../FuncVersion' ; import { localize } from '../localize' ; import { feedUtils } from './feedUtils' ; export namespace cliFeedUtils { const funcCliFeedV4Url = 'https://aka.ms/AAbbk68' ; interface ICliFeed { tags : { [ tag ] : ITag | undefined ; } ; releases : { [ version ] : IRelease ; } ; } export interface IRelease { templates : string ; workerRuntimes : { dotnet : { [ key ] : IWorkerRuntime ; } ; } ; } interface ITag { release : string ; } export interface IWorkerRuntime { displayInfo : { displayName : string ; description ? : string ; hidden : boolean ; } ; sdk : { name : string ; } ; targetFramework : string ; itemTemplates : string ; projectTemplates : string ; projectTemplateId : { csharp : string ; } ; } export async function getLatestVersion ( context , version ) { const cliFeed = await getCliFeed ( context ) ; const majorVersion = getMajorVersion ( version ) ; let tag = 'v' + majorVersion ; const templateProvider = ext . templateProvider . get ( context ) ; if ( templateProvider . templateSource === TemplateSource . Staging ) { const newTag = tag + '-prerelease' ; if ( cliFeed . tags [ newTag ] ) { tag = newTag ; } else { ext . outputChannel . appendLog ( localize ( 'versionWithoutStaging' , 'WARNING: Azure Functions v{0} does not support the staging template source. Using default template source instead.' , majorVersion ) ) ; } } const releaseData = cliFeed . tags [ tag ] ; if ( ! releaseData ) { throw new Error ( localize ( 'unsupportedVersion' , 'Azure Functions v{0} does not support this operation.' , majorVersion ) ) ; } return releaseData . release ; } export async function getSortedVersions ( context , version ) { const cliFeed = await getCliFeed ( context ) ; const majorVersion = parseInt ( getMajorVersion ( version ) ) ; const versions = Object . keys ( cliFeed . releases ) . filter ( v => semver . valid ( v ) && semver . major ( v ) === majorVersion ) ; return semver . rsort ( versions ) . map ( v => typeof v === 'string' ? v : v . version ) ; } export async function getRelease ( context , templateVersion ) { const cliFeed = await getCliFeed ( context ) ; return cliFeed . releases [ templateVersion ] ; } async function getCliFeed ( context ) { return feedUtils . getJsonFeed ( context , funcCliFeedV4Url ) ; } }