Skip to content

Commit 7dc03a5

Browse files
authored
Update dev-proxy-toolkit.config-new command to add file to .devproxy folder. Closes #283 (#313)
1 parent e0fc88e commit 7dc03a5

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
### Changed:
1818

1919
- Snippets: All snippets that reference schemas updated to use `v1.0.0` schema
20+
- Commands: `dev-proxy-toolkit.config-new` now creates the configuration file in the `.devproxy` folder and creates the folder if it does not exist
2021

2122
### Fixed:
2223

src/commands.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,23 +314,34 @@ export const registerCommands = (context: vscode.ExtensionContext, configuration
314314
// we do this after the user has entered the filename
315315
try {
316316
const workspaceFolder = vscode.workspace.workspaceFolders?.[0].uri.fsPath;
317-
const { type } = await vscode.workspace.fs.stat(vscode.Uri.file(`${workspaceFolder}/${fileName}`));
317+
const { type } = await vscode.workspace.fs.stat(vscode.Uri.file(`${workspaceFolder}/.devproxy/${fileName}`));
318318
if (type === vscode.FileType.File) {
319319
vscode.window.showErrorMessage('A file with that name already exists');
320320
return;
321321
}
322322
} catch { } // file does not exist, continue
323323

324324
try {
325+
// ensure .devproxy folder exists
326+
const workspaceFolder = vscode.workspace.workspaceFolders?.[0].uri.fsPath;
327+
const devProxyFolder = vscode.Uri.file(`${workspaceFolder}/.devproxy`);
328+
329+
try {
330+
await vscode.workspace.fs.stat(devProxyFolder);
331+
} catch {
332+
// folder doesn't exist, create it
333+
await vscode.workspace.fs.createDirectory(devProxyFolder);
334+
}
335+
325336
// show progress
326337
await vscode.window.withProgress({
327338
location: vscode.ProgressLocation.Notification,
328339
title: 'Creating new config file...'
329340
}, async () => {
330-
await executeCommand(`${devProxyExe} config new ${fileName}`, { cwd: vscode.workspace.workspaceFolders?.[0].uri.fsPath });
341+
await executeCommand(`${devProxyExe} config new ${fileName}`, { cwd: `${workspaceFolder}/.devproxy` });
331342
});
332343

333-
const configUri = vscode.Uri.file(`${vscode.workspace.workspaceFolders?.[0].uri.fsPath}/${fileName}`);
344+
const configUri = vscode.Uri.file(`${workspaceFolder}/.devproxy/${fileName}`);
334345
const document = await vscode.workspace.openTextDocument(configUri);
335346
await vscode.window.showTextDocument(document);
336347
} catch (error) {

0 commit comments

Comments
 (0)