1+ import * as vscode from 'vscode' ;
12import { exec } from 'child_process' ;
23import { DevProxyInstall } from './types' ;
34import os from 'os' ;
5+ import { VersionExeName , VersionPreference } from './enums' ;
46
5- export const getVersion = async ( ) => {
7+ export const getVersion = async ( devProxyExe : string ) => {
68 try {
7- const version = await executeCommand ( `devproxy --version` ) ;
9+ const version = await executeCommand ( `${ devProxyExe } --version` ) ;
810 return version . trim ( ) ;
911 } catch ( error ) {
1012 return "" ;
@@ -25,14 +27,15 @@ export const executeCommand = async (cmd: string): Promise<string> => {
2527 } ) ;
2628} ;
2729
28- export const detectDevProxyInstall = async ( ) : Promise < DevProxyInstall > => {
29- const version = await getVersion ( ) ;
30+ export const detectDevProxyInstall = async ( versionPreference : VersionPreference ) : Promise < DevProxyInstall > => {
31+ const devProxyExe = getDevProxyExe ( versionPreference ) ;
32+ const version = await getVersion ( devProxyExe ) ;
3033 const isInstalled = version !== '' ;
3134 const isBeta = version . includes ( 'beta' ) ;
3235 const platform = os . platform ( ) ;
33- const outdatedVersion = await getOutdatedVersion ( ) ;
36+ const outdatedVersion = await getOutdatedVersion ( devProxyExe ) ;
3437 const isOutdated = isInstalled && outdatedVersion !== '' ;
35- const isRunning = await isDevProxyRunning ( ) ;
38+ const isRunning = await isDevProxyRunning ( devProxyExe ) ;
3639
3740 return {
3841 version,
@@ -45,25 +48,31 @@ export const detectDevProxyInstall = async (): Promise<DevProxyInstall> => {
4548 } ;
4649} ;
4750
48- export const getOutdatedVersion = async ( ) : Promise < string > => {
51+ export const getOutdatedVersion = async ( devProxyExe : string ) : Promise < string > => {
4952 try {
50- const outdated = await executeCommand ( `devproxy outdated --short` ) ;
53+ const outdated = await executeCommand ( `${ devProxyExe } outdated --short` ) ;
5154 return outdated ? outdated . trim ( ) : '' ;
5255 } catch ( error ) {
5356 return "" ;
5457 }
5558} ;
5659
57- export const isDevProxyRunning = async ( ) : Promise < boolean > => {
60+ export const isDevProxyRunning = async ( devProxyExe : string ) : Promise < boolean > => {
5861 const platform = os . platform ( ) ;
5962
6063 if ( platform === 'win32' ) {
61- const processId = await executeCommand ( ' pwsh.exe -c "(Get-Process devproxy -ErrorAction SilentlyContinue).Id"' ) ;
64+ const processId = await executeCommand ( ` pwsh.exe -c "(Get-Process ${ devProxyExe } -ErrorAction SilentlyContinue).Id"` ) ;
6265 return processId . trim ( ) !== '' ;
6366 } ;
6467 if ( platform === 'darwin' ) {
65- const processId = await executeCommand ( ' $SHELL -c "ps -ef | grep devproxy | grep -v grep | awk \'{print $2}\'"' ) ;
68+ const processId = await executeCommand ( ` $SHELL -c "ps -ef | grep ${ devProxyExe } | grep -v grep | awk \'{print $2}\'"` ) ;
6669 return processId . trim ( ) !== '' ;
6770 } ;
6871 return false ;
72+ } ;
73+
74+ export const getDevProxyExe = ( versionPreference : VersionPreference ) => {
75+ return versionPreference === VersionPreference . Stable
76+ ? VersionExeName . Stable
77+ : VersionExeName . Beta ;
6978} ;
0 commit comments