From 17cd523235ad7f8b02d173ec450cf0a4aebeb412 Mon Sep 17 00:00:00 2001 From: nicoschoenteich Date: Fri, 6 Sep 2024 17:06:32 +0200 Subject: [PATCH] fix: destination name can't be empty --- generators/helpers.js | 10 ++++++++++ generators/model/prompts.js | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/generators/helpers.js b/generators/helpers.js index 05a56fb..4eb4c08 100644 --- a/generators/helpers.js +++ b/generators/helpers.js @@ -104,6 +104,16 @@ export function validateAlphaNumeric(string) { return "Please use alpha numeric characters only." } +export function validateAlphaNumericNonEmpty(string) { + if (/^[a-zA-Z0-9_-]*$/g.test(string)) { + if (string !== "") { + return true + } + } + return "Please use a non-empty value with alpha numeric characters only." +} + + export function validateUrl(string) { if (new URL(string) instanceof Error) { return // no error message required, yeoman will forward an error to the user diff --git a/generators/model/prompts.js b/generators/model/prompts.js index d0138ca..bf0055b 100644 --- a/generators/model/prompts.js +++ b/generators/model/prompts.js @@ -1,6 +1,7 @@ import { validateAlphaNumeric, - validateUrl + validateUrl, + validateAlphaNumericNonEmpty } from "../helpers.js" export default async function prompts() { @@ -57,7 +58,7 @@ export default async function prompts() { type: "input", name: "destName", message: "How do you want to name your new destination?", - validate: validateAlphaNumeric + validate: validateAlphaNumericNonEmpty })).destName } }