feat(medusa-cli): added branch option (#7384)

This commit is contained in:
Shahed Nasser
2024-05-21 22:17:01 +03:00
committed by GitHub
parent c4fde7ea5c
commit 1f43290cec
3 changed files with 14 additions and 6 deletions

View File

@@ -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)
}

View File

@@ -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),