Skip to content

Commit

Permalink
Add create option if file does not exist
Browse files Browse the repository at this point in the history
If the file doesn't exist, a warning is displayed. Add a create button to create the file on the warning and proceed.
  • Loading branch information
grgar committed Apr 3, 2024
1 parent 76512b1 commit c4a04a2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Changelog
### v1.1.3

- Add create option if file does not exist

If the file doesn't exist, a warning is displayed. Add a create button to create the file on the warning and proceed.

### v1.1.2

- Always use posix-specific pathing
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 @@ -8,7 +8,7 @@
},
"description": "Apply dotfiles from settings",
"icon": "images/icon-small.png",
"version": "1.1.2",
"version": "1.1.3",
"license": "MIT",
"engines": {
"vscode": "^1.74.0"
Expand Down
9 changes: 9 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ async function apply() {
const filePath = path.join(directory, file);
try {
await fs.stat(filePath);
} catch (err) {
switch (await vscode.window.showWarningMessage(`${filePath} does not exist: ${err}`, "Create")) {
case "Create":
break;
default:
continue;
}
}
try {
await fs.writeFile(filePath, content);
outputChannel.appendLine(`${new Date().toLocaleString()}: wrote ${filePath}`);
} catch (err) {
Expand Down

0 comments on commit c4a04a2

Please sign in to comment.