From 1f43290cec1768e3c2d985b6dc9eba2d2a9b4c73 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Tue, 21 May 2024 22:17:01 +0300 Subject: [PATCH] feat(medusa-cli): added branch option (#7384) --- .github/workflows/test-cli-with-database.yml | 2 +- packages/cli/medusa-cli/src/commands/new.ts | 14 +++++++++----- packages/cli/medusa-cli/src/create-cli.ts | 4 ++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test-cli-with-database.yml b/.github/workflows/test-cli-with-database.yml index d36f3c3d7b..73b3132150 100644 --- a/.github/workflows/test-cli-with-database.yml +++ b/.github/workflows/test-cli-with-database.yml @@ -52,7 +52,7 @@ jobs: - name: Create Medusa project run: | - medusa new cli-test --skip-db --v2 + medusa new cli-test --skip-db --v2 --branch feat/v2-ci working-directory: .. - name: run medusa dev diff --git a/packages/cli/medusa-cli/src/commands/new.ts b/packages/cli/medusa-cli/src/commands/new.ts index 1f3fe99476..042859fa66 100644 --- a/packages/cli/medusa-cli/src/commands/new.ts +++ b/packages/cli/medusa-cli/src/commands/new.ts @@ -169,7 +169,7 @@ const copy = async (starterPath, rootPath) => { } // Clones starter from URI. -const clone = async (hostInfo, rootPath, v2 = false) => { +const clone = async (hostInfo, rootPath, v2 = false, inputBranch) => { let url // Let people use private repos accessed over SSH. if (hostInfo.getDefaultRepresentation() === `sshurl`) { @@ -179,8 +179,11 @@ const clone = async (hostInfo, rootPath, v2 = false) => { url = hostInfo.https({ noCommittish: true, noGitPlus: true }) } - const branch = v2 ? [`-b`, "feat/v2"] : - hostInfo.committish ? [`-b`, hostInfo.committish] : [] + let branch = (inputBranch || hostInfo.committish ? [`-b`, inputBranch || hostInfo.committish] : []) + + if (v2) { + branch = [`-b`, inputBranch || "feat/v2"] + } const createAct = reporter.activity(`Creating new project from git: ${url}`) @@ -524,7 +527,8 @@ export const newStarter = async (args) => { dbPass, dbPort, dbHost, - v2 + v2, + branch } = args const dbCredentials = removeUndefined({ @@ -600,7 +604,7 @@ medusa new ${rootPath} [url-to-starter] const hostedInfo = hostedGitInfo.fromUrl(starterPath) if (hostedInfo) { - await clone(hostedInfo, rootPath, v2) + await clone(hostedInfo, rootPath, v2, branch) } else { await copy(starterPath, rootPath) } diff --git a/packages/cli/medusa-cli/src/create-cli.ts b/packages/cli/medusa-cli/src/create-cli.ts index 341d1fdcac..8133c57bff 100644 --- a/packages/cli/medusa-cli/src/create-cli.ts +++ b/packages/cli/medusa-cli/src/create-cli.ts @@ -118,6 +118,10 @@ function buildLocalCommands(cli, isLocalProject) { 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, + }) + .option(`branch`, { + type: `string`, + describe: `The branch of the git repository to clone.`, }), desc: `Create a new Medusa project.`, handler: handlerP(newStarter),