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,7 +44,9 @@ export type CreateOptions = {
|
|||||||
verbose?: boolean
|
verbose?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async ({
|
export default async (
|
||||||
|
args: string[],
|
||||||
|
{
|
||||||
repoUrl = "",
|
repoUrl = "",
|
||||||
seed,
|
seed,
|
||||||
skipDb,
|
skipDb,
|
||||||
@@ -54,7 +56,8 @@ export default async ({
|
|||||||
directoryPath,
|
directoryPath,
|
||||||
withNextjsStarter = false,
|
withNextjsStarter = false,
|
||||||
verbose = false,
|
verbose = false,
|
||||||
}: CreateOptions) => {
|
}: CreateOptions
|
||||||
|
) => {
|
||||||
const nodeVersion = getNodeVersion()
|
const nodeVersion = getNodeVersion()
|
||||||
if (nodeVersion < MIN_SUPPORTED_NODE_VERSION) {
|
if (nodeVersion < MIN_SUPPORTED_NODE_VERSION) {
|
||||||
logMessage({
|
logMessage({
|
||||||
@@ -98,7 +101,20 @@ export default async ({
|
|||||||
return
|
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 projectPath = getProjectPath(projectName, directoryPath)
|
||||||
const installNextjs = withNextjsStarter || (await askForNextjsStarter())
|
const installNextjs = withNextjsStarter || (await askForNextjsStarter())
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import create from "./commands/create.js"
|
|||||||
|
|
||||||
program
|
program
|
||||||
.description("Create a new Medusa project")
|
.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("--repo-url <url>", "URL of repository to use to setup project.")
|
||||||
.option("--seed", "Seed the created database with demo data.")
|
.option("--seed", "Seed the created database with demo data.")
|
||||||
.option(
|
.option(
|
||||||
@@ -41,4 +42,4 @@ program
|
|||||||
)
|
)
|
||||||
.parse()
|
.parse()
|
||||||
|
|
||||||
void create(program.opts())
|
void create(program.args, program.opts())
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { logger } from "./logger.js"
|
|||||||
|
|
||||||
type LogOptions = {
|
type LogOptions = {
|
||||||
message: string
|
message: string
|
||||||
type?: "error" | "success" | "info" | "warning" | "verbose"
|
type?: "error" | "success" | "info" | "warn" | "verbose"
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ({ message, type = "info" }: LogOptions) => {
|
export default ({ message, type = "info" }: LogOptions) => {
|
||||||
@@ -15,8 +15,8 @@ export default ({ message, type = "info" }: LogOptions) => {
|
|||||||
case "success":
|
case "success":
|
||||||
logger.info(chalk.green(message))
|
logger.info(chalk.green(message))
|
||||||
break
|
break
|
||||||
case "warning":
|
case "warn":
|
||||||
logger.warning(chalk.yellow(message))
|
logger.warn(chalk.yellow(message))
|
||||||
break
|
break
|
||||||
case "verbose":
|
case "verbose":
|
||||||
logger.info(`${chalk.bgYellowBright("VERBOSE LOG:")} ${message}`)
|
logger.info(`${chalk.bgYellowBright("VERBOSE LOG:")} ${message}`)
|
||||||
|
|||||||
Reference in New Issue
Block a user