Skip to content

Commit

Permalink
feat: showInformationMessage if file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
lxkuz committed Jul 28, 2021
1 parent 5837317 commit 3f32077
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions templates/vscode-extension/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,33 @@ const getRemoteDirStructure = async ({
};

const buildDirStructure = async (structure) => {
structure.forEach((entity) => {
structure.forEach(async (entity) => {
if (!entity) return;

const { fileType, fileName, fileContent, filePath } = entity;

let writeFlag = false;
if (fileType === vscode.FileType.Directory) {
buildDirStructure(fileContent);
} else {
vscode.workspace.fs.writeFile(
vscode.Uri.file(`${filePath}/${fileName}`),
new TextEncoder().encode(fileContent)
);
const fullPath = vscode.Uri.file(`${filePath}/${fileName}`)
try {
vscode.workspace.fs.readFile(fullPath)
const answer = await vscode.window.showInformationMessage(
`File ${fullPath} already exists`,
...["Rewrite", "Keep it"]
)
writeFlag = answer === "Yes"
} catch (_err) {
// Do we know a better way to ensure file doesn't exist
// but raising exception while reading the file?
writeFlag = true
}
if(writeFlag) {
vscode.workspace.fs.writeFile(
fullPath,
new TextEncoder().encode(fileContent)
);
}
}
});
};
Expand Down

0 comments on commit 3f32077

Please sign in to comment.