feat(create-medusa-app): Added --v2 option (#6729)
## What Added a `--v2` option to the `create-medusa-app` command that clones the [feat/v2](https://github.com/medusajs/medusa-starter-default/pull/150) branch of the starter default and makes minor changes to the setup process. ## Why This option is supposed to make it easier to test out internally a Medusa setup with all the commerce modules. The starter's branch installs and configures the modules + the V2 feature flag. ## Testing To test it out, run the snapshot with the `--v2` option. ## Notes - I couldn't install the new admin dashboard in the starter branch as it's not on NPM yet (at the time of writing this), so at the moment, this opens the current admin dashboard instead. - When trying to create an invite using the CLI tool I get the error `Unable to resolve inviteService`. Not sure if we should also make changes to the CLI tool to allow creating an invite when V2 is enabled (I know now invites are creating within the User Module, so maybe when the V2 feature flag is enabled that should be resolved instead), but for now I just disabled running the create invite command as this is mainly for internal testing. Let me know what the suggested approach is here.
This commit is contained in:
5
.changeset/big-kings-trade.md
Normal file
5
.changeset/big-kings-trade.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"create-medusa-app": patch
|
||||
---
|
||||
|
||||
feat(create-medusa-app): Add `--v2` option
|
||||
@@ -42,6 +42,7 @@ export type CreateOptions = {
|
||||
migrations?: boolean
|
||||
directoryPath?: string
|
||||
withNextjsStarter?: boolean
|
||||
v2?: boolean
|
||||
}
|
||||
|
||||
export default async ({
|
||||
@@ -54,6 +55,7 @@ export default async ({
|
||||
migrations,
|
||||
directoryPath,
|
||||
withNextjsStarter = false,
|
||||
v2 = false,
|
||||
}: CreateOptions) => {
|
||||
track("CREATE_CLI_CMA")
|
||||
|
||||
@@ -134,6 +136,7 @@ export default async ({
|
||||
repoUrl,
|
||||
abortController,
|
||||
spinner,
|
||||
v2,
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
@@ -184,6 +187,7 @@ export default async ({
|
||||
onboardingType: installNextjs ? "nextjs" : "default",
|
||||
nextjsDirectory,
|
||||
client,
|
||||
v2,
|
||||
})
|
||||
} catch (e: any) {
|
||||
if (isAbortError(e)) {
|
||||
|
||||
@@ -38,6 +38,11 @@ program
|
||||
"Install the Next.js starter along with the Medusa backend",
|
||||
false
|
||||
)
|
||||
.option(
|
||||
"--v2",
|
||||
"Install Medusa with the V2 feature flag enabled. WARNING: Medusa V2 is still in development and shouldn't be used in production.",
|
||||
false
|
||||
)
|
||||
.parse()
|
||||
|
||||
void create(program.opts())
|
||||
|
||||
@@ -9,18 +9,26 @@ type CloneRepoOptions = {
|
||||
directoryName?: string
|
||||
repoUrl?: string
|
||||
abortController?: AbortController
|
||||
v2?: boolean
|
||||
}
|
||||
|
||||
const DEFAULT_REPO = "https://github.com/medusajs/medusa-starter-default"
|
||||
const V2_BRANCH = "feat/v2"
|
||||
|
||||
export default async function cloneRepo({
|
||||
directoryName = "",
|
||||
repoUrl,
|
||||
abortController,
|
||||
v2 = false,
|
||||
}: CloneRepoOptions) {
|
||||
await promiseExec(`git clone ${repoUrl || DEFAULT_REPO} ${directoryName}`, {
|
||||
signal: abortController?.signal,
|
||||
})
|
||||
await promiseExec(
|
||||
`git clone ${repoUrl || DEFAULT_REPO}${
|
||||
v2 ? ` -b ${V2_BRANCH}` : ""
|
||||
} ${directoryName}`,
|
||||
{
|
||||
signal: abortController?.signal,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export async function runCloneRepo({
|
||||
@@ -28,17 +36,20 @@ export async function runCloneRepo({
|
||||
repoUrl,
|
||||
abortController,
|
||||
spinner,
|
||||
v2 = false,
|
||||
}: {
|
||||
projectName: string
|
||||
repoUrl: string
|
||||
abortController: AbortController
|
||||
spinner: Ora
|
||||
v2?: boolean
|
||||
}) {
|
||||
try {
|
||||
await cloneRepo({
|
||||
directoryName: projectName,
|
||||
repoUrl,
|
||||
abortController,
|
||||
v2,
|
||||
})
|
||||
|
||||
deleteGitDirectory(projectName)
|
||||
|
||||
@@ -25,6 +25,7 @@ type PrepareOptions = {
|
||||
onboardingType?: "default" | "nextjs"
|
||||
nextjsDirectory?: string
|
||||
client: Client | null
|
||||
v2?: boolean
|
||||
}
|
||||
|
||||
export default async ({
|
||||
@@ -41,6 +42,7 @@ export default async ({
|
||||
onboardingType = "default",
|
||||
nextjsDirectory = "",
|
||||
client,
|
||||
v2 = false,
|
||||
}: PrepareOptions) => {
|
||||
// initialize execution options
|
||||
const execOptions = {
|
||||
@@ -69,6 +71,9 @@ export default async ({
|
||||
|
||||
if (!skipDb) {
|
||||
let env = `DATABASE_TYPE=postgres${EOL}DATABASE_URL=${dbConnectionString}${EOL}MEDUSA_ADMIN_ONBOARDING_TYPE=${onboardingType}${EOL}STORE_CORS=http://localhost:8000,http://localhost:7001`
|
||||
if (v2) {
|
||||
env += `${EOL}POSTGRES_URL=${dbConnectionString}`
|
||||
}
|
||||
if (nextjsDirectory) {
|
||||
env += `${EOL}MEDUSA_ADMIN_ONBOARDING_NEXTJS_DIRECTORY=${nextjsDirectory}`
|
||||
}
|
||||
@@ -153,7 +158,9 @@ export default async ({
|
||||
// to ensure that migrations ran
|
||||
let errorOccurred = false
|
||||
try {
|
||||
const migrations = await client.query(`SELECT * FROM "migrations"`)
|
||||
const migrations = await client.query(
|
||||
`SELECT * FROM "${v2 ? "mikro_orm_migrations" : "migrations"}"`
|
||||
)
|
||||
errorOccurred = migrations.rowCount == 0
|
||||
} catch (e) {
|
||||
// avoid error thrown if the migrations table
|
||||
@@ -179,7 +186,7 @@ export default async ({
|
||||
})
|
||||
}
|
||||
|
||||
if (admin && !skipDb && migrations) {
|
||||
if (admin && !skipDb && migrations && !v2) {
|
||||
// create admin user
|
||||
factBoxOptions.interval = displayFactBox({
|
||||
...factBoxOptions,
|
||||
|
||||
Reference in New Issue
Block a user