import { funcPackageName } from '../constants' ; import { FuncVersion , getMajorVersion } from '../FuncVersion' ; import { cpUtils } from '../utils/cpUtils' ; export function getBrewPackageName ( version ) { return `${ funcPackageName }@${ getMajorVersion ( version ) }` ; } export async function tryGetInstalledBrewPackageName ( version ) { const brewPackageName = getBrewPackageName ( version ) ; if ( await isBrewPackageInstalled ( brewPackageName ) ) { return brewPackageName ; } else { let oldPackageName ; if ( version === FuncVersion . v2 ) { oldPackageName = funcPackageName ; } else if ( version === FuncVersion . v3 ) { oldPackageName = funcPackageName + '-v3-preview' ; } if ( oldPackageName && await isBrewPackageInstalled ( oldPackageName ) ) { return oldPackageName ; } else { return undefined ; } } } async function isBrewPackageInstalled ( packageName ) { try { await cpUtils . executeCommand ( undefined , undefined , 'brew' , 'ls' , packageName ) ; return true ; } catch ( error ) { return false ; } }