feat(medusa-cli): added v2 flag (#7211)

This commit is contained in:
Shahed Nasser
2024-05-03 08:43:54 +02:00
committed by GitHub
parent 0140fd63ab
commit 5bc780a646
3 changed files with 21 additions and 8 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/medusa-cli": patch
---
feat(medusa-cli): added v2 flag
+11 -8
View File
@@ -169,7 +169,7 @@ const copy = async (starterPath, rootPath) => {
} }
// Clones starter from URI. // Clones starter from URI.
const clone = async (hostInfo, rootPath) => { const clone = async (hostInfo, rootPath, v2 = false) => {
let url let url
// Let people use private repos accessed over SSH. // Let people use private repos accessed over SSH.
if (hostInfo.getDefaultRepresentation() === `sshurl`) { if (hostInfo.getDefaultRepresentation() === `sshurl`) {
@@ -179,7 +179,8 @@ const clone = async (hostInfo, rootPath) => {
url = hostInfo.https({ noCommittish: true, noGitPlus: true }) 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}`) const createAct = reporter.activity(`Creating new project from git: ${url}`)
@@ -228,7 +229,7 @@ const getMedusaConfig = (rootPath) => {
return {} return {}
} }
const getPaths = async (starterPath, rootPath) => { const getPaths = async (starterPath, rootPath, v2 = false) => {
let selectedOtherStarter = false let selectedOtherStarter = false
// if no args are passed, prompt user for path and starter // 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?`, message: `What is your project called?`,
initial: `my-medusa-store`, initial: `my-medusa-store`,
}, },
{ !v2 && {
type: `select`, type: `select`,
name: `starter`, name: `starter`,
message: `What starter would you like to use?`, message: `What starter would you like to use?`,
@@ -253,14 +254,14 @@ const getPaths = async (starterPath, rootPath) => {
]) ])
// exit gracefully if responses aren't provided // exit gracefully if responses aren't provided
if (!response.starter || !response.path.trim()) { if ((!v2 && !response.starter) || !response.path.trim()) {
throw new Error( throw new Error(
`Please mention both starter package and project name along with path(if its not in the root)` `Please mention both starter package and project name along with path(if its not in the root)`
) )
} }
selectedOtherStarter = response.starter === `different` selectedOtherStarter = response.starter === `different`
starterPath = `medusajs/${response.starter}` starterPath = `medusajs/${v2 ? "medusa-starter-default" : response.starter}`
rootPath = response.path rootPath = response.path
} }
@@ -523,6 +524,7 @@ export const newStarter = async (args) => {
dbPass, dbPass,
dbPort, dbPort,
dbHost, dbHost,
v2
} = args } = args
const dbCredentials = removeUndefined({ const dbCredentials = removeUndefined({
@@ -535,7 +537,8 @@ export const newStarter = async (args) => {
const { starterPath, rootPath, selectedOtherStarter } = await getPaths( const { starterPath, rootPath, selectedOtherStarter } = await getPaths(
starter, starter,
root root,
v2
) )
const urlObject = url.parse(rootPath) const urlObject = url.parse(rootPath)
@@ -597,7 +600,7 @@ medusa new ${rootPath} [url-to-starter]
const hostedInfo = hostedGitInfo.fromUrl(starterPath) const hostedInfo = hostedGitInfo.fromUrl(starterPath)
if (hostedInfo) { if (hostedInfo) {
await clone(hostedInfo, rootPath) await clone(hostedInfo, rootPath, v2)
} else { } else {
await copy(starterPath, rootPath) await copy(starterPath, rootPath)
} }
+5
View File
@@ -113,6 +113,11 @@ function buildLocalCommands(cli, isLocalProject) {
.option(`db-host`, { .option(`db-host`, {
type: `string`, type: `string`,
describe: `The database host to use for database setup and migrations.`, 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.`, desc: `Create a new Medusa project.`,
handler: handlerP(newStarter), handler: handlerP(newStarter),