feat(create-medusa-app): support admin onboarding experience (#4339)
This commit is contained in:
5
.changeset/dirty-rocks-divide.md
Normal file
5
.changeset/dirty-rocks-divide.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"create-medusa-app": patch
|
||||
---
|
||||
|
||||
feat(create-medusa-app): support admin onboarding experience
|
||||
@@ -34,12 +34,7 @@ type CreateOptions = {
|
||||
boilerplate?: boolean
|
||||
}
|
||||
|
||||
export default async ({
|
||||
repoUrl = "",
|
||||
// TODO remove default value later
|
||||
seed = true,
|
||||
boilerplate,
|
||||
}: CreateOptions) => {
|
||||
export default async ({ repoUrl = "", seed, boilerplate }: CreateOptions) => {
|
||||
track("CREATE_CLI")
|
||||
if (repoUrl) {
|
||||
track("STARTER_SELECTED", { starter: repoUrl })
|
||||
@@ -118,20 +113,19 @@ export default async ({
|
||||
}
|
||||
}
|
||||
|
||||
// TODO enable this later
|
||||
// const { adminEmail } = await inquirer.prompt([
|
||||
// {
|
||||
// type: "input",
|
||||
// name: "adminEmail",
|
||||
// message: "Enter an email for your admin dashboard user",
|
||||
// default: !seed && boilerplate ? "admin@medusa-test.com" : undefined,
|
||||
// validate: (input) => {
|
||||
// return typeof input === "string" && input.length > 0 && isEmail(input)
|
||||
// ? true
|
||||
// : "Please enter a valid email"
|
||||
// },
|
||||
// },
|
||||
// ])
|
||||
const { adminEmail } = await inquirer.prompt([
|
||||
{
|
||||
type: "input",
|
||||
name: "adminEmail",
|
||||
message: "Enter an email for your admin dashboard user",
|
||||
default: !seed && boilerplate ? "admin@medusa-test.com" : undefined,
|
||||
validate: (input) => {
|
||||
return typeof input === "string" && input.length > 0 && isEmail(input)
|
||||
? true
|
||||
: "Please enter a valid email"
|
||||
},
|
||||
},
|
||||
])
|
||||
|
||||
logMessage({
|
||||
message: `${emojify(
|
||||
@@ -214,9 +208,9 @@ export default async ({
|
||||
inviteToken = await prepareProject({
|
||||
directory: projectName,
|
||||
dbConnectionString,
|
||||
// admin: {
|
||||
// email: adminEmail,
|
||||
// },
|
||||
admin: {
|
||||
email: adminEmail,
|
||||
},
|
||||
seed,
|
||||
boilerplate,
|
||||
spinner,
|
||||
@@ -285,13 +279,13 @@ export default async ({
|
||||
}
|
||||
})
|
||||
|
||||
// await waitOn({
|
||||
// resources: ["http://localhost:9000/health"],
|
||||
// }).then(async () =>
|
||||
// open(
|
||||
// inviteToken
|
||||
// ? `http://localhost:7001/invite?token=${inviteToken}&first_run=true`
|
||||
// : "http://localhost:7001"
|
||||
// )
|
||||
// )
|
||||
await waitOn({
|
||||
resources: ["http://localhost:9000/health"],
|
||||
}).then(async () =>
|
||||
open(
|
||||
inviteToken
|
||||
? `http://localhost:7001/invite?token=${inviteToken}&first_run=true`
|
||||
: "http://localhost:7001"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@ type CloneRepoOptions = {
|
||||
abortController?: AbortController
|
||||
}
|
||||
|
||||
const DEFAULT_REPO = "https://github.com/medusajs/medusa-starter-default"
|
||||
const DEFAULT_REPO =
|
||||
"https://github.com/medusajs/medusa-starter-default -b feat/onboarding"
|
||||
|
||||
export default async ({
|
||||
directoryName = "",
|
||||
|
||||
@@ -37,6 +37,14 @@ export default async ({
|
||||
signal: abortController?.signal,
|
||||
}
|
||||
|
||||
const npxOptions = {
|
||||
...execOptions,
|
||||
env: {
|
||||
...process.env,
|
||||
npm_config_yes: "yes",
|
||||
},
|
||||
}
|
||||
|
||||
// initialize the invite token to return
|
||||
let inviteToken: string | undefined = undefined
|
||||
|
||||
@@ -110,8 +118,8 @@ export default async ({
|
||||
await processManager.runProcess({
|
||||
process: async () => {
|
||||
const proc = await promiseExec(
|
||||
"npx -y @medusajs/medusa-cli@latest migrations run",
|
||||
execOptions
|
||||
"npx @medusajs/medusa-cli@latest migrations run",
|
||||
npxOptions
|
||||
)
|
||||
|
||||
// ensure that migrations actually ran in case of an uncaught error
|
||||
@@ -138,8 +146,8 @@ export default async ({
|
||||
await processManager.runProcess({
|
||||
process: async () => {
|
||||
const proc = await promiseExec(
|
||||
`npx -y @medusajs/medusa-cli@latest user -e ${admin.email} --invite`,
|
||||
execOptions
|
||||
`npx @medusajs/medusa-cli@latest user -e ${admin.email} --invite`,
|
||||
npxOptions
|
||||
)
|
||||
// get invite token from stdout
|
||||
const match = proc.stdout.match(/Invite token: (?<token>.+)/)
|
||||
@@ -173,11 +181,11 @@ export default async ({
|
||||
await processManager.runProcess({
|
||||
process: async () => {
|
||||
await promiseExec(
|
||||
`npx -y @medusajs/medusa-cli@latest seed --seed-file=${path.join(
|
||||
`npx @medusajs/medusa-cli@latest seed --seed-file=${path.join(
|
||||
"data",
|
||||
"seed.json"
|
||||
)}`,
|
||||
execOptions
|
||||
npxOptions
|
||||
)
|
||||
},
|
||||
})
|
||||
@@ -196,11 +204,11 @@ export default async ({
|
||||
await processManager.runProcess({
|
||||
process: async () => {
|
||||
await promiseExec(
|
||||
`npx -y @medusajs/medusa-cli@latest seed --seed-file=${path.join(
|
||||
`npx @medusajs/medusa-cli@latest seed --seed-file=${path.join(
|
||||
"data",
|
||||
"seed-onboarding.json"
|
||||
)}`,
|
||||
execOptions
|
||||
npxOptions
|
||||
)
|
||||
},
|
||||
})
|
||||
|
||||
@@ -6,9 +6,14 @@ type StartOptions = {
|
||||
}
|
||||
|
||||
export default ({ directory, abortController }: StartOptions) => {
|
||||
const childProcess = exec(`npx -y @medusajs/medusa-cli develop`, {
|
||||
const childProcess = exec(`npx @medusajs/medusa-cli@latest develop`, {
|
||||
cwd: directory,
|
||||
signal: abortController?.signal,
|
||||
env: {
|
||||
...process.env,
|
||||
OPEN_BROWSER: "false",
|
||||
npm_config_yes: "yes",
|
||||
},
|
||||
})
|
||||
|
||||
childProcess.stdout?.pipe(process.stdout)
|
||||
|
||||
Reference in New Issue
Block a user