Skip to content

Commit a873216

Browse files
committed
Add command support for Dev Proxy Beta. Closes #212
Closes #212
1 parent 06a594e commit a873216

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
> **Note**: odd version numbers, for example, `0.13.0`, are not included in this changelog. They are used to test the new features and fixes before the final release.
99
10-
## [0.23.0] - Unreleased
10+
## [0.23.1] - Unreleased
11+
12+
### Added:
13+
14+
- Support for using Dev Proxy Beta with commands
1115

1216
### Changed:
1317

src/commands.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as vscode from 'vscode';
22
import { pluginDocs } from './constants';
3-
import { VersionExeName, VersionPreference } from './enums';
3+
import { VersionPreference } from './enums';
44
import { executeCommand, isConfigFile } from './helpers';
5-
import { isDevProxyRunning } from './detect';
5+
import { isDevProxyRunning, getDevProxyExe } from './detect';
66

77
export const registerCommands = (context: vscode.ExtensionContext, configuration: vscode.WorkspaceConfiguration) => {
88
context.subscriptions.push(
@@ -86,6 +86,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
8686
vscode.commands.registerCommand('dev-proxy-toolkit.start', async () => {
8787
const showTerminal = configuration.get('showTerminal') as boolean;
8888
const newTerminal = configuration.get('newTerminal') as boolean;
89+
const devProxyExe = getDevProxyExe(configuration.get('version') as VersionPreference);
8990

9091
let terminal: vscode.Terminal;
9192

@@ -98,15 +99,14 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
9899
}
99100

100101
vscode.window.activeTextEditor && isConfigFile(vscode.window.activeTextEditor.document)
101-
? terminal.sendText(`devproxy --config-file "${vscode.window.activeTextEditor.document.uri.fsPath}"`)
102-
: terminal.sendText('devproxy');
102+
? terminal.sendText(`${devProxyExe} --config-file "${vscode.window.activeTextEditor.document.uri.fsPath}"`)
103+
: terminal.sendText(devProxyExe);
103104
}));
104105

105106
context.subscriptions.push(
106107
vscode.commands.registerCommand('dev-proxy-toolkit.stop', async () => {
107108
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;
109+
const devProxyExe = getDevProxyExe(configuration.get('version') as VersionPreference);
110110

111111
await fetch(`http://localhost:${apiPort}/proxy/stopproxy`, {
112112
method: 'POST',
@@ -119,7 +119,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
119119
if (closeTerminal) {
120120
const checkProxyStatus = async () => {
121121
try {
122-
return await isDevProxyRunning(exeName);
122+
return await isDevProxyRunning(devProxyExe);
123123
} catch {
124124
return false;
125125
}
@@ -148,8 +148,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
148148
context.subscriptions.push(
149149
vscode.commands.registerCommand('dev-proxy-toolkit.restart', async () => {
150150
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;
151+
const devProxyExe = getDevProxyExe(configuration.get('version') as VersionPreference);
153152

154153
try {
155154
await fetch(`http://localhost:${apiPort}/proxy/stopproxy`, {
@@ -161,7 +160,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
161160

162161
const checkProxyStatus = async () => {
163162
try {
164-
return await isDevProxyRunning(exeName);
163+
return await isDevProxyRunning(devProxyExe);
165164
} catch {
166165
return false;
167166
}
@@ -192,8 +191,8 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
192191
}
193192

194193
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);
197196
} catch {
198197
vscode.window.showErrorMessage('Failed to restart Dev Proxy');
199198
}
@@ -247,16 +246,13 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
247246

248247
context.subscriptions.push(
249248
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+
const devProxyExe = getDevProxyExe(configuration.get('version') as VersionPreference);
250+
await executeCommand(`${devProxyExe} config open`);
254251
}));
255252

256253
context.subscriptions.push(
257254
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;
255+
const devProxyExe = getDevProxyExe(configuration.get('version') as VersionPreference);
260256

261257
// ask the user for the filename that they want to use
262258
const fileName = await vscode.window.showInputBox({
@@ -300,7 +296,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
300296
location: vscode.ProgressLocation.Notification,
301297
title: 'Creating new config file...'
302298
}, async () => {
303-
await executeCommand(`${exeName} config new ${fileName}`, { cwd: vscode.workspace.workspaceFolders?.[0].uri.fsPath });
299+
await executeCommand(`${devProxyExe} config new ${fileName}`, { cwd: vscode.workspace.workspaceFolders?.[0].uri.fsPath });
304300
});
305301

306302
const configUri = vscode.Uri.file(`${vscode.workspace.workspaceFolders?.[0].uri.fsPath}/${fileName}`);

0 commit comments

Comments
 (0)