Skip to content

Commit 95ba86d

Browse files
committed
fix: Checks if project already exists
1 parent 6f5a799 commit 95ba86d

File tree

7 files changed

+47
-27
lines changed

7 files changed

+47
-27
lines changed

vscode-extension/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"type": "git",
88
"url": "https://github.com/swift-server-community/vscode-aws-lambda-swift-sam"
99
},
10-
"version": "1.1.7",
10+
"version": "1.1.8",
1111
"workspaces": [
1212
"packages/*"
1313
],

vscode-extension/packages/core-lib/src/sam/sam.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export async function getRegions(): Promise<RegionsResult> {
121121
* @returns {Promise<string>} The default path
122122
*/
123123
export async function getDefaultPath(): Promise<string> {
124-
const defaultPath = process.env.HOME + "/Documents/aws-lambda-swift";
124+
const defaultPath = process.env.HOME + "/Documents/MySwiftLambdaFunctions";
125125
if (!fs.existsSync(defaultPath)) {
126126
fs.mkdirSync(defaultPath, { recursive: true });
127127
}

vscode-extension/src/commands/Commands.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ export async function getFunctions(data: any) {
3434
* @returns {Promise<{ exists: boolean }>} An object containing whether the folder exists.
3535
*/
3636
export async function checkFolderExists(data: any) {
37-
const folderPath = data.folderPath;
38-
const exists = await Sam.checkFolderExists(folderPath);
39-
return { exists };
37+
const path = data.path;
38+
const type = data.type;
39+
const exists = await Sam.checkFolderExists(path);
40+
return { exists, type };
4041
}
4142

4243
/**

vscode-extension/src/panels/MainPanel.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,17 @@ export class MainPanel {
211211
const data = message.data;
212212

213213
switch (command) {
214-
case "checkFolderExists":
214+
case "checkExists":
215215
checkFolderExists(data)
216216
.then((response) => {
217217
webview.postMessage({
218-
command: "folderCheckResult",
218+
command: "checkResult",
219219
data: response,
220220
});
221221
})
222222
.catch((error) => {
223223
webview.postMessage({
224-
command: "folderCheckResult",
224+
command: "checkResult",
225225
data: { success: false, error },
226226
});
227227
});

vscode-extension/webview-ui/src/components/configuration/Configuration.css

-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
}
3939

4040
.slash-separator {
41-
display: flex;
42-
align-items: center;
43-
justify-content: center;
4441
font-size: 1.5rem;
4542
margin: 0 0.3rem;
4643
}

vscode-extension/webview-ui/src/components/configuration/Configuration.tsx

+31-14
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,35 @@ const Configuration = () => {
3232
// Hooks for translation and context
3333
const [t] = useTranslation("global");
3434
const { configuration, setConfiguration } = useContext(ConfigurationContext);
35-
const [error, setError] = useState("");
35+
const [errorFolder, setErrorFolder] = useState("");
36+
const [errorName, setErrorName] = useState("");
3637

37-
const checkFolderExists = (folderPath: string) => {
38-
if (folderPath) {
38+
const checkExists = (path: string, type: string) => {
39+
if (path) {
3940
vscode.postMessage({
40-
command: "checkFolderExists",
41+
command: "checkExists",
4142
data: {
42-
folderPath,
43+
path,
44+
type,
4345
},
4446
});
4547
} else {
46-
setError(t("configuration.error.emptyPath"));
48+
if (type === "folder") setErrorFolder(t("configuration.error.emptyPath"));
49+
else if (type === "name")
50+
setErrorName(t("configuration.error.emptyName"));
4751
}
4852
};
4953

5054
useEffect(() => {
5155
const listener = (event: any) => {
52-
if (event.data.command === "folderCheckResult") {
53-
if (!event.data.data.exists) {
54-
setError(t("configuration.error.folderDoesNotExist"));
55-
} else {
56-
setError("");
56+
if (event.data.command === "checkResult") {
57+
const { exists, type } = event.data.data;
58+
if (type === "folder") {
59+
setErrorFolder(
60+
exists ? "" : t("configuration.error.folderDoesNotExist"),
61+
);
62+
} else if (type === "name") {
63+
setErrorName(exists ? t("configuration.error.alreadyExists") : "");
5764
}
5865
}
5966
};
@@ -84,12 +91,13 @@ const Configuration = () => {
8491
});
8592
}}
8693
onBlur={(e: any) => {
87-
checkFolderExists(e.target.value);
94+
checkExists(e.target.value, "folder");
8895
}}
8996
placeholder={t("configuration.form.projectFolder.placeholder")}
90-
className={error ? "error-textField" : ""}
97+
className={errorFolder ? "error-textField" : ""}
9198
/>
92-
{error && <div className="error-message">{error}</div>}
99+
{errorFolder && <div className="error-message">{errorFolder}</div>}
100+
{errorName && <div className="error-message">{errorName}</div>}
93101
</div>
94102
<div className="slash-separator">
95103
<p>/</p>
@@ -107,7 +115,16 @@ const Configuration = () => {
107115
projectName: e.target.value,
108116
});
109117
}}
118+
onBlur={(e: any) => {
119+
checkExists(
120+
e.target.value
121+
? configuration.projectFolder + "/" + e.target.value
122+
: e.target.value,
123+
"name",
124+
);
125+
}}
110126
placeholder={t("configuration.form.projectName.placeholder")}
127+
className={errorName ? "error-textField" : ""}
111128
/>
112129
</div>
113130
</div>

vscode-extension/webview-ui/src/i18n/en/global.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
},
4040
"error": {
4141
"emptyPath": "Project folder path cannot be empty",
42-
"folderDoesNotExist": "Folder does not exist"
42+
"folderDoesNotExist": "Folder does not exist",
43+
"emptyName": "Project name cannot be empty",
44+
"alreadyExists": "Project already exists, please choose another name"
4345
}
4446
},
4547
"initializeProject": {
@@ -58,7 +60,10 @@
5860
"info": {
5961
"message": "This will create a new project with the selected template."
6062
},
61-
"button": "Initialize"
63+
"button": "Initialize",
64+
"error": {
65+
"folderAlreadyExists": "Project already exist, please choose another folder"
66+
}
6267
},
6368
"buildProject": {
6469
"title": "Build Project",

0 commit comments

Comments
 (0)