1
1
import * as vscode from 'vscode' ;
2
2
import { pluginDocs } from './constants' ;
3
- import { VersionExeName , VersionPreference } from './enums' ;
3
+ import { VersionPreference } from './enums' ;
4
4
import { executeCommand , isConfigFile } from './helpers' ;
5
- import { isDevProxyRunning } from './detect' ;
5
+ import { isDevProxyRunning , getDevProxyExe } from './detect' ;
6
6
7
7
export const registerCommands = ( context : vscode . ExtensionContext , configuration : vscode . WorkspaceConfiguration ) => {
8
+ const versionPreference = configuration . get ( 'version' ) as VersionPreference ;
9
+ const devProxyExe = getDevProxyExe ( configuration . get ( 'version' ) as VersionPreference ) ;
10
+
8
11
context . subscriptions . push (
9
12
vscode . commands . registerCommand ( 'dev-proxy-toolkit.install' , async ( platform : NodeJS . Platform ) => {
10
- const versionPreference = configuration . get ( 'version' ) as VersionPreference ;
11
13
const message = vscode . window . setStatusBarMessage ( 'Installing Dev Proxy...' ) ;
12
14
13
15
// we are on windows so we can use winget
@@ -87,6 +89,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
87
89
const showTerminal = configuration . get ( 'showTerminal' ) as boolean ;
88
90
const newTerminal = configuration . get ( 'newTerminal' ) as boolean ;
89
91
92
+
90
93
let terminal : vscode . Terminal ;
91
94
92
95
if ( ! newTerminal && vscode . window . activeTerminal ) {
@@ -98,15 +101,13 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
98
101
}
99
102
100
103
vscode . window . activeTextEditor && isConfigFile ( vscode . window . activeTextEditor . document )
101
- ? terminal . sendText ( `devproxy --config-file "${ vscode . window . activeTextEditor . document . uri . fsPath } "` )
102
- : terminal . sendText ( 'devproxy' ) ;
104
+ ? terminal . sendText ( `${ devProxyExe } --config-file "${ vscode . window . activeTextEditor . document . uri . fsPath } "` )
105
+ : terminal . sendText ( devProxyExe ) ;
103
106
} ) ) ;
104
107
105
108
context . subscriptions . push (
106
109
vscode . commands . registerCommand ( 'dev-proxy-toolkit.stop' , async ( ) => {
107
110
const apiPort = configuration . get ( 'apiPort' ) as number ;
108
- const versionPreference = configuration . get ( 'version' ) as VersionPreference ;
109
- const exeName = versionPreference === VersionPreference . Stable ? VersionExeName . Stable : VersionExeName . Beta ;
110
111
111
112
await fetch ( `http://localhost:${ apiPort } /proxy/stopproxy` , {
112
113
method : 'POST' ,
@@ -119,7 +120,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
119
120
if ( closeTerminal ) {
120
121
const checkProxyStatus = async ( ) => {
121
122
try {
122
- return await isDevProxyRunning ( exeName ) ;
123
+ return await isDevProxyRunning ( devProxyExe ) ;
123
124
} catch {
124
125
return false ;
125
126
}
@@ -148,8 +149,6 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
148
149
context . subscriptions . push (
149
150
vscode . commands . registerCommand ( 'dev-proxy-toolkit.restart' , async ( ) => {
150
151
const apiPort = configuration . get ( 'apiPort' ) as number ;
151
- const versionPreference = configuration . get ( 'version' ) as VersionPreference ;
152
- const exeName = versionPreference === VersionPreference . Stable ? VersionExeName . Stable : VersionExeName . Beta ;
153
152
154
153
try {
155
154
await fetch ( `http://localhost:${ apiPort } /proxy/stopproxy` , {
@@ -161,7 +160,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
161
160
162
161
const checkProxyStatus = async ( ) => {
163
162
try {
164
- return await isDevProxyRunning ( exeName ) ;
163
+ return await isDevProxyRunning ( devProxyExe ) ;
165
164
} catch {
166
165
return false ;
167
166
}
@@ -192,8 +191,8 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
192
191
}
193
192
194
193
vscode . window . activeTextEditor && isConfigFile ( vscode . window . activeTextEditor . document )
195
- ? terminal . sendText ( `devproxy --config-file "${ vscode . window . activeTextEditor . document . uri . fsPath } "` )
196
- : terminal . sendText ( 'devproxy' ) ;
194
+ ? terminal . sendText ( `${ devProxyExe } --config-file "${ vscode . window . activeTextEditor . document . uri . fsPath } "` )
195
+ : terminal . sendText ( devProxyExe ) ;
197
196
} catch {
198
197
vscode . window . showErrorMessage ( 'Failed to restart Dev Proxy' ) ;
199
198
}
@@ -247,23 +246,17 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
247
246
248
247
context . subscriptions . push (
249
248
vscode . commands . registerCommand ( 'dev-proxy-toolkit.config-open' , async ( ) => {
250
- const versionPreference = configuration . get ( 'version' ) as VersionPreference ;
251
- versionPreference === VersionPreference . Stable
252
- ? await executeCommand ( `${ VersionExeName . Stable } config open` )
253
- : await executeCommand ( `${ VersionExeName . Beta } config open` ) ;
249
+ await executeCommand ( `${ devProxyExe } config open` ) ;
254
250
} ) ) ;
255
251
256
252
context . subscriptions . push (
257
253
vscode . commands . registerCommand ( 'dev-proxy-toolkit.config-new' , async ( ) => {
258
- const versionPreference = configuration . get ( 'version' ) as VersionPreference ;
259
- const exeName = versionPreference === VersionPreference . Stable ? VersionExeName . Stable : VersionExeName . Beta ;
260
-
261
254
// ask the user for the filename that they want to use
262
255
const fileName = await vscode . window . showInputBox ( {
263
256
prompt : 'Enter the name of the new config file' ,
257
+ placeHolder : 'devproxyrc.json' ,
264
258
value : 'devproxyrc.json' ,
265
259
validateInput : ( value : string ) => {
266
- console . log ( value ) ;
267
260
const errors : string [ ] = [ ] ;
268
261
269
262
if ( ! value ) {
@@ -286,7 +279,6 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
286
279
// we do this after the user has entered the filename
287
280
try {
288
281
const workspaceFolder = vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath ;
289
- console . log ( workspaceFolder ) ;
290
282
const { type } = await vscode . workspace . fs . stat ( vscode . Uri . file ( `${ workspaceFolder } /${ fileName } ` ) ) ;
291
283
if ( type === vscode . FileType . File ) {
292
284
vscode . window . showErrorMessage ( 'A file with that name already exists' ) ;
@@ -300,7 +292,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
300
292
location : vscode . ProgressLocation . Notification ,
301
293
title : 'Creating new config file...'
302
294
} , async ( ) => {
303
- await executeCommand ( `${ exeName } config new ${ fileName } ` , { cwd : vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath } ) ;
295
+ await executeCommand ( `${ devProxyExe } config new ${ fileName } ` , { cwd : vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath } ) ;
304
296
} ) ;
305
297
306
298
const configUri = vscode . Uri . file ( `${ vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath } /${ fileName } ` ) ;
0 commit comments