Skip to content

Commit

Permalink
This fully addresses issue Knowcode-AI#5 and contributes to my issue K…
Browse files Browse the repository at this point in the history
…nowcode-AI#6

The /media/drawable directory does not exist when the extension is initially
installed, yet the createOrShow() function calls fs.rmdirSync recursively,
which throws an error on the non-existing drawable directory (media exists).

I've wrapped this call up with an fs.existsSync, which will perform the
existing action if the directory exists, otherwise it calls fs.mkdirSync
with the same options as the call to fs.rmdirSync (i.e, recursive: true)

The extension will now execute successfully on an initial install without the
user having to create the subdirectory tree manually.
  • Loading branch information
Nos78 committed Nov 7, 2022
1 parent 418a344 commit 06a422d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,17 @@ class AppPanel {
// fall back to hard-coded path
resourcesPath = "src/main/res/drawable";
}

const fse = require('fs-extra');
//@ts-ignore.
var sourceDir = path.join(rootUri?.path, resourcesPath)
var destinationDir = path.join(extensionUri.path, "/media/drawable")
fs.rmdirSync(destinationDir, { recursive: true });

if (fs.existsSync(destinationDir)) {
fs.rmdirSync(destinationDir, { recursive: true });
} else {
// Create cache location
fs.mkdirSync(destinationDir, { recursive: true });
}
// To copy a folder or file
fse.copySync(sourceDir, destinationDir)

Expand Down

0 comments on commit 06a422d

Please sign in to comment.