fix: exists check, projectName validation on pre-enter

This commit is contained in:
2026-06-11 16:31:18 +02:00
parent 65f2efd879
commit a6a6d13e5c
2 changed files with 16 additions and 3 deletions
+6 -1
View File
@@ -29,7 +29,8 @@ async function main() {
return "Project name is required";
if (!/^[a-zA-Z0-9-]+$/.test(value))
return "Project name can only contain letters, numbers, and dashes";
if (fs.existsSync(value))
const targetDir = path.resolve(process.cwd(), value);
if (fs.existsSync(targetDir))
return "Directory already exists";
return true;
},
@@ -39,6 +40,10 @@ async function main() {
process.exit(1);
}
}
if (!/^[a-zA-Z0-9-]+$/.test(projectName)) {
console.error("❌ Project name can only contain letters, numbers, and dashes");
process.exit(1);
}
const templateType = await select({
message: "Please select a template type:",
choices: projectTypes,
+10 -2
View File
@@ -33,7 +33,8 @@ async function main() {
if (!value) return "Project name is required";
if (!/^[a-zA-Z0-9-]+$/.test(value))
return "Project name can only contain letters, numbers, and dashes";
if (fs.existsSync(value)) return "Directory already exists";
const targetDir = path.resolve(process.cwd(), value);
if (fs.existsSync(targetDir)) return "Directory already exists";
return true;
},
});
@@ -44,6 +45,13 @@ async function main() {
}
}
if (!/^[a-zA-Z0-9-]+$/.test(projectName)) {
console.error(
"❌ Project name can only contain letters, numbers, and dashes",
);
process.exit(1);
}
const templateType = await select({
message: "Please select a template type:",
choices: projectTypes,
@@ -52,7 +60,7 @@ async function main() {
const targetDir = path.resolve(process.cwd(), projectName);
const templateDir = path.resolve(__dirname, `../templates/${templateType}`);
if(!fs.existsSync(templateDir)) {
if (!fs.existsSync(templateDir)) {
console.error("❌ Template directory not found");
process.exit(1);
}