From 26ef2ab83707e94115169a5b3db21026a29b9825 Mon Sep 17 00:00:00 2001 From: aalej Date: Fri, 13 Dec 2024 02:13:16 +0800 Subject: [PATCH] added validation for project id and project name --- CHANGELOG.md | 1 + src/management/projects.ts | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b17de18fd0c..8a3f1bbd01a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,3 +4,4 @@ - CF3 callables can now be annotate with a genkit action they are serving (#8039) - HTTPS functions can now be upgraded to HTTPS Callable functions (#8039) - Update default tsconfig to support more modern defaults (#8039) +- Added validation for project ID and project name during `firebase init` (#2514) diff --git a/src/management/projects.ts b/src/management/projects.ts index 93076da1699..9f25bc4552b 100644 --- a/src/management/projects.ts +++ b/src/management/projects.ts @@ -33,12 +33,30 @@ export const PROJECTS_CREATE_QUESTIONS: Question[] = [ message: "Please specify a unique project id " + `(${clc.yellow("warning")}: cannot be modified afterward) [6-30 characters]:\n`, + validate: (projectId: string) => { + if (projectId.length < 6) { + return "Project ID must be at least 6 characters long"; + } else if (projectId.length > 30) { + return "Project ID cannot be longer than 30 characters"; + } else { + return true; + } + }, }, { type: "input", name: "displayName", - default: "", + default: (answers: any) => answers.projectId, message: "What would you like to call your project? (defaults to your project ID)", + validate: (displayName: string) => { + if (displayName.length < 4) { + return "Project name must be at least 4 characters long"; + } else if (displayName.length > 30) { + return "Project name cannot be longer than 30 characters"; + } else { + return true; + } + }, }, ];