Skip to content

Commit

Permalink
update wording
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p committed Jan 10, 2025
1 parent 4ae8b82 commit cd007a3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
26 changes: 17 additions & 9 deletions packages/cli/create-medusa-app/src/commands/create-refactoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ class ProjectCreatorFactory {

const projectName = await ProjectCreatorFactory.getProjectName(
args,
options.directoryPath
isPlugin,
options.directoryPath,
isPlugin
)

return isPlugin
Expand Down Expand Up @@ -470,36 +470,44 @@ class ProjectCreatorFactory {
fs.lstatSync(projectPath).isDirectory()
) {
logMessage({
message: `A directory already exists with the name ${args[0]}. Please enter a different ${isPlugin ? "plugin" : "project"} name.`,
message: `A directory already exists with the name ${
args[0]
}. Please enter a different ${isPlugin ? "plugin" : "project"} name.`,
type: "warn",
})
askProjectName = true
}
}

return askProjectName ? await askForProjectName(directoryPath) : args[0]
return askProjectName
? await askForProjectName(directoryPath, isPlugin)
: args[0]
}
}

// User Input Handler
async function askForProjectName(directoryPath?: string): Promise<string> {
async function askForProjectName(
directoryPath?: string,
isPlugin?: boolean
): Promise<string> {
const { projectName } = await inquirer.prompt([
{
type: "input",
name: "projectName",
message: "What's the name of your project?",
message: `What's the name of your ${isPlugin ? "plugin" : "project"}?`,
default: "my-medusa-store",
filter: (input) => {
return slugify(input).toLowerCase()
},
validate: (input) => {
if (!input.length) {
return "Please enter a project name"
return `Please enter a ${isPlugin ? "plugin" : "project"} name`
}
const projectPath = path.join(directoryPath || "", input)
return fs.existsSync(projectPath) &&
fs.lstatSync(projectPath).isDirectory()
? "A directory already exists with the same name. Please enter a different project name."
? `A directory already exists with the same name. Please enter a different ${
isPlugin ? "plugin" : "project"
} name.`
: true
},
},
Expand Down
17 changes: 11 additions & 6 deletions packages/cli/create-medusa-app/src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ async function createPluginProject(
}

const projectName = askProjectName
? await askForProjectName(directoryPath)
? await askForProjectName(directoryPath, true)
: args[0]
const projectPath = getProjectPath(projectName, directoryPath)

Expand Down Expand Up @@ -280,7 +280,7 @@ async function createMedusaProject(
}

const projectName = askProjectName
? await askForProjectName(directoryPath)
? await askForProjectName(directoryPath, false)
: args[0]
const projectPath = getProjectPath(projectName, directoryPath)
const installNextjs = withNextjsStarter || (await askForNextjsStarter())
Expand Down Expand Up @@ -449,24 +449,29 @@ async function createMedusaProject(
})
}

async function askForProjectName(directoryPath?: string): Promise<string> {
async function askForProjectName(
directoryPath?: string,
isPlugin?: boolean
): Promise<string> {
const { projectName } = await inquirer.prompt([
{
type: "input",
name: "projectName",
message: "What's the name of your project?",
message: `What's the name of your ${isPlugin ? "plugin" : "project"}?`,
default: "my-medusa-store",
filter: (input) => {
return slugify(input).toLowerCase()
},
validate: (input) => {
if (!input.length) {
return "Please enter a project name"
return `Please enter a ${isPlugin ? "plugin" : "project"} name`
}
const projectPath = getProjectPath(input, directoryPath)
return fs.existsSync(projectPath) &&
fs.lstatSync(projectPath).isDirectory()
? "A directory already exists with the same name. Please enter a different project name."
? `A directory already exists with the same name. Please enter a different ${
isPlugin ? "plugin" : "project"
} name.`
: true
},
},
Expand Down

0 comments on commit cd007a3

Please sign in to comment.