diff --git a/.changeset/warm-olives-compare.md b/.changeset/warm-olives-compare.md new file mode 100644 index 0000000000..d0ccdc128d --- /dev/null +++ b/.changeset/warm-olives-compare.md @@ -0,0 +1,5 @@ +--- +"create-medusa-app": patch +--- + +fix(create-medusa-app): remove seed command from create-medusa-app and improve success message diff --git a/packages/create-medusa-app/src/index.ts b/packages/create-medusa-app/src/index.ts index 1af6e9826f..5e3b4daccd 100644 --- a/packages/create-medusa-app/src/index.ts +++ b/packages/create-medusa-app/src/index.ts @@ -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 => { 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 => { await newStarter({ starter, root: path.join(projectRoot, `backend`), - seed: !noSeed, verbose: progOptions.verbose, }) @@ -118,18 +110,27 @@ export const run = async (): Promise => { } 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 `) } } diff --git a/packages/create-medusa-app/src/new-starter.js b/packages/create-medusa-app/src/new-starter.js index 3186c7a51b..8662a88eb8 100644 --- a/packages/create-medusa-app/src/new-starter.js +++ b/packages/create-medusa-app/src/new-starter.js @@ -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) }