feat(create-medusa-app): allow passing project name on command line (#10755)
Allow passing the project name on the command line: ```bash npx create-medusa-app@latest my-project ```
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"create-medusa-app": patch
|
||||
---
|
||||
|
||||
feat(create-medusa-app): allow passing project name on command line
|
||||
@@ -44,17 +44,20 @@ export type CreateOptions = {
|
||||
verbose?: boolean
|
||||
}
|
||||
|
||||
export default async ({
|
||||
repoUrl = "",
|
||||
seed,
|
||||
skipDb,
|
||||
dbUrl,
|
||||
browser,
|
||||
migrations,
|
||||
directoryPath,
|
||||
withNextjsStarter = false,
|
||||
verbose = false,
|
||||
}: CreateOptions) => {
|
||||
export default async (
|
||||
args: string[],
|
||||
{
|
||||
repoUrl = "",
|
||||
seed,
|
||||
skipDb,
|
||||
dbUrl,
|
||||
browser,
|
||||
migrations,
|
||||
directoryPath,
|
||||
withNextjsStarter = false,
|
||||
verbose = false,
|
||||
}: CreateOptions
|
||||
) => {
|
||||
const nodeVersion = getNodeVersion()
|
||||
if (nodeVersion < MIN_SUPPORTED_NODE_VERSION) {
|
||||
logMessage({
|
||||
@@ -98,7 +101,20 @@ export default async ({
|
||||
return
|
||||
})
|
||||
|
||||
const projectName = await askForProjectName(directoryPath)
|
||||
let askProjectName = args.length === 0
|
||||
if (args.length > 0) {
|
||||
// check if project directory already exists
|
||||
const projectPath = getProjectPath(args[0], directoryPath)
|
||||
if (fs.existsSync(projectPath) && fs.lstatSync(projectPath).isDirectory()) {
|
||||
logMessage({
|
||||
message: `A directory already exists with the name ${args[0]}. Please enter a different project name.`,
|
||||
type: "warn",
|
||||
})
|
||||
askProjectName = true
|
||||
}
|
||||
}
|
||||
|
||||
const projectName = askProjectName ? await askForProjectName(directoryPath) : args[0]
|
||||
const projectPath = getProjectPath(projectName, directoryPath)
|
||||
const installNextjs = withNextjsStarter || (await askForNextjsStarter())
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import create from "./commands/create.js"
|
||||
|
||||
program
|
||||
.description("Create a new Medusa project")
|
||||
.argument("[project-name]", "Name of the project to create.")
|
||||
.option("--repo-url <url>", "URL of repository to use to setup project.")
|
||||
.option("--seed", "Seed the created database with demo data.")
|
||||
.option(
|
||||
@@ -41,4 +42,4 @@ program
|
||||
)
|
||||
.parse()
|
||||
|
||||
void create(program.opts())
|
||||
void create(program.args, program.opts())
|
||||
|
||||
@@ -4,7 +4,7 @@ import { logger } from "./logger.js"
|
||||
|
||||
type LogOptions = {
|
||||
message: string
|
||||
type?: "error" | "success" | "info" | "warning" | "verbose"
|
||||
type?: "error" | "success" | "info" | "warn" | "verbose"
|
||||
}
|
||||
|
||||
export default ({ message, type = "info" }: LogOptions) => {
|
||||
@@ -15,8 +15,8 @@ export default ({ message, type = "info" }: LogOptions) => {
|
||||
case "success":
|
||||
logger.info(chalk.green(message))
|
||||
break
|
||||
case "warning":
|
||||
logger.warning(chalk.yellow(message))
|
||||
case "warn":
|
||||
logger.warn(chalk.yellow(message))
|
||||
break
|
||||
case "verbose":
|
||||
logger.info(`${chalk.bgYellowBright("VERBOSE LOG:")} ${message}`)
|
||||
|
||||
Reference in New Issue
Block a user