From 5bc780a64626a89f42a46723a7bc84a41ca3d953 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Fri, 3 May 2024 09:43:54 +0300 Subject: [PATCH] feat(medusa-cli): added v2 flag (#7211) --- .changeset/olive-tigers-mate.md | 5 +++++ packages/medusa-cli/src/commands/new.ts | 19 +++++++++++-------- packages/medusa-cli/src/create-cli.ts | 5 +++++ 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 .changeset/olive-tigers-mate.md diff --git a/.changeset/olive-tigers-mate.md b/.changeset/olive-tigers-mate.md new file mode 100644 index 0000000000..0da2c3d700 --- /dev/null +++ b/.changeset/olive-tigers-mate.md @@ -0,0 +1,5 @@ +--- +"@medusajs/medusa-cli": patch +--- + +feat(medusa-cli): added v2 flag diff --git a/packages/medusa-cli/src/commands/new.ts b/packages/medusa-cli/src/commands/new.ts index 668136aa75..1f3fe99476 100644 --- a/packages/medusa-cli/src/commands/new.ts +++ b/packages/medusa-cli/src/commands/new.ts @@ -169,7 +169,7 @@ const copy = async (starterPath, rootPath) => { } // Clones starter from URI. -const clone = async (hostInfo, rootPath) => { +const clone = async (hostInfo, rootPath, v2 = false) => { let url // Let people use private repos accessed over SSH. if (hostInfo.getDefaultRepresentation() === `sshurl`) { @@ -179,7 +179,8 @@ const clone = async (hostInfo, rootPath) => { url = hostInfo.https({ noCommittish: true, noGitPlus: true }) } - const branch = hostInfo.committish ? [`-b`, hostInfo.committish] : [] + const branch = v2 ? [`-b`, "feat/v2"] : + hostInfo.committish ? [`-b`, hostInfo.committish] : [] const createAct = reporter.activity(`Creating new project from git: ${url}`) @@ -228,7 +229,7 @@ const getMedusaConfig = (rootPath) => { return {} } -const getPaths = async (starterPath, rootPath) => { +const getPaths = async (starterPath, rootPath, v2 = false) => { let selectedOtherStarter = false // if no args are passed, prompt user for path and starter @@ -240,7 +241,7 @@ const getPaths = async (starterPath, rootPath) => { message: `What is your project called?`, initial: `my-medusa-store`, }, - { + !v2 && { type: `select`, name: `starter`, message: `What starter would you like to use?`, @@ -253,14 +254,14 @@ const getPaths = async (starterPath, rootPath) => { ]) // exit gracefully if responses aren't provided - if (!response.starter || !response.path.trim()) { + if ((!v2 && !response.starter) || !response.path.trim()) { throw new Error( `Please mention both starter package and project name along with path(if its not in the root)` ) } selectedOtherStarter = response.starter === `different` - starterPath = `medusajs/${response.starter}` + starterPath = `medusajs/${v2 ? "medusa-starter-default" : response.starter}` rootPath = response.path } @@ -523,6 +524,7 @@ export const newStarter = async (args) => { dbPass, dbPort, dbHost, + v2 } = args const dbCredentials = removeUndefined({ @@ -535,7 +537,8 @@ export const newStarter = async (args) => { const { starterPath, rootPath, selectedOtherStarter } = await getPaths( starter, - root + root, + v2 ) const urlObject = url.parse(rootPath) @@ -597,7 +600,7 @@ medusa new ${rootPath} [url-to-starter] const hostedInfo = hostedGitInfo.fromUrl(starterPath) if (hostedInfo) { - await clone(hostedInfo, rootPath) + await clone(hostedInfo, rootPath, v2) } else { await copy(starterPath, rootPath) } diff --git a/packages/medusa-cli/src/create-cli.ts b/packages/medusa-cli/src/create-cli.ts index 395a17ca5b..e04ca8bbd0 100644 --- a/packages/medusa-cli/src/create-cli.ts +++ b/packages/medusa-cli/src/create-cli.ts @@ -113,6 +113,11 @@ function buildLocalCommands(cli, isLocalProject) { .option(`db-host`, { type: `string`, describe: `The database host to use for database setup and migrations.`, + }) + .option(`v2`, { + type: `boolean`, + describe: `Install Medusa with the V2 feature flag enabled. WARNING: Medusa V2 is still in development and shouldn't be used in production.`, + default: false }), desc: `Create a new Medusa project.`, handler: handlerP(newStarter),