From 48a945f8548ba5883f48596a0162899d7afb4f6b Mon Sep 17 00:00:00 2001 From: Leandro Melo Date: Mon, 15 Jan 2024 11:42:34 +0000 Subject: [PATCH] app name validation on creating project --- README.md | 5 +++-- commands/create.js | 28 +++++++++++++--------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 3e97f5c..25767aa 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ NPM Downloads

+## `This project currently only supports creation of React + vite and raw JS projects with Biomejs as lint and formatter` + # Monorepo Automator **Create Monorepo Projects with Ease** @@ -55,7 +57,6 @@ Option | Description ---|--- `-p` or `--path` | Provide path where you want to create the monorepo project - + ## Contributing Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Check the contributor guidelines [here](CONTRIBUTING.md). diff --git a/commands/create.js b/commands/create.js index 5a9119f..361fa39 100644 --- a/commands/create.js +++ b/commands/create.js @@ -58,21 +58,9 @@ export default async (cmd, opts, appDir) => { try { const folders = await promisifyQuestion( - "❔ Which subfolders should this project have? (ex: client(vite) backoffice(vite) server) (separate by space)\n", + "❔ Which apps should this project have? (ex: client,backoffice,server) (separate by comma)\n", ); - //TODO: sanitize input - // const validFolders = new RegExp(/^([a-zA-Z]+(?:-[a-zA-Z]+)?(\([a-zA-Z]+(?:-[a-zA-Z]+)?\))?\s*)*$/).test( - // folders, - // ); - - // if (!validFolders) { - // handleError( - // "Invalid subfolders format.\nSubfolder names must not contain special characters or numbers.\nAll subfolders must be separated by a space and can be followed by and development environment inside parenthesis. ", - // `${projectPath}${projectName}`, - // ); - // } - const apps = folders.split(",").map((el, index) => ({ name: el, path: `${projectPath}${projectName}/${el}`, @@ -80,15 +68,25 @@ export default async (cmd, opts, appDir) => { })); for (let i = 0; i <= apps.length - 1; i++) { - console.log(i); const app = apps[i]; + const isNameValid = new RegExp(/^[a-zA-Z0-9_-]+$/).test(app.name); + + if (!isNameValid) { + handleError( + "Invalid app name format.\nApp names must not contain special characters.", + `${projectPath}${projectName}`, + ); + } + await list({ name: "devEnv", message: `❔ Do you want to install any development environment on ${app.name}?`, choices: ["vite", "none"], }).then(res => { - app.devEnv = res.devEnv; + if (res.devEnv !== "none") { + app.devEnv = res.devEnv; + } }); }