Skip to content

Commit

Permalink
app name validation on creating project
Browse files Browse the repository at this point in the history
  • Loading branch information
Tpleme committed Jan 15, 2024
1 parent fe21469 commit 48a945f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<img alt="NPM Downloads" src="https://img.shields.io/npm/dt/%40tpleme%2Fmonorepo-automator?logo=npm">
</p>

## `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**
Expand Down Expand Up @@ -55,7 +57,6 @@ Option | Description
---|---
`-p` or `--path` | Provide path where you want to create the monorepo project

<!--
##
- ### Add
```bash
Expand All @@ -66,7 +67,7 @@ monorepo-automator add <name> [options]
Option | Description
---|---
`-e` or `--env` | Provide a development environment to the new app, ex: vite
-->

## 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).
Expand Down
28 changes: 13 additions & 15 deletions commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,37 +58,35 @@ 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}`,
port: 3000 + index,
}));

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;
}
});
}

Expand Down

0 comments on commit 48a945f

Please sign in to comment.