The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.
TypeScript b2b-marketplacecomposable-commerceecommerceenterpriseheadless-commercemarketplacemedusamedusajsmulti-vendortypescript
refactor(cli): update project creation command with enhanced template… (#841)
Jakub Sieradzkif2c12d31d421
diff --git a/packages/cli/src/commands/create.ts b/packages/cli/src/commands/create.tsindex c3ac92e83..90e26d44b 100644--- a/packages/cli/src/commands/create.ts+++ b/packages/cli/src/commands/create.ts@@ -28,10 +28,19 @@ const DEFAULT_BRANCH = "canary";const MIN_SUPPORTED_NODE_VERSION = 20;const CREATE_TEMPLATES = {- basic: "basic",+ basic: {+ path: "basic",+ description: "Full marketplace starter — sellers, products, orders, admin & vendor panels",+ },// todo: uncomment registry template- // registry: "registry",- plugin: "plugin",+ // registry: {+ // path: "registry",+ // description: "Create and publish your own block registry",+ // },+ plugin: {+ path: "plugin",+ description: "MedusaJS plugin template — for building reusable marketplace extensions",+ },} as const;export const create = new Command()@@ -55,6 +64,7 @@ export const create = new Command().option("--db-port <port>", "PostgreSQL port.", "5432").action(async (name, opts) => {try {+ const createStart = Date.now();validateNodeVersion();showTelemetryNoticeIfNeeded();@@ -92,9 +102,10 @@ export const create = new Command()message: `Which ${highlighter.info("template")} would you like to use?`,- choices: Object.entries(CREATE_TEMPLATES).map(([key, value]) => ({- title: value,+ choices: Object.entries(CREATE_TEMPLATES).map(([key, tmpl]) => ({+ title: key,value: key,+ description: tmpl.description,})),});@@ -224,7 +235,14 @@ export const create = new Command()cwd: projectDir,});- spinner("Mercur project successfully created!").succeed();+ const totalDuration = ((Date.now() - createStart) / 1000).toFixed(1);+ spinner(`Mercur project successfully created! (${totalDuration}s)`).succeed();++ const isNewDb = dbResult?.success && !dbResult.alreadyExists;++ if (isNewDb) {+ logger.log(sellerCredentials());+ }if (dbResult?.success) {spinner("Starting development server...").info();@@ -244,6 +262,9 @@ export const create = new Command()const printRestartHint = () => {logger.break();+ if (isNewDb) {+ logger.log(sellerCredentials());+ }logger.log(kleur.bgGreen(kleur.black(" Project stopped. To start again: ")));logger.log(successMessage(projectDir, packageManager));logger.log(feedbackOutro());@@ -263,8 +284,14 @@ export const create = new Command()resources: ["http://localhost:9000/health"],timeout: 60000,}).then(async () => {+ logger.break();+ logger.log(serverUrls());+ if (isNewDb) {+ logger.log(sellerCredentials());+ }try {await open(inviteUrl);+ spinner("Admin panel opened in your browser.").succeed();} catch {spinner("Open this URL in your browser to create your admin account:").info();logger.log(highlighter.info(inviteUrl));@@ -291,6 +318,22 @@ async function createOrFindProjectDir(projectDir: string): Promise<void> {const pathExists = await fs.pathExists(projectDir);if (!pathExists) {await fs.mkdir(projectDir);+ return;+ }++ const files = await fs.readdir(projectDir);+ const nonHidden = files.filter((f) => !f.startsWith("."));+ if (nonHidden.length > 0) {+ const { proceed } = await prompts({+ type: "confirm",+ name: "proceed",+ message: `Directory ${highlighter.info(path.basename(projectDir))} already exists and contains ${nonHidden.length} file(s). Continue and overwrite?`,+ initial: false,+ });++ if (!proceed) {+ process.exit(0);+ }}}@@ -302,7 +345,7 @@ async function downloadTemplate({template: keyof typeof CREATE_TEMPLATES;}) {const url = `https://codeload.github.com/mercurjs/mercur/tar.gz/${DEFAULT_BRANCH}`;- const templatePath = CREATE_TEMPLATES[template];+ const templatePath = CREATE_TEMPLATES[template].path;const filter = `mercur-${DEFAULT_BRANCH.replace(/^v/, "").replaceAll("/", "-")}/templates/${templatePath}/`;await pipeline(@@ -383,6 +426,27 @@ ${header("Documentation:")}`;}+function sellerCredentials(): string {+ return `+${kleur.bgCyan(kleur.black(" Demo Seller Credentials "))}++ Email: ${highlighter.info("[email protected]")}+ Password: ${highlighter.info("supersecret")}+ Login at: ${highlighter.info("http://localhost:9000/seller")}+`;+}++function serverUrls(): string {+ const header = (message: string) => kleur.bold(message);+ return `+${header("Your marketplace is running:")}++ API: ${highlighter.info("http://localhost:9000")}+ Admin Panel: ${highlighter.info("http://localhost:9000/dashboard")}+ Vendor Panel: ${highlighter.info("http://localhost:9000/seller")}+`;+}+function feedbackOutro(): string {return `${kleur.bgCyan(kleur.black(" Have feedback? "))} Visit us on ${createTerminalLink("GitHub", "https://github.com/mercurjs/mercur")}.\n${kleur.bgMagenta(kleur.black(" Join the community! "))} Chat with us on ${createTerminalLink("Discord", "https://discord.gg/hnZBzc4NJU")}.`;}diff --git a/packages/cli/src/registry/constants.ts b/packages/cli/src/registry/constants.tsindex fb7de18e3..d5f58a054 100644--- a/packages/cli/src/registry/constants.ts+++ b/packages/cli/src/registry/constants.ts@@ -9,7 +9,7 @@ export const REGISTRY_ITEM_SCHEMA_URL = "https://registry.mercurjs.com/registry-export const REGISTRY_URL =process.env.REGISTRY_URL ??// todo: change to main branch- "https://raw.githubusercontent.com/mercurjs/mercur/new/packages/registry/r";+ "https://raw.githubusercontent.com/mercurjs/mercur/canary/packages/registry/r";// Built-in registries that are always available and cannot be overriddenexport const BUILTIN_REGISTRIES: z.infer<typeof registryConfigSchema> = {diff --git a/packages/cli/src/utils/create-db.ts b/packages/cli/src/utils/create-db.tsindex db4003119..6b30e15ba 100644--- a/packages/cli/src/utils/create-db.ts+++ b/packages/cli/src/utils/create-db.ts@@ -225,7 +225,6 @@ async function getDbClient({connectionTimeoutMillis: 5000,});await client.connect();- spinnerRef?.stop();return {client,dbConnectionString: formatConnectionString({@@ -362,7 +361,7 @@ async function seedDatabase({ projectDir, spinner: parentSpinner }: DbSetupArgs)? ["bun", "run", "seed"]: ["npm", "run", "seed"];- seedSpinner.text = "Seeding database...";+ seedSpinner.text = "Seeding database with demo data...";await execa(seedCmd[0], seedCmd.slice(1), { cwd: apiDir });if (!parentSpinner) {