mercur-cli 0.1.3 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/backend-setup.js +11 -15
- package/cli/data.js +124 -0
- package/cli/frontend-setup.js +17 -0
- package/cli/full-install.js +7 -1
- package/cli/pull-and-install.js +50 -2
- package/cli/start.js +15 -2
- package/index.js +6 -1
- package/package.json +10 -8
package/cli/backend-setup.js
CHANGED
|
@@ -6,21 +6,14 @@ import ora from "ora";
|
|
|
6
6
|
export async function backendSetup(options) {
|
|
7
7
|
const targetDir = options.directory;
|
|
8
8
|
const spinner = ora("Setting up Mercur backend...").start();
|
|
9
|
-
|
|
10
|
-
await execa("yarn", ["generate:oas"], {
|
|
11
|
-
cwd: path.join(targetDir, "backend/apps/backend"),
|
|
12
|
-
});
|
|
13
|
-
await execa("yarn", ["codegen"], {
|
|
14
|
-
cwd: path.join(targetDir, "backend"),
|
|
15
|
-
});
|
|
16
9
|
const DB_URL = `postgres://${options.db_user}:${options.db_pass}@${options.db_url}:${options.db_port}/${options.db_name}`;
|
|
17
10
|
|
|
18
11
|
await fs.writeFile(
|
|
19
|
-
path.join(targetDir, "backend
|
|
12
|
+
path.join(targetDir, "backend/.env"),
|
|
20
13
|
`STORE_CORS=http://localhost:3000
|
|
21
|
-
ADMIN_CORS=http://localhost:9000
|
|
14
|
+
ADMIN_CORS=http://localhost:9000,http://localhost:9001
|
|
22
15
|
VENDOR_CORS=http://localhost:5173
|
|
23
|
-
AUTH_CORS=http://localhost:9000,http://localhost:5173,http://localhost:3000
|
|
16
|
+
AUTH_CORS=http://localhost:9000,http://localhost:9001,http://localhost:5173,http://localhost:3000
|
|
24
17
|
REDIS_URL=redis://localhost:6379
|
|
25
18
|
JWT_SECRET=supersecret
|
|
26
19
|
COOKIE_SECRET=supersecret
|
|
@@ -34,17 +27,20 @@ STRIPE_CONNECTED_ACCOUNTS_WEBHOOK_SECRET=supersecret
|
|
|
34
27
|
|
|
35
28
|
RESEND_API_KEY=supersecret
|
|
36
29
|
RESEND_FROM_EMAIL=onboarding@resend.dev
|
|
30
|
+
|
|
31
|
+
VITE_TALK_JS_APP_ID=xxx
|
|
32
|
+
VITE_TALK_JS_SECRET_API_KEY=xxx
|
|
37
33
|
`
|
|
38
34
|
);
|
|
39
35
|
|
|
40
36
|
spinner.text = "Setting up database...";
|
|
41
37
|
await execa("npx", ["medusa", "db:create", "--db", options.db_name], {
|
|
42
|
-
cwd: path.join(targetDir, "backend
|
|
38
|
+
cwd: path.join(targetDir, "backend"),
|
|
43
39
|
});
|
|
44
40
|
|
|
45
41
|
spinner.text = "Running migrations...";
|
|
46
|
-
await execa("
|
|
47
|
-
cwd: path.join(targetDir, "backend
|
|
42
|
+
await execa("npx", ["medusa", "db:migrate"], {
|
|
43
|
+
cwd: path.join(targetDir, "backend"),
|
|
48
44
|
});
|
|
49
45
|
|
|
50
46
|
spinner.text = "Seeding data...";
|
|
@@ -53,12 +49,12 @@ RESEND_FROM_EMAIL=onboarding@resend.dev
|
|
|
53
49
|
"npx",
|
|
54
50
|
["medusa", "user", "--email", "admin@mercurjs.com", "--password", "admin"],
|
|
55
51
|
{
|
|
56
|
-
cwd: path.join(targetDir, "backend
|
|
52
|
+
cwd: path.join(targetDir, "backend"),
|
|
57
53
|
}
|
|
58
54
|
);
|
|
59
55
|
|
|
60
56
|
const result = await execa("yarn", ["seed"], {
|
|
61
|
-
cwd: path.join(targetDir, "backend
|
|
57
|
+
cwd: path.join(targetDir, "backend"),
|
|
62
58
|
});
|
|
63
59
|
|
|
64
60
|
const pkstart = result.stdout.indexOf("pk_");
|
package/cli/data.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export const b2cMedusaConfigTemplate = `
|
|
2
|
+
import { defineConfig, loadEnv } from '@medusajs/framework/utils'
|
|
3
|
+
|
|
4
|
+
loadEnv(process.env.NODE_ENV || 'development', process.cwd())
|
|
5
|
+
|
|
6
|
+
module.exports = defineConfig({
|
|
7
|
+
projectConfig: {
|
|
8
|
+
databaseUrl: process.env.DATABASE_URL,
|
|
9
|
+
http: {
|
|
10
|
+
storeCors: process.env.STORE_CORS!,
|
|
11
|
+
adminCors: process.env.ADMIN_CORS!,
|
|
12
|
+
// @ts-expect-error: vendorCors is not a valid config
|
|
13
|
+
vendorCors: process.env.VENDOR_CORS!,
|
|
14
|
+
authCors: process.env.AUTH_CORS!,
|
|
15
|
+
jwtSecret: process.env.JWT_SECRET || 'supersecret',
|
|
16
|
+
cookieSecret: process.env.COOKIE_SECRET || 'supersecret'
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
admin: {
|
|
20
|
+
disable: true,
|
|
21
|
+
},
|
|
22
|
+
plugins: [
|
|
23
|
+
{
|
|
24
|
+
resolve: '@mercurjs/b2c-core',
|
|
25
|
+
options: {}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
resolve: '@mercurjs/commission',
|
|
29
|
+
options: {}
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
resolve: '@mercurjs/algolia',
|
|
33
|
+
options: {
|
|
34
|
+
apiKey: process.env.ALGOLIA_API_KEY,
|
|
35
|
+
appId: process.env.ALGOLIA_APP_ID
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
resolve: '@mercurjs/reviews',
|
|
40
|
+
options: {}
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
resolve: '@mercurjs/requests',
|
|
44
|
+
options: {}
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
resolve: '@mercurjs/resend',
|
|
48
|
+
options: {}
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
modules: [
|
|
52
|
+
{
|
|
53
|
+
resolve: '@medusajs/medusa/payment',
|
|
54
|
+
options: {
|
|
55
|
+
providers: [
|
|
56
|
+
{
|
|
57
|
+
resolve:
|
|
58
|
+
'@mercurjs/payment-stripe-connect/providers/stripe-connect',
|
|
59
|
+
id: 'stripe-connect',
|
|
60
|
+
options: {
|
|
61
|
+
apiKey: process.env.STRIPE_SECRET_API_KEY
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
resolve: '@medusajs/medusa/notification',
|
|
69
|
+
options: {
|
|
70
|
+
providers: [
|
|
71
|
+
{
|
|
72
|
+
resolve: '@mercurjs/resend/providers/resend',
|
|
73
|
+
id: 'resend',
|
|
74
|
+
options: {
|
|
75
|
+
channels: ['email'],
|
|
76
|
+
api_key: process.env.RESEND_API_KEY,
|
|
77
|
+
from: process.env.RESEND_FROM_EMAIL
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
resolve: '@medusajs/medusa/notification-local',
|
|
82
|
+
id: 'local',
|
|
83
|
+
options: {
|
|
84
|
+
channels: ['feed', 'seller_feed']
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
})
|
|
92
|
+
`;
|
|
93
|
+
|
|
94
|
+
export const b2cDependencies = [
|
|
95
|
+
"@mercurjs/b2c-core",
|
|
96
|
+
"@mercurjs/framework",
|
|
97
|
+
"@mercurjs/commission",
|
|
98
|
+
"@mercurjs/payment-stripe-connect",
|
|
99
|
+
"@mercurjs/resend",
|
|
100
|
+
"@mercurjs/requests",
|
|
101
|
+
"@mercurjs/algolia",
|
|
102
|
+
"@mercurjs/reviews",
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
export async function getSeedScript() {
|
|
106
|
+
const seedScript = await fetch(
|
|
107
|
+
"https://raw.githubusercontent.com/mercurjs/mercur/refs/heads/main/apps/backend/src/scripts/seed.ts"
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const seedFunctions = await fetch(
|
|
111
|
+
"https://raw.githubusercontent.com/mercurjs/mercur/refs/heads/main/apps/backend/src/scripts/seed/seed-functions.ts"
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const seedProducts = await fetch(
|
|
115
|
+
"https://raw.githubusercontent.com/mercurjs/mercur/refs/heads/main/apps/backend/src/scripts/seed/seed-products.ts"
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const seeds = {
|
|
119
|
+
seedScript: await seedScript.text(),
|
|
120
|
+
seedFunctions: await seedFunctions.text(),
|
|
121
|
+
seedProducts: await seedProducts.text(),
|
|
122
|
+
};
|
|
123
|
+
return seeds;
|
|
124
|
+
}
|
package/cli/frontend-setup.js
CHANGED
|
@@ -23,6 +23,23 @@ NEXT_PUBLIC_ALGOLIA_SEARCH_KEY=`
|
|
|
23
23
|
spinner.succeed("Storefront ready!");
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
export async function adminPanelSetup(options) {
|
|
27
|
+
const targetDir = options.directory;
|
|
28
|
+
const spinner = ora("Setting up Mercur admin panel...").start();
|
|
29
|
+
|
|
30
|
+
await fs.writeFile(
|
|
31
|
+
path.join(targetDir, "admin-panel/.env"),
|
|
32
|
+
`
|
|
33
|
+
VITE_MEDUSA_BASE='/'
|
|
34
|
+
VITE_MEDUSA_STOREFRONT_URL=http://localhost:3000
|
|
35
|
+
VITE_MEDUSA_BACKEND_URL=http://localhost:9000
|
|
36
|
+
VITE_MEDUSA_B2B_PANEL=true
|
|
37
|
+
`
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
spinner.succeed("Admin panel ready!");
|
|
41
|
+
}
|
|
42
|
+
|
|
26
43
|
export async function vendorPanelSetup(options) {
|
|
27
44
|
const targetDir = options.directory;
|
|
28
45
|
const spinner = ora("Setting up Mercur vendor panel...").start();
|
package/cli/full-install.js
CHANGED
|
@@ -2,7 +2,11 @@ import chalk from "chalk";
|
|
|
2
2
|
import inquirer from "inquirer";
|
|
3
3
|
import { pullAndInstall } from "./pull-and-install.js";
|
|
4
4
|
import { backendSetup } from "./backend-setup.js";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
storefrontSetup,
|
|
7
|
+
vendorPanelSetup,
|
|
8
|
+
adminPanelSetup,
|
|
9
|
+
} from "./frontend-setup.js";
|
|
6
10
|
|
|
7
11
|
export async function fullInstall() {
|
|
8
12
|
const { project_name } = await inquirer.prompt({
|
|
@@ -77,6 +81,8 @@ export async function fullInstall() {
|
|
|
77
81
|
directory: project_name,
|
|
78
82
|
});
|
|
79
83
|
|
|
84
|
+
await adminPanelSetup({ directory: project_name });
|
|
85
|
+
|
|
80
86
|
if (install_storefront) {
|
|
81
87
|
await storefrontSetup({ directory: project_name, publishableKey });
|
|
82
88
|
}
|
package/cli/pull-and-install.js
CHANGED
|
@@ -2,6 +2,11 @@ import { execa } from "execa";
|
|
|
2
2
|
import fs from "fs-extra";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import ora from "ora";
|
|
5
|
+
import {
|
|
6
|
+
b2cDependencies,
|
|
7
|
+
b2cMedusaConfigTemplate,
|
|
8
|
+
getSeedScript,
|
|
9
|
+
} from "./data.js";
|
|
5
10
|
|
|
6
11
|
export async function pullAndInstall(options) {
|
|
7
12
|
const targetDir = path.resolve(process.cwd(), options.directory);
|
|
@@ -12,13 +17,56 @@ export async function pullAndInstall(options) {
|
|
|
12
17
|
spinner.text = "Installing Mercur backend...";
|
|
13
18
|
await execa(
|
|
14
19
|
"git",
|
|
15
|
-
["clone", "https://github.com/
|
|
20
|
+
["clone", "https://github.com/medusajs/medusa-starter-default", "backend"],
|
|
16
21
|
{
|
|
17
22
|
cwd: targetDir,
|
|
18
23
|
}
|
|
19
24
|
);
|
|
25
|
+
|
|
26
|
+
for (const dependency of b2cDependencies) {
|
|
27
|
+
await execa("yarn", ["add", dependency], {
|
|
28
|
+
cwd: path.join(targetDir, "backend"),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
await fs.remove(path.join(targetDir, "backend/medusa-config.ts"));
|
|
33
|
+
|
|
34
|
+
await fs.writeFile(
|
|
35
|
+
path.join(targetDir, "backend/medusa-config.ts"),
|
|
36
|
+
b2cMedusaConfigTemplate
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const seedScript = await getSeedScript();
|
|
40
|
+
|
|
41
|
+
await fs.writeFile(
|
|
42
|
+
path.join(targetDir, "backend/src/scripts/seed.ts"),
|
|
43
|
+
seedScript.seedScript
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
await fs.mkdir(path.join(targetDir, "backend/src/scripts/seed"));
|
|
47
|
+
await fs.writeFile(
|
|
48
|
+
path.join(targetDir, "backend/src/scripts/seed/seed-functions.ts"),
|
|
49
|
+
seedScript.seedFunctions
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
await fs.writeFile(
|
|
53
|
+
path.join(targetDir, "backend/src/scripts/seed/seed-products.ts"),
|
|
54
|
+
seedScript.seedProducts
|
|
55
|
+
);
|
|
56
|
+
|
|
20
57
|
await execa("yarn", ["install"], { cwd: path.join(targetDir, "backend") });
|
|
21
|
-
|
|
58
|
+
|
|
59
|
+
spinner.text = "Installing Mercur admin panel...";
|
|
60
|
+
await execa(
|
|
61
|
+
"git",
|
|
62
|
+
["clone", "https://github.com/mercurjs/admin-panel.git", "admin-panel"],
|
|
63
|
+
{
|
|
64
|
+
cwd: targetDir,
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
await execa("yarn", ["install"], {
|
|
68
|
+
cwd: path.join(targetDir, "admin-panel"),
|
|
69
|
+
});
|
|
22
70
|
|
|
23
71
|
if (options.install_storefront) {
|
|
24
72
|
spinner.text = "Installing Mercur storefront...";
|
package/cli/start.js
CHANGED
|
@@ -10,6 +10,7 @@ export async function startAll() {
|
|
|
10
10
|
const backendExists = fs.existsSync("backend");
|
|
11
11
|
const storefrontExists = fs.existsSync("storefront");
|
|
12
12
|
const vendorExists = fs.existsSync("vendor-panel");
|
|
13
|
+
const adminPanelExists = fs.existsSync("admin-panel");
|
|
13
14
|
|
|
14
15
|
if (!backendExists) {
|
|
15
16
|
spinner.fail("Mercur backend not detected!");
|
|
@@ -20,10 +21,17 @@ export async function startAll() {
|
|
|
20
21
|
|
|
21
22
|
spinner.text = "Starting Mercur backend...";
|
|
22
23
|
const backend = execa("yarn", ["dev"], {
|
|
23
|
-
cwd: path.join(process.cwd(), "backend
|
|
24
|
+
cwd: path.join(process.cwd(), "backend"),
|
|
24
25
|
});
|
|
25
26
|
servicesToRun.push(backend);
|
|
26
27
|
|
|
28
|
+
if (adminPanelExists) {
|
|
29
|
+
const adminPanel = execa("yarn", ["dev", "--port", "9001"], {
|
|
30
|
+
cwd: path.join(process.cwd(), "admin-panel"),
|
|
31
|
+
});
|
|
32
|
+
servicesToRun.push(adminPanel);
|
|
33
|
+
}
|
|
34
|
+
|
|
27
35
|
if (storefrontExists) {
|
|
28
36
|
spinner.text = "Starting Mercur storefront...";
|
|
29
37
|
const storefront = execa("npm", ["run", "dev"], {
|
|
@@ -42,7 +50,12 @@ export async function startAll() {
|
|
|
42
50
|
|
|
43
51
|
spinner.succeed(chalk.green("Development environment started!"));
|
|
44
52
|
console.log(chalk.blue("\nServices:"));
|
|
45
|
-
console.log("-
|
|
53
|
+
console.log("- API: http://localhost:9000");
|
|
54
|
+
|
|
55
|
+
if (adminPanelExists) {
|
|
56
|
+
console.log("- Admin Panel: http://localhost:9001");
|
|
57
|
+
}
|
|
58
|
+
|
|
46
59
|
if (storefrontExists) {
|
|
47
60
|
console.log("- B2C Storefront: http://localhost:3000");
|
|
48
61
|
}
|
package/index.js
CHANGED
|
@@ -15,9 +15,14 @@ console.log(
|
|
|
15
15
|
`)
|
|
16
16
|
);
|
|
17
17
|
|
|
18
|
+
program.option("-v, --version", "Show version").action(() => {
|
|
19
|
+
console.log(chalk.blue(`Mercur CLI v0.1.6`));
|
|
20
|
+
process.exit(0);
|
|
21
|
+
});
|
|
22
|
+
|
|
18
23
|
program
|
|
19
24
|
.command("install")
|
|
20
|
-
.version("1.
|
|
25
|
+
.version("1.1.0")
|
|
21
26
|
.description("Perform full installation of Mercur")
|
|
22
27
|
.action(fullInstall);
|
|
23
28
|
|
package/package.json
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mercur-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "CLI for Mercur - Open Source Marketplace Platform",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"bin": {
|
|
8
|
-
"mercur-cli": "./index.js"
|
|
9
|
-
},
|
|
10
5
|
"author": "MercurJS <hello@mercurjs.com> (https://mercurjs.com)",
|
|
11
6
|
"repository": {
|
|
12
7
|
"type": "git",
|
|
13
8
|
"url": "https://github.com/mercurjs/mercur"
|
|
14
9
|
},
|
|
10
|
+
"license": "MIT",
|
|
15
11
|
"keywords": [
|
|
16
12
|
"mercur",
|
|
17
13
|
"marketplace",
|
|
18
|
-
"medusajs"
|
|
14
|
+
"medusajs",
|
|
15
|
+
"mercurjs"
|
|
19
16
|
],
|
|
17
|
+
"main": "index.js",
|
|
18
|
+
"bin": {
|
|
19
|
+
"mercur-cli": "./index.js"
|
|
20
|
+
},
|
|
20
21
|
"type": "module",
|
|
21
22
|
"scripts": {},
|
|
22
23
|
"dependencies": {
|
|
@@ -33,5 +34,6 @@
|
|
|
33
34
|
"@types/node": "^20.11.0",
|
|
34
35
|
"tsup": "^8.0.2",
|
|
35
36
|
"typescript": "^5.3.3"
|
|
36
|
-
}
|
|
37
|
+
},
|
|
38
|
+
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
|
|
37
39
|
}
|