import * as semver from 'semver' ; import { IActionContext } from 'vscode-azureextensionui' ; import { cpUtils } from '../utils/cpUtils' ; import { getFuncCliPath } from './getFuncCliPath' ; export async function getLocalFuncCoreToolsVersion ( context , workspacePath ) { const funcCliPath = await getFuncCliPath ( context , workspacePath ) ; const output = await cpUtils . executeCommand ( undefined , workspacePath , funcCliPath , '--version' ) ; const version = semver . clean ( output ) ; if ( version ) { return version ; } else { const matchResult = output . match ( /(?:.*)Azure Functions Core Tools (.*)/ ) ; if ( matchResult !== null ) { let localVersion = matchResult [ 1 ] . replace ( /[()]/g , '' ) . trim ( ) ; if ( localVersion === '220.0.0-beta.0' ) { localVersion = '2.0.1-beta.25' ; } return semver . valid ( localVersion ) ; } return null ; } } export function addLocalFuncTelemetry ( context , workspacePath ) { context . telemetry . properties . funcCliVersion = 'unknown' ; getLocalFuncCoreToolsVersion ( context , workspacePath ) . then ( ( version ) => { context . telemetry . properties . funcCliVersion = version || 'none' ; } ) . catch ( ( ) => { context . telemetry . properties . funcCliVersion = 'none' ; } ) ; }