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