fix(create-medusa-app): remove seed command from create-medusa-app and improve success message (#4247)

## What

- Removed the `seed` process and the `--no-seed` option from the `create-medusa-app` command
- Improved the success message to include details about creating the database and running migrations before starting the backend.

## Why

As of removing support for SQLite, the `seed` command does not work most of the time on installation since there's no database configured and the default one isn't created by the user yet. This leads to an error message showing during the installation which leads the user into thinking the setup went wrong.

Also, the steps after the installation is done successfully don't include anything related to the database, which means that when the user starts the backend they'll see errors.
This commit is contained in:
Shahed Nasser
2023-06-05 19:30:42 +03:00
committed by GitHub
parent 216faf0369
commit 4b5b7b5148
3 changed files with 22 additions and 93 deletions

View File

@@ -0,0 +1,5 @@
---
"create-medusa-app": patch
---
fix(create-medusa-app): remove seed command from create-medusa-app and improve success message

View File

@@ -47,10 +47,6 @@ const program = new Commander.Command(pkg.name)
`-s --starter-url`,
`A GitHub URL to a repository that contains a Medusa starter project to bootstrap from`
)
.option(
`--no-seed`,
`If run with the no-seed flag the script will skip seeding the database upon setup`
)
.option(`-v --verbose`, `Show all installation output`)
.parse(process.argv)
@@ -92,9 +88,6 @@ export const run = async (): Promise<void> => {
const progOptions = program.opts()
const noSeed = progOptions.noSeed
track("SEED_SELECTED", { seed: !noSeed })
const { storefront } = (await prompt(questions.storefront)) as {
storefront: string
}
@@ -103,7 +96,6 @@ export const run = async (): Promise<void> => {
await newStarter({
starter,
root: path.join(projectRoot, `backend`),
seed: !noSeed,
verbose: progOptions.verbose,
})
@@ -118,18 +110,27 @@ export const run = async (): Promise<void> => {
}
console.log(`
Your project is ready 🚀. The available commands are:
Your project is ready 🚀. To start your Medusa project:
Medusa API
cd ${projectRoot}/backend
yarn start
Medusa Backend
1. Change to the backend directory: cd ${projectRoot}/backend
2. Create a PostgreSQL database and make sure your PostgreSQL server is running.
3. Add the following environment variable to the \`.env\` file:
DATABASE_URL=postgres://localhost/medusa-store # This is the default URL, change it to your own database URL
4. Run migrations:
npx @medusajs/medusa-cli@latest migrations run
5. Optionally seed database with dummy data:
npx @medusajs/medusa-cli@latest seed -f ./data/seed.json
6. Start backend:
npx @medusajs/medusa-cli@latest develop
`)
if (hasStorefront) {
console.log(`
Storefront
cd ${projectRoot}/storefront
yarn dev
1. Run the backend as explained above.
2. Change to the storefront directory: cd ${projectRoot}/storefront
3. Run storefront: yarn dev
`)
}
}

View File

@@ -30,14 +30,6 @@ export const getPackageManager = (npmConfigUserAgent) => {
return `npm`
}
const removeUndefined = (obj) => {
return Object.fromEntries(
Object.entries(obj)
.filter(([_, v]) => v != null)
.map(([k, v]) => [k, v === Object(v) ? removeEmpty(v) : v])
)
}
const spawnWithArgs = (file, args, options) =>
execa(file, args, { stdio: "ignore", preferLocal: false, ...options })
@@ -115,8 +107,6 @@ const install = async (rootPath, verbose) => {
process.chdir(rootPath)
const npmConfigUserAgent = process.env.npm_config_user_agent
try {
if (getPackageManager() === `yarn` && checkForYarn()) {
await fs.remove(`package-lock.json`)
@@ -218,21 +208,6 @@ const clone = async (hostInfo, rootPath, keepGit, verbose = false) => {
if (!isGit) await createInitialGitCommit(rootPath, url)
}
const getMedusaConfig = (rootPath) => {
try {
const configPath = sysPath.join(rootPath, "medusa-config.js")
if (existsSync(configPath)) {
const resolved = sysPath.resolve(configPath)
const configModule = require(resolved)
return configModule
}
throw Error()
} catch (err) {
return null
}
return {}
}
const getPaths = async (starterPath, rootPath) => {
let selectedOtherStarter = false
@@ -243,14 +218,6 @@ const getPaths = async (starterPath, rootPath) => {
return { starterPath, rootPath, selectedOtherStarter }
}
const successMessage = (path) => {
reporter.info(`Your new Medusa project is ready for you! To start developing run:
cd ${path}
medusa develop
`)
}
const setupEnvVars = async (rootPath) => {
const templatePath = sysPath.join(rootPath, ".env.template")
const destination = sysPath.join(rootPath, ".env")
@@ -259,51 +226,11 @@ const setupEnvVars = async (rootPath) => {
}
}
const attemptSeed = async (rootPath) => {
const stop = spin("Seeding database")
const pkgPath = sysPath.resolve(rootPath, "package.json")
if (existsSync(pkgPath)) {
const pkg = require(pkgPath)
if (pkg.scripts && pkg.scripts.seed) {
await setupEnvVars(rootPath)
const proc = execa(getPackageManager(), [`run`, `seed`], {
cwd: rootPath,
})
// Useful for development
proc.stdout.pipe(process.stdout)
await proc
.then(() => {
stop()
console.log()
reporter.success("Seed completed")
})
.catch((err) => {
stop()
console.log()
reporter.error("Failed to complete seed; skipping")
console.error(err)
})
} else {
stop()
console.log()
reporter.error("Starter doesn't provide a seed command; skipping.")
}
} else {
stop()
console.log()
reporter.error("Could not find package.json")
}
}
/**
* Main function that clones or copies the starter.
*/
export const newStarter = async (args) => {
const { starter, root, verbose, seed, keepGit } = args
const { starter, root, verbose, keepGit } = args
const { starterPath, rootPath, selectedOtherStarter } = await getPaths(
starter,
@@ -362,9 +289,5 @@ export const newStarter = async (args) => {
await copy(starterPath, rootPath, verbose)
}
const medusaConfig = getMedusaConfig(rootPath)
if (medusaConfig && seed) {
await attemptSeed(rootPath)
}
await setupEnvVars(rootPath)
}