From 8993b8d949b051f7c14275a7ff6be5e90ec56545 Mon Sep 17 00:00:00 2001 From: Garry Trinder Date: Tue, 29 Jul 2025 09:36:21 +0100 Subject: [PATCH] Update dev-proxy-toolkit.config-new command to add file to .devproxy folder. Closes #283 Closes #283 --- CHANGELOG.md | 1 + src/commands.ts | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c773d3..62ecde1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed: - Snippets: All snippets that reference schemas updated to use `v1.0.0` schema +- Commands: `dev-proxy-toolkit.config-new` now creates the configuration file in the `.devproxy` folder and creates the folder if it does not exist ### Fixed: diff --git a/src/commands.ts b/src/commands.ts index 1aeb0db..ebb6603 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -314,7 +314,7 @@ 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; - const { type } = await vscode.workspace.fs.stat(vscode.Uri.file(`${workspaceFolder}/${fileName}`)); + const { type } = await vscode.workspace.fs.stat(vscode.Uri.file(`${workspaceFolder}/.devproxy/${fileName}`)); if (type === vscode.FileType.File) { vscode.window.showErrorMessage('A file with that name already exists'); return; @@ -322,15 +322,26 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration } catch { } // file does not exist, continue try { + // ensure .devproxy folder exists + const workspaceFolder = vscode.workspace.workspaceFolders?.[0].uri.fsPath; + const devProxyFolder = vscode.Uri.file(`${workspaceFolder}/.devproxy`); + + try { + await vscode.workspace.fs.stat(devProxyFolder); + } catch { + // folder doesn't exist, create it + await vscode.workspace.fs.createDirectory(devProxyFolder); + } + // show progress await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, title: 'Creating new config file...' }, async () => { - await executeCommand(`${devProxyExe} config new ${fileName}`, { cwd: vscode.workspace.workspaceFolders?.[0].uri.fsPath }); + await executeCommand(`${devProxyExe} config new ${fileName}`, { cwd: `${workspaceFolder}/.devproxy` }); }); - const configUri = vscode.Uri.file(`${vscode.workspace.workspaceFolders?.[0].uri.fsPath}/${fileName}`); + const configUri = vscode.Uri.file(`${workspaceFolder}/.devproxy/${fileName}`); const document = await vscode.workspace.openTextDocument(configUri); await vscode.window.showTextDocument(document); } catch (error) {