Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

> **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.

## [0.23.0] - Unreleased
## [0.23.1] - Unreleased

### Added:

- Support for using Dev Proxy Beta with commands

### Changed:

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dev-proxy-toolkit",
"displayName": "Dev Proxy Toolkit",
"description": "Makes it easy to create and update Dev Proxy configuration files.",
"version": "0.23.0",
"version": "0.23.1",
"publisher": "garrytrinder",
"engines": {
"vscode": "^1.89.0"
Expand Down
38 changes: 15 additions & 23 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import * as vscode from 'vscode';
import { pluginDocs } from './constants';
import { VersionExeName, VersionPreference } from './enums';
import { VersionPreference } from './enums';
import { executeCommand, isConfigFile } from './helpers';
import { isDevProxyRunning } from './detect';
import { isDevProxyRunning, getDevProxyExe } from './detect';

export const registerCommands = (context: vscode.ExtensionContext, configuration: vscode.WorkspaceConfiguration) => {
const versionPreference = configuration.get('version') as VersionPreference;
Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The versionPreference variable is declared but never used; consider removing it or passing it directly to getDevProxyExe to avoid redundant configuration lookups.

Suggested change
const versionPreference = configuration.get('version') as VersionPreference;

Copilot uses AI. Check for mistakes.
const devProxyExe = getDevProxyExe(configuration.get('version') as VersionPreference);

context.subscriptions.push(
vscode.commands.registerCommand('dev-proxy-toolkit.install', async (platform: NodeJS.Platform) => {
const versionPreference = configuration.get('version') as VersionPreference;
const message = vscode.window.setStatusBarMessage('Installing Dev Proxy...');

Comment on lines +9 to 14
Copy link

Copilot AI May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider whether configuration changes at runtime should update devProxyExe dynamically. If configuration may change after activation, it might be better to compute devProxyExe inside each command handler.

Copilot uses AI. Check for mistakes.
// we are on windows so we can use winget
Expand Down Expand Up @@ -87,6 +89,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
const showTerminal = configuration.get('showTerminal') as boolean;
const newTerminal = configuration.get('newTerminal') as boolean;


let terminal: vscode.Terminal;

if (!newTerminal && vscode.window.activeTerminal) {
Expand All @@ -98,15 +101,13 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
}

vscode.window.activeTextEditor && isConfigFile(vscode.window.activeTextEditor.document)
? terminal.sendText(`devproxy --config-file "${vscode.window.activeTextEditor.document.uri.fsPath}"`)
: terminal.sendText('devproxy');
? terminal.sendText(`${devProxyExe} --config-file "${vscode.window.activeTextEditor.document.uri.fsPath}"`)
: terminal.sendText(devProxyExe);
}));

context.subscriptions.push(
vscode.commands.registerCommand('dev-proxy-toolkit.stop', async () => {
const apiPort = configuration.get('apiPort') as number;
const versionPreference = configuration.get('version') as VersionPreference;
const exeName = versionPreference === VersionPreference.Stable ? VersionExeName.Stable : VersionExeName.Beta;

await fetch(`http://localhost:${apiPort}/proxy/stopproxy`, {
method: 'POST',
Expand All @@ -119,7 +120,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
if (closeTerminal) {
const checkProxyStatus = async () => {
try {
return await isDevProxyRunning(exeName);
return await isDevProxyRunning(devProxyExe);
} catch {
return false;
}
Expand Down Expand Up @@ -148,8 +149,6 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
context.subscriptions.push(
vscode.commands.registerCommand('dev-proxy-toolkit.restart', async () => {
const apiPort = configuration.get('apiPort') as number;
const versionPreference = configuration.get('version') as VersionPreference;
const exeName = versionPreference === VersionPreference.Stable ? VersionExeName.Stable : VersionExeName.Beta;

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

const checkProxyStatus = async () => {
try {
return await isDevProxyRunning(exeName);
return await isDevProxyRunning(devProxyExe);
} catch {
return false;
}
Expand Down Expand Up @@ -192,8 +191,8 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
}

vscode.window.activeTextEditor && isConfigFile(vscode.window.activeTextEditor.document)
? terminal.sendText(`devproxy --config-file "${vscode.window.activeTextEditor.document.uri.fsPath}"`)
: terminal.sendText('devproxy');
? terminal.sendText(`${devProxyExe} --config-file "${vscode.window.activeTextEditor.document.uri.fsPath}"`)
: terminal.sendText(devProxyExe);
} catch {
vscode.window.showErrorMessage('Failed to restart Dev Proxy');
}
Expand Down Expand Up @@ -247,23 +246,17 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration

context.subscriptions.push(
vscode.commands.registerCommand('dev-proxy-toolkit.config-open', async () => {
const versionPreference = configuration.get('version') as VersionPreference;
versionPreference === VersionPreference.Stable
? await executeCommand(`${VersionExeName.Stable} config open`)
: await executeCommand(`${VersionExeName.Beta} config open`);
await executeCommand(`${devProxyExe} config open`);
}));

context.subscriptions.push(
vscode.commands.registerCommand('dev-proxy-toolkit.config-new', async () => {
const versionPreference = configuration.get('version') as VersionPreference;
const exeName = versionPreference === VersionPreference.Stable ? VersionExeName.Stable : VersionExeName.Beta;

// ask the user for the filename that they want to use
const fileName = await vscode.window.showInputBox({
prompt: 'Enter the name of the new config file',
placeHolder: 'devproxyrc.json',
value: 'devproxyrc.json',
validateInput: (value: string) => {
console.log(value);
const errors: string[] = [];

if (!value) {
Expand All @@ -286,7 +279,6 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
// we do this after the user has entered the filename
try {
const workspaceFolder = vscode.workspace.workspaceFolders?.[0].uri.fsPath;
console.log(workspaceFolder);
const { type } = await vscode.workspace.fs.stat(vscode.Uri.file(`${workspaceFolder}/${fileName}`));
if (type === vscode.FileType.File) {
vscode.window.showErrorMessage('A file with that name already exists');
Expand All @@ -300,7 +292,7 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
location: vscode.ProgressLocation.Notification,
title: 'Creating new config file...'
}, async () => {
await executeCommand(`${exeName} config new ${fileName}`, { cwd: vscode.workspace.workspaceFolders?.[0].uri.fsPath });
await executeCommand(`${devProxyExe} config new ${fileName}`, { cwd: vscode.workspace.workspaceFolders?.[0].uri.fsPath });
});

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