Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes spaces in project name #176

Merged
merged 11 commits into from
Jan 6, 2025
5 changes: 5 additions & 0 deletions .changeset/bright-pigs-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-eth": patch
---

restrict trailing whitespace in the project name
8 changes: 7 additions & 1 deletion src/utils/parse-arguments-into-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { validateFoundryUp } from "./system-validation";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { HAS_TRAILING_WHITESPACE_REGEX } from "./prompt-for-missing-options";

const validateExternalExtension = async (
extensionName: string,
Expand Down Expand Up @@ -84,7 +85,7 @@ export async function parseArgumentsIntoOptions(

const help = args["--help"] ?? false;

const project = args._[0] ?? null;
let project: string | null = args._[0] ?? null;

// use the original extension arg
const extensionName = args["--extension"] && rawArgs.slice(2).find(a => a.toLowerCase() === args["--extension"]);
Expand All @@ -101,6 +102,11 @@ export async function parseArgumentsIntoOptions(
);
}

if (project && HAS_TRAILING_WHITESPACE_REGEX.test(project)) {
project = null;
console.log(chalk.yellow(" Project name cannot end with whitespace. Enter a valid project name."));
technophile-04 marked this conversation as resolved.
Show resolved Hide resolved
}

let solidityFrameworkChoices = [
SOLIDITY_FRAMEWORKS.HARDHAT,
SOLIDITY_FRAMEWORKS.FOUNDRY,
Expand Down
8 changes: 7 additions & 1 deletion src/utils/prompt-for-missing-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Options, RawOptions, SolidityFrameworkChoices } from "../types";
import inquirer from "inquirer";
import { SOLIDITY_FRAMEWORKS } from "./consts";

export const HAS_TRAILING_WHITESPACE_REGEX = /\s$/;

// default values for unspecified args
const defaultOptions: RawOptions = {
project: "my-dapp-example",
Expand All @@ -23,7 +25,11 @@ export async function promptForMissingOptions(
name: "project",
message: "Your project name:",
default: defaultOptions.project,
validate: (value: string) => value.length > 0,
validate: (value: string) => {
if (value.length === 0) return "Project name cannot be empty";
if (HAS_TRAILING_WHITESPACE_REGEX.test(value)) return "Project name cannot end with whitespace";
return true;
},
},
{
type: "list",
Expand Down
Loading