Skip to content

Commit c6fa5b0

Browse files
authored
add warning if folder exists in target path (#53)
* add warning if folder already exists in target path * separate ask folder functions and add constants * move options into new target folder function * fix for target folder path check for windows Signed-off-by: Jimmy Wu <[email protected]>
1 parent 65d00c4 commit c6fa5b0

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

Diff for: src/commands/generateProject.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ export async function generateProject(): Promise<void> {
6060
return;
6161
}
6262

63-
const targetFolder = await prompts.askForFolder({
64-
openLabel: "Generate into this folder",
65-
});
63+
const targetFolder = await prompts.askForTargetFolder(artifactId);
6664
if (targetFolder === undefined) {
6765
return;
6866
}

Diff for: src/constants.ts

+5
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ export const OPEN_NEW_PROJECT_OPTIONS = {
2828
};
2929

3030
export const EXTENSION_USER_AGENT = "Visual Studio Code";
31+
32+
export const CONFIRM_OPTIONS = {
33+
YES: "Yes",
34+
NO: "No",
35+
};

Diff for: src/util/vscodePrompts.ts

+32-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as vscode from "vscode";
2+
import * as path from "path";
23
import { OpenDialogOptions, Uri, window, QuickPickItem } from "vscode";
3-
import { MP_SERVER_LABELS, MP_VERSION_LABELS } from "../constants";
4-
import { trimCapitalizeFirstLetter } from "./util";
4+
import { MP_SERVER_LABELS, MP_VERSION_LABELS, CONFIRM_OPTIONS } from "../constants";
5+
import { trimCapitalizeFirstLetter, exists } from "./util";
56

67
export async function askForGroupID(): Promise<string | undefined> {
78
return await vscode.window.showInputBox({
@@ -160,3 +161,32 @@ export async function askForFolder(customOptions: OpenDialogOptions): Promise<Ur
160161

161162
return undefined;
162163
}
164+
165+
export async function askForTargetFolder(artifactId: string): Promise<Uri | undefined> {
166+
const customOptions: OpenDialogOptions = {
167+
openLabel: "Generate into this folder",
168+
};
169+
170+
const targetFolder = await askForFolder(customOptions);
171+
172+
if (targetFolder && (await exists(path.join(targetFolder.fsPath, artifactId)))) {
173+
const selection = await askConfirmation(
174+
`Folder ${artifactId} already exists inside the ${targetFolder.fsPath} folder. Contents of the ${artifactId} folder and the generated MicroProfile Starter Project will be merged. Are you sure you want to generate into this folder?`
175+
);
176+
if (selection === CONFIRM_OPTIONS.YES) {
177+
return targetFolder;
178+
} else if (selection === CONFIRM_OPTIONS.NO) {
179+
return await askForTargetFolder(artifactId);
180+
}
181+
return undefined;
182+
}
183+
184+
return targetFolder;
185+
}
186+
187+
export async function askConfirmation(message: string): Promise<string | undefined> {
188+
return await vscode.window.showWarningMessage(
189+
message,
190+
...[CONFIRM_OPTIONS.YES, CONFIRM_OPTIONS.NO]
191+
);
192+
}

0 commit comments

Comments
 (0)