@hszrdm/create-commerce 0.0.0-stage → 1.0.0
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/README.md +50 -2
- package/bin/create-commerce.mjs +51 -0
- package/package.json +23 -4
- package/src/cli.mjs +585 -0
- package/templates/backend/.env.example +113 -0
- package/templates/backend/README.md +7 -0
- package/templates/backend/instrumentation.ts +24 -0
- package/templates/backend/medusa-config.ts +11 -0
- package/templates/backend/package.json +42 -0
- package/templates/backend/scripts/prepare-project.mjs +49 -0
- package/templates/backend/src/project/README.md +13 -0
- package/templates/backend/src/project/api/.gitkeep +0 -0
- package/templates/backend/src/project/jobs/.gitkeep +0 -0
- package/templates/backend/src/project/modules/.gitkeep +0 -0
- package/templates/backend/src/project/subscribers/.gitkeep +0 -0
- package/templates/backend/src/project/workflows/.gitkeep +0 -0
- package/templates/backend/src/scripts/core-init.ts +21 -0
- package/templates/backend/src/scripts/create-storefront-key.ts +12 -0
- package/templates/backend/src/scripts/verify-bootstrap.ts +1 -0
- package/templates/backend/tsconfig.json +33 -0
- package/templates/storefront/.env.example +5 -0
- package/templates/storefront/README.md +108 -0
- package/templates/storefront/next-env.d.ts +4 -0
- package/templates/storefront/next.config.ts +8 -0
- package/templates/storefront/package.json +24 -0
- package/templates/storefront/src/app/[countryCode]/categories/[handle]/page.tsx +38 -0
- package/templates/storefront/src/app/[countryCode]/products/[handle]/page.tsx +51 -0
- package/templates/storefront/src/app/[countryCode]/products/page.tsx +47 -0
- package/templates/storefront/src/app/account/orders/[id]/page.tsx +8 -0
- package/templates/storefront/src/app/account/page.tsx +11 -0
- package/templates/storefront/src/app/cart/page.tsx +12 -0
- package/templates/storefront/src/app/checkout/page.tsx +15 -0
- package/templates/storefront/src/app/checkout/success/page.tsx +72 -0
- package/templates/storefront/src/app/error.tsx +14 -0
- package/templates/storefront/src/app/globals.css +250 -0
- package/templates/storefront/src/app/layout.tsx +59 -0
- package/templates/storefront/src/app/legal/page.tsx +26 -0
- package/templates/storefront/src/app/loading.tsx +3 -0
- package/templates/storefront/src/app/not-found.tsx +14 -0
- package/templates/storefront/src/app/page.tsx +47 -0
- package/templates/storefront/src/app/reset-password/page.tsx +14 -0
- package/templates/storefront/src/app/robots.txt/route.ts +13 -0
- package/templates/storefront/src/app/sitemap.xml/route.ts +13 -0
- package/templates/storefront/src/components/account-dashboard.tsx +325 -0
- package/templates/storefront/src/components/add-to-cart.tsx +71 -0
- package/templates/storefront/src/components/analytics.tsx +90 -0
- package/templates/storefront/src/components/cart-provider.tsx +236 -0
- package/templates/storefront/src/components/cart-view.tsx +135 -0
- package/templates/storefront/src/components/checkout-flow.tsx +534 -0
- package/templates/storefront/src/components/consent-banner.tsx +131 -0
- package/templates/storefront/src/components/order-detail.tsx +273 -0
- package/templates/storefront/src/components/product-card.tsx +38 -0
- package/templates/storefront/src/components/product-view-tracker.tsx +37 -0
- package/templates/storefront/src/components/reset-password-form.tsx +65 -0
- package/templates/storefront/src/components/storefront-header.tsx +42 -0
- package/templates/storefront/src/components/stripe-payment.tsx +90 -0
- package/templates/storefront/src/lib/core/account.ts +170 -0
- package/templates/storefront/src/lib/core/after-sales.ts +50 -0
- package/templates/storefront/src/lib/core/catalog.ts +56 -0
- package/templates/storefront/src/lib/core/checkout.ts +330 -0
- package/templates/storefront/src/lib/core/client.ts +107 -0
- package/templates/storefront/src/lib/core/commerce.ts +148 -0
- package/templates/storefront/src/lib/core/consent.ts +111 -0
- package/templates/storefront/src/lib/core/legal.ts +33 -0
- package/templates/storefront/src/lib/core/seo.ts +88 -0
- package/templates/storefront/src/lib/core/tracking.ts +584 -0
- package/templates/storefront/src/lib/core/types.ts +123 -0
- package/templates/storefront/tsconfig.json +23 -0
package/src/cli.mjs
ADDED
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
import { randomBytes, createHash } from "node:crypto"
|
|
2
|
+
import { execFileSync } from "node:child_process"
|
|
3
|
+
import {
|
|
4
|
+
cpSync,
|
|
5
|
+
existsSync,
|
|
6
|
+
mkdirSync,
|
|
7
|
+
readFileSync,
|
|
8
|
+
rmSync,
|
|
9
|
+
writeFileSync,
|
|
10
|
+
} from "node:fs"
|
|
11
|
+
import { dirname, join, resolve } from "node:path"
|
|
12
|
+
import { fileURLToPath } from "node:url"
|
|
13
|
+
import { createInterface } from "node:readline/promises"
|
|
14
|
+
import { stdin as input, stdout as output } from "node:process"
|
|
15
|
+
|
|
16
|
+
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..")
|
|
17
|
+
|
|
18
|
+
export async function main(argv = process.argv.slice(2)) {
|
|
19
|
+
const parsed = parseArgs(argv)
|
|
20
|
+
if (parsed.flags.help || parsed.flags.h) {
|
|
21
|
+
printHelp()
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const projectName = normalizeSlug(parsed.positionals[0] || parsed.flags.project || "")
|
|
26
|
+
if (!projectName) throw new Error("Add meg a projekt nevét: npx @hszrdm/create-commerce <project-name>")
|
|
27
|
+
|
|
28
|
+
const destination = resolve(parsed.flags.dir || projectName)
|
|
29
|
+
const force = bool(parsed.flags.force)
|
|
30
|
+
if (existsSync(destination)) {
|
|
31
|
+
if (!force) throw new Error(`A célkönyvtár már létezik: ${destination}. Tudatos felülíráshoz: --force`)
|
|
32
|
+
rmSync(destination, { recursive: true, force: true })
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const settings = await collectSettings(projectName, parsed.flags)
|
|
36
|
+
const templates = resolveTemplates()
|
|
37
|
+
const skipDocker = bool(parsed.flags["skip-docker"])
|
|
38
|
+
const skipBootstrap = bool(parsed.flags["skip-bootstrap"])
|
|
39
|
+
|
|
40
|
+
console.log(`\nHSZRDM Commerce projekt létrehozása: ${settings.storeName}`)
|
|
41
|
+
console.log(`Cél: ${destination}\n`)
|
|
42
|
+
|
|
43
|
+
mkdirSync(destination, { recursive: true })
|
|
44
|
+
cpSync(templates.backend, join(destination, "backend"), { recursive: true, dereference: false })
|
|
45
|
+
cpSync(templates.storefront, join(destination, "storefront"), { recursive: true, dereference: false })
|
|
46
|
+
|
|
47
|
+
configureProject(destination, settings)
|
|
48
|
+
configureDocker(destination, settings)
|
|
49
|
+
configureBackend(destination, settings)
|
|
50
|
+
configureStorefront(destination, settings)
|
|
51
|
+
writeMetadata(destination, settings)
|
|
52
|
+
|
|
53
|
+
if (!bool(parsed.flags["skip-install"])) {
|
|
54
|
+
run("npm", ["install"], destination)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (settings.infrastructureMode === "external") {
|
|
58
|
+
console.log("\nKülső PostgreSQL + Redis használata; Docker nem szükséges.")
|
|
59
|
+
} else if (!skipDocker) {
|
|
60
|
+
ensureDockerAvailable()
|
|
61
|
+
run("docker", ["compose", "--env-file", ".env.docker", "up", "-d", "--wait"], destination)
|
|
62
|
+
} else if (!skipBootstrap) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
"A bootstraphoz PostgreSQL és Redis szükséges. Add meg együtt a --database-url és --redis-url értékeket, vagy engedélyezd a Docker fallbacket.",
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!skipBootstrap) {
|
|
69
|
+
run("npm", ["run", "db:migrate"], destination)
|
|
70
|
+
run("npm", [
|
|
71
|
+
"run",
|
|
72
|
+
"core:init",
|
|
73
|
+
"--",
|
|
74
|
+
"yes",
|
|
75
|
+
`store-name=${settings.storeName}`,
|
|
76
|
+
`currency=${settings.currency}`,
|
|
77
|
+
`country=${settings.country}`,
|
|
78
|
+
`locale=${settings.locale}`,
|
|
79
|
+
], destination)
|
|
80
|
+
|
|
81
|
+
const keyOutput = runCapture("npm", [
|
|
82
|
+
"run",
|
|
83
|
+
"storefront:key",
|
|
84
|
+
"--",
|
|
85
|
+
`title=${settings.storeName} Storefront`,
|
|
86
|
+
], destination)
|
|
87
|
+
const publishableKey = captureMarker(keyOutput, "HSZRDM_PUBLISHABLE_KEY")
|
|
88
|
+
if (!publishableKey) throw new Error("A publishable API key létrejöttét nem sikerült visszaellenőrizni.")
|
|
89
|
+
updateStorefrontKey(destination, publishableKey)
|
|
90
|
+
|
|
91
|
+
createAdminUser(destination, settings)
|
|
92
|
+
run("npm", ["run", "bootstrap:assert"], destination)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!bool(parsed.flags["skip-verify"])) {
|
|
96
|
+
run("npm", ["run", "verify"], destination)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (!bool(parsed.flags["skip-git"])) {
|
|
100
|
+
initializeGit(destination)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
console.log("\n✅ HSZRDM Commerce projekt elkészült.")
|
|
104
|
+
console.log(` ${destination}`)
|
|
105
|
+
console.log(` Backend: ${settings.backendUrl}`)
|
|
106
|
+
console.log(` Storefront: ${settings.storefrontUrl}`)
|
|
107
|
+
console.log(` Admin: ${settings.adminEmail}`)
|
|
108
|
+
if (settings.generatedAdminPassword) {
|
|
109
|
+
console.log(`\n⚠️ Generált admin jelszó – most mentsd el, metadata fájlba nem került:\n ${settings.adminPassword}`)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function collectSettings(projectName, flags) {
|
|
114
|
+
const interactive = process.stdin.isTTY && !bool(flags["non-interactive"])
|
|
115
|
+
const rl = interactive ? createInterface({ input, output }) : null
|
|
116
|
+
try {
|
|
117
|
+
const storeName = clean(flags.name || titleFromSlug(projectName))
|
|
118
|
+
const slug = normalizeSlug(flags.slug || projectName)
|
|
119
|
+
const locale = clean(flags.locale || "hu-HU")
|
|
120
|
+
const country = normalizeCountry(flags.country || "HU")
|
|
121
|
+
const currency = normalizeCurrency(flags.currency || "HUF")
|
|
122
|
+
const backendUrl = normalizeUrl(flags["backend-url"] || "http://localhost:9000")
|
|
123
|
+
const storefrontUrl = normalizeUrl(flags["storefront-url"] || "http://localhost:3000")
|
|
124
|
+
const emailDomain = clean(flags["email-domain"] || safeHostname(storefrontUrl) || "example.com")
|
|
125
|
+
const adminEmail = clean(
|
|
126
|
+
flags["admin-email"] ||
|
|
127
|
+
(interactive ? await rl.question(`Admin e-mail [admin@${emailDomain}]: `) : "") ||
|
|
128
|
+
`admin@${emailDomain}`,
|
|
129
|
+
)
|
|
130
|
+
let adminPassword = clean(flags["admin-password"] || "")
|
|
131
|
+
let generatedAdminPassword = false
|
|
132
|
+
if (!adminPassword) {
|
|
133
|
+
if (interactive) {
|
|
134
|
+
const answer = clean(await rl.question("Admin jelszó [Enter = generálás]: "))
|
|
135
|
+
adminPassword = answer
|
|
136
|
+
}
|
|
137
|
+
if (!adminPassword) {
|
|
138
|
+
adminPassword = secret(24)
|
|
139
|
+
generatedAdminPassword = true
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const externalDatabaseUrl = clean(flags["database-url"] || "")
|
|
144
|
+
const externalRedisUrl = clean(flags["redis-url"] || "")
|
|
145
|
+
if (Boolean(externalDatabaseUrl) !== Boolean(externalRedisUrl)) {
|
|
146
|
+
throw new Error("A --database-url és --redis-url opciókat együtt kell megadni.")
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const ports = deterministicPorts(slug)
|
|
150
|
+
const postgresPort = validPort(flags["postgres-port"] || ports.postgres, "postgres-port")
|
|
151
|
+
const redisPort = validPort(flags["redis-port"] || ports.redis, "redis-port")
|
|
152
|
+
const dbName = normalizeDbName(flags["database-name"] || slug)
|
|
153
|
+
const dbUser = normalizeDbName(flags["database-user"] || `${slug}_app`)
|
|
154
|
+
const dbPassword = secret(32)
|
|
155
|
+
const generatedDatabaseUrl = `postgres://${encodeURIComponent(dbUser)}:${encodeURIComponent(dbPassword)}@localhost:${postgresPort}/${dbName}`
|
|
156
|
+
const generatedRedisUrl = `redis://localhost:${redisPort}`
|
|
157
|
+
const infrastructureMode = externalDatabaseUrl ? "external" : "docker"
|
|
158
|
+
const databaseUrl = externalDatabaseUrl
|
|
159
|
+
? normalizeDatabaseUrl(externalDatabaseUrl)
|
|
160
|
+
: generatedDatabaseUrl
|
|
161
|
+
const redisUrl = externalRedisUrl
|
|
162
|
+
? normalizeRedisUrl(externalRedisUrl)
|
|
163
|
+
: generatedRedisUrl
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
projectName,
|
|
167
|
+
storeName,
|
|
168
|
+
slug,
|
|
169
|
+
locale,
|
|
170
|
+
country,
|
|
171
|
+
currency,
|
|
172
|
+
backendUrl,
|
|
173
|
+
storefrontUrl,
|
|
174
|
+
emailDomain,
|
|
175
|
+
orderEmail: clean(flags["order-email"] || `orders@${emailDomain}`),
|
|
176
|
+
supportEmail: clean(flags["support-email"] || `support@${emailDomain}`),
|
|
177
|
+
billingEmail: clean(flags["billing-email"] || `billing@${emailDomain}`),
|
|
178
|
+
systemEmail: clean(flags["system-email"] || `system@${emailDomain}`),
|
|
179
|
+
adminEmail,
|
|
180
|
+
adminPassword,
|
|
181
|
+
generatedAdminPassword,
|
|
182
|
+
postgresPort,
|
|
183
|
+
redisPort,
|
|
184
|
+
dbName,
|
|
185
|
+
dbUser,
|
|
186
|
+
dbPassword,
|
|
187
|
+
databaseUrl,
|
|
188
|
+
redisUrl,
|
|
189
|
+
infrastructureMode,
|
|
190
|
+
jwtSecret: secret(48),
|
|
191
|
+
cookieSecret: secret(48),
|
|
192
|
+
integrationEncryptionKey: secret(48),
|
|
193
|
+
shippingWebhookSecret: secret(48),
|
|
194
|
+
coreVersion: clean(flags["core-version"] || "1.0.0"),
|
|
195
|
+
}
|
|
196
|
+
} finally {
|
|
197
|
+
rl?.close()
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function resolveTemplates() {
|
|
202
|
+
const embedded = join(packageRoot, "templates")
|
|
203
|
+
if (existsSync(join(embedded, "backend")) && existsSync(join(embedded, "storefront"))) {
|
|
204
|
+
return { backend: join(embedded, "backend"), storefront: join(embedded, "storefront") }
|
|
205
|
+
}
|
|
206
|
+
const repoRoot = resolve(packageRoot, "../..")
|
|
207
|
+
const backend = join(repoRoot, "starters", "backend")
|
|
208
|
+
const storefront = join(repoRoot, "starters", "storefront-next")
|
|
209
|
+
if (!existsSync(backend) || !existsSync(storefront)) {
|
|
210
|
+
throw new Error("A create-commerce starter template-ek nem találhatók. A package hibásan lett publikálva.")
|
|
211
|
+
}
|
|
212
|
+
return { backend, storefront }
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function configureProject(root, settings) {
|
|
216
|
+
const rootPackage = {
|
|
217
|
+
name: settings.slug,
|
|
218
|
+
version: "0.1.0",
|
|
219
|
+
private: true,
|
|
220
|
+
packageManager: "npm@10.9.4",
|
|
221
|
+
engines: { node: "22.x" },
|
|
222
|
+
workspaces: ["backend", "storefront"],
|
|
223
|
+
scripts: {
|
|
224
|
+
"dev:backend": "npm --workspace backend run dev",
|
|
225
|
+
"dev:storefront": "npm --workspace storefront run dev",
|
|
226
|
+
"typecheck": "npm --workspace backend run typecheck && npm --workspace storefront run typecheck",
|
|
227
|
+
"test": "npm --workspace backend run test",
|
|
228
|
+
"build": "npm --workspace backend run verify:build && npm --workspace storefront run build",
|
|
229
|
+
"verify": "npm run typecheck && npm run test && npm run build",
|
|
230
|
+
"db:migrate": "npm --workspace backend run db:migrate",
|
|
231
|
+
"core:init": "npm --workspace backend run core:init --",
|
|
232
|
+
"storefront:key": "npm --workspace backend run storefront:key --",
|
|
233
|
+
"bootstrap:assert": "npm --workspace backend run bootstrap:assert",
|
|
234
|
+
"docker:up": "docker compose --env-file .env.docker up -d --wait",
|
|
235
|
+
"docker:down": "docker compose --env-file .env.docker down"
|
|
236
|
+
},
|
|
237
|
+
}
|
|
238
|
+
writeJson(join(root, "package.json"), rootPackage)
|
|
239
|
+
writeFileSync(join(root, ".nvmrc"), "22\n")
|
|
240
|
+
writeFileSync(
|
|
241
|
+
join(root, ".gitignore"),
|
|
242
|
+
[
|
|
243
|
+
"node_modules/",
|
|
244
|
+
"backend/.env",
|
|
245
|
+
"backend/.medusa/",
|
|
246
|
+
"backend/src/api",
|
|
247
|
+
"backend/src/jobs",
|
|
248
|
+
"backend/src/modules",
|
|
249
|
+
"backend/src/subscribers",
|
|
250
|
+
"backend/src/workflows",
|
|
251
|
+
"storefront/.env.local",
|
|
252
|
+
"storefront/.next/",
|
|
253
|
+
"*.tsbuildinfo",
|
|
254
|
+
".env.docker",
|
|
255
|
+
".DS_Store",
|
|
256
|
+
"*.log",
|
|
257
|
+
"backups/",
|
|
258
|
+
"",
|
|
259
|
+
].join("\n"),
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
const backendPackagePath = join(root, "backend", "package.json")
|
|
263
|
+
const backendPackage = readJson(backendPackagePath)
|
|
264
|
+
backendPackage.name = "backend"
|
|
265
|
+
backendPackage.private = true
|
|
266
|
+
backendPackage.dependencies["@hszrdm/core"] = resolveCoreDependency(settings.coreVersion)
|
|
267
|
+
backendPackage.scripts.test = "npm run typecheck"
|
|
268
|
+
writeJson(backendPackagePath, backendPackage)
|
|
269
|
+
|
|
270
|
+
const storefrontPackagePath = join(root, "storefront", "package.json")
|
|
271
|
+
const storefrontPackage = readJson(storefrontPackagePath)
|
|
272
|
+
storefrontPackage.name = "storefront"
|
|
273
|
+
storefrontPackage.private = true
|
|
274
|
+
writeJson(storefrontPackagePath, storefrontPackage)
|
|
275
|
+
|
|
276
|
+
writeFileSync(
|
|
277
|
+
join(root, "README.md"),
|
|
278
|
+
`# ${settings.storeName}\n\nGenerated by @hszrdm/create-commerce.\n\n## Development\n\n\`npm run docker:up\`\n\`npm run dev:backend\`\n\`npm run dev:storefront\`\n\nProject-specific backend code belongs in \`backend/src/project/\`. Shared commerce behavior comes from \`@hszrdm/core\`.\n`,
|
|
279
|
+
)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function configureDocker(root, settings) {
|
|
283
|
+
writeFileSync(
|
|
284
|
+
join(root, ".env.docker"),
|
|
285
|
+
[
|
|
286
|
+
`POSTGRES_DB=${settings.dbName}`,
|
|
287
|
+
`POSTGRES_USER=${settings.dbUser}`,
|
|
288
|
+
`POSTGRES_PASSWORD=${settings.dbPassword}`,
|
|
289
|
+
`POSTGRES_PORT=${settings.postgresPort}`,
|
|
290
|
+
`REDIS_PORT=${settings.redisPort}`,
|
|
291
|
+
"",
|
|
292
|
+
].join("\n"),
|
|
293
|
+
{ mode: 0o600 },
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
writeFileSync(
|
|
297
|
+
join(root, "docker-compose.yml"),
|
|
298
|
+
`services:\n postgres:\n image: postgres:16-alpine\n restart: unless-stopped\n env_file: .env.docker\n environment:\n POSTGRES_DB: \${POSTGRES_DB}\n POSTGRES_USER: \${POSTGRES_USER}\n POSTGRES_PASSWORD: \${POSTGRES_PASSWORD}\n ports:\n - "127.0.0.1:\${POSTGRES_PORT}:5432"\n volumes:\n - postgres_data:/var/lib/postgresql/data\n healthcheck:\n test: ["CMD-SHELL", "pg_isready -U \${POSTGRES_USER} -d \${POSTGRES_DB}"]\n interval: 2s\n timeout: 5s\n retries: 30\n\n redis:\n image: redis:7-alpine\n restart: unless-stopped\n ports:\n - "127.0.0.1:\${REDIS_PORT}:6379"\n volumes:\n - redis_data:/data\n healthcheck:\n test: ["CMD", "redis-cli", "ping"]\n interval: 2s\n timeout: 5s\n retries: 30\n\nvolumes:\n postgres_data:\n redis_data:\n`,
|
|
299
|
+
)
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function configureBackend(root, settings) {
|
|
303
|
+
const examplePath = join(root, "backend", ".env.example")
|
|
304
|
+
const envPath = join(root, "backend", ".env")
|
|
305
|
+
let env = readFileSync(examplePath, "utf8")
|
|
306
|
+
const values = {
|
|
307
|
+
DATABASE_URL: settings.databaseUrl,
|
|
308
|
+
REDIS_URL: settings.redisUrl,
|
|
309
|
+
MEDUSA_BACKEND_URL: settings.backendUrl,
|
|
310
|
+
STOREFRONT_URL: settings.storefrontUrl,
|
|
311
|
+
JWT_SECRET: settings.jwtSecret,
|
|
312
|
+
COOKIE_SECRET: settings.cookieSecret,
|
|
313
|
+
STORE_CORS: settings.storefrontUrl,
|
|
314
|
+
ADMIN_CORS: settings.backendUrl,
|
|
315
|
+
AUTH_CORS: `${settings.storefrontUrl},${settings.backendUrl}`,
|
|
316
|
+
INTEGRATION_SETTINGS_ENCRYPTION_KEY: settings.integrationEncryptionKey,
|
|
317
|
+
SHIPPING_WEBHOOK_SECRET: settings.shippingWebhookSecret,
|
|
318
|
+
STORE_NAME: settings.storeName,
|
|
319
|
+
STORE_SLUG: settings.slug,
|
|
320
|
+
STORE_LOCALE: settings.locale,
|
|
321
|
+
STORE_DEFAULT_CURRENCY: settings.currency,
|
|
322
|
+
STORE_DEFAULT_COUNTRY: settings.country,
|
|
323
|
+
VITE_ADMIN_BRAND_NAME: `${settings.storeName} – HSZRDM Commerce`,
|
|
324
|
+
ORDER_EMAIL: settings.orderEmail,
|
|
325
|
+
SUPPORT_EMAIL: settings.supportEmail,
|
|
326
|
+
BILLING_EMAIL: settings.billingEmail,
|
|
327
|
+
SYSTEM_EMAIL: settings.systemEmail,
|
|
328
|
+
SEO_STOREFRONT_URL: settings.storefrontUrl,
|
|
329
|
+
SEO_STORE_NAME: settings.storeName,
|
|
330
|
+
SEO_ORGANIZATION_NAME: settings.storeName,
|
|
331
|
+
SEO_ALLOW_INDEXING: "false",
|
|
332
|
+
}
|
|
333
|
+
for (const [key, value] of Object.entries(values)) env = setEnvValue(env, key, value)
|
|
334
|
+
writeFileSync(envPath, env, { mode: 0o600 })
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function configureStorefront(root, settings) {
|
|
338
|
+
const examplePath = join(root, "storefront", ".env.example")
|
|
339
|
+
const envPath = join(root, "storefront", ".env.local")
|
|
340
|
+
let env = readFileSync(examplePath, "utf8")
|
|
341
|
+
env = setEnvValue(env, "MEDUSA_BACKEND_URL", settings.backendUrl)
|
|
342
|
+
env = setEnvValue(env, "NEXT_PUBLIC_MEDUSA_BACKEND_URL", settings.backendUrl)
|
|
343
|
+
env = setEnvValue(env, "NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY", "")
|
|
344
|
+
writeFileSync(envPath, env, { mode: 0o600 })
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function updateStorefrontKey(root, key) {
|
|
348
|
+
const path = join(root, "storefront", ".env.local")
|
|
349
|
+
let env = readFileSync(path, "utf8")
|
|
350
|
+
env = setEnvValue(env, "NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY", key)
|
|
351
|
+
writeFileSync(path, env, { mode: 0o600 })
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function writeMetadata(root, settings) {
|
|
355
|
+
writeJson(join(root, "hszrdm-commerce.json"), {
|
|
356
|
+
schema_version: 1,
|
|
357
|
+
generator: "@hszrdm/create-commerce",
|
|
358
|
+
core_version: settings.coreVersion,
|
|
359
|
+
created_at: new Date().toISOString(),
|
|
360
|
+
project: { name: settings.projectName, slug: settings.slug, store_name: settings.storeName },
|
|
361
|
+
locale: settings.locale,
|
|
362
|
+
country: settings.country,
|
|
363
|
+
currency: settings.currency,
|
|
364
|
+
urls: { backend: settings.backendUrl, storefront: settings.storefrontUrl },
|
|
365
|
+
admin_email: settings.adminEmail,
|
|
366
|
+
database: settings.infrastructureMode === "external"
|
|
367
|
+
? { mode: "external" }
|
|
368
|
+
: { mode: "docker", name: settings.dbName, user: settings.dbUser, port: settings.postgresPort },
|
|
369
|
+
redis: settings.infrastructureMode === "external"
|
|
370
|
+
? { mode: "external" }
|
|
371
|
+
: { mode: "docker", port: settings.redisPort },
|
|
372
|
+
})
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function createAdminUser(root, settings) {
|
|
376
|
+
console.log("\nElső Medusa admin felhasználó létrehozása...")
|
|
377
|
+
run(
|
|
378
|
+
"npm",
|
|
379
|
+
["exec", "--workspace", "backend", "--", "medusa", "user", "-e", settings.adminEmail, "-p", settings.adminPassword],
|
|
380
|
+
root,
|
|
381
|
+
)
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function initializeGit(root) {
|
|
385
|
+
run("git", ["init"], root)
|
|
386
|
+
try {
|
|
387
|
+
execFileSync("git", ["config", "user.email"], { cwd: root, stdio: "ignore" })
|
|
388
|
+
} catch {
|
|
389
|
+
run("git", ["config", "user.email", "hszrdm@local.invalid"], root)
|
|
390
|
+
}
|
|
391
|
+
try {
|
|
392
|
+
execFileSync("git", ["config", "user.name"], { cwd: root, stdio: "ignore" })
|
|
393
|
+
} catch {
|
|
394
|
+
run("git", ["config", "user.name", "HSZRDM Commerce"], root)
|
|
395
|
+
}
|
|
396
|
+
run("git", ["add", "."], root)
|
|
397
|
+
run("git", ["commit", "-m", "Initial HSZRDM Commerce project"], root)
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function resolveCoreDependency(version) {
|
|
401
|
+
const override = clean(process.env.HSZRDM_CORE_PACKAGE || "")
|
|
402
|
+
if (override) return override.startsWith("file:") ? override : `file:${resolve(override)}`
|
|
403
|
+
return version
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function ensureDockerAvailable() {
|
|
407
|
+
try {
|
|
408
|
+
execFileSync(executable("docker"), ["--version"], { stdio: "ignore", env: process.env })
|
|
409
|
+
execFileSync(executable("docker"), ["compose", "version"], { stdio: "ignore", env: process.env })
|
|
410
|
+
execFileSync(executable("docker"), ["info"], { stdio: "ignore", env: process.env })
|
|
411
|
+
} catch {
|
|
412
|
+
throw new Error(
|
|
413
|
+
"Docker fallback nem elérhető. Indítsd/telepítsd a Dockert, vagy add meg együtt a --database-url és --redis-url értékeket.",
|
|
414
|
+
)
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function run(command, args, cwd) {
|
|
419
|
+
console.log(`\n› ${command} ${args.join(" ")}`)
|
|
420
|
+
execFileSync(executable(command), args, { cwd, stdio: "inherit", env: process.env })
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function runCapture(command, args, cwd) {
|
|
424
|
+
console.log(`\n› ${command} ${args.join(" ")}`)
|
|
425
|
+
const result = execFileSync(executable(command), args, {
|
|
426
|
+
cwd,
|
|
427
|
+
encoding: "utf8",
|
|
428
|
+
env: process.env,
|
|
429
|
+
stdio: ["inherit", "pipe", "pipe"],
|
|
430
|
+
})
|
|
431
|
+
process.stdout.write(result)
|
|
432
|
+
return result
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function executable(command) {
|
|
436
|
+
if (process.platform !== "win32") return command
|
|
437
|
+
if (command === "npm") return "npm.cmd"
|
|
438
|
+
if (command === "npx") return "npx.cmd"
|
|
439
|
+
if (command === "docker") return "docker.exe"
|
|
440
|
+
return command
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function captureMarker(output, name) {
|
|
444
|
+
const match = String(output).match(new RegExp(`(?:^|\\n)${name}=([^\\r\\n]+)`))
|
|
445
|
+
return match?.[1]?.trim() || ""
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function parseArgs(tokens) {
|
|
449
|
+
const positionals = []
|
|
450
|
+
const flags = {}
|
|
451
|
+
for (let index = 0; index < tokens.length; index++) {
|
|
452
|
+
const token = tokens[index]
|
|
453
|
+
if (!token.startsWith("--")) {
|
|
454
|
+
positionals.push(token)
|
|
455
|
+
continue
|
|
456
|
+
}
|
|
457
|
+
const raw = token.slice(2)
|
|
458
|
+
if (raw.startsWith("no-")) {
|
|
459
|
+
flags[`skip-${raw.slice(3)}`] = true
|
|
460
|
+
continue
|
|
461
|
+
}
|
|
462
|
+
const eq = raw.indexOf("=")
|
|
463
|
+
if (eq >= 0) {
|
|
464
|
+
flags[raw.slice(0, eq)] = raw.slice(eq + 1)
|
|
465
|
+
continue
|
|
466
|
+
}
|
|
467
|
+
const next = tokens[index + 1]
|
|
468
|
+
if (next && !next.startsWith("--")) {
|
|
469
|
+
flags[raw] = next
|
|
470
|
+
index++
|
|
471
|
+
} else {
|
|
472
|
+
flags[raw] = true
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return { positionals, flags }
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function setEnvValue(source, key, value) {
|
|
479
|
+
const line = `${key}=${String(value)}`
|
|
480
|
+
const pattern = new RegExp(`^${escapeRegExp(key)}=.*$`, "m")
|
|
481
|
+
if (pattern.test(source)) return source.replace(pattern, line)
|
|
482
|
+
return `${source.replace(/\\s*$/, "")}\n${line}\n`
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function escapeRegExp(value) {
|
|
486
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function deterministicPorts(slug) {
|
|
490
|
+
const value = Number.parseInt(createHash("sha256").update(slug).digest("hex").slice(0, 8), 16)
|
|
491
|
+
return {
|
|
492
|
+
postgres: 15432 + (value % 500),
|
|
493
|
+
redis: 16379 + (value % 500),
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function validPort(value, name) {
|
|
498
|
+
const port = Number(value)
|
|
499
|
+
if (!Number.isInteger(port) || port < 1024 || port > 65535) throw new Error(`Érvénytelen --${name}: ${value}`)
|
|
500
|
+
return port
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function normalizeSlug(value) {
|
|
504
|
+
return clean(value)
|
|
505
|
+
.normalize("NFD")
|
|
506
|
+
.replace(/[\u0300-\u036f]/g, "")
|
|
507
|
+
.toLowerCase()
|
|
508
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
509
|
+
.replace(/^-+|-+$/g, "")
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function normalizeDbName(value) {
|
|
513
|
+
const result = normalizeSlug(value).replace(/-/g, "_")
|
|
514
|
+
if (!result) throw new Error("Érvényes adatbázisnév nem képezhető.")
|
|
515
|
+
return result.slice(0, 48)
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
function normalizeCurrency(value) {
|
|
519
|
+
const result = clean(value).toUpperCase()
|
|
520
|
+
if (!/^[A-Z]{3}$/.test(result)) throw new Error("A pénznem 3 betűs ISO kód legyen.")
|
|
521
|
+
return result
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
function normalizeCountry(value) {
|
|
525
|
+
const result = clean(value).toUpperCase()
|
|
526
|
+
if (!/^[A-Z]{2}$/.test(result)) throw new Error("Az ország 2 betűs ISO kód legyen.")
|
|
527
|
+
return result
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function normalizeDatabaseUrl(value) {
|
|
531
|
+
const url = new URL(clean(value))
|
|
532
|
+
if (!["postgres:", "postgresql:"].includes(url.protocol)) {
|
|
533
|
+
throw new Error("A --database-url PostgreSQL URL legyen (postgres:// vagy postgresql://).")
|
|
534
|
+
}
|
|
535
|
+
return clean(value)
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
function normalizeRedisUrl(value) {
|
|
539
|
+
const url = new URL(clean(value))
|
|
540
|
+
if (!["redis:", "rediss:"].includes(url.protocol)) {
|
|
541
|
+
throw new Error("A --redis-url Redis URL legyen (redis:// vagy rediss://).")
|
|
542
|
+
}
|
|
543
|
+
return clean(value)
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
function normalizeUrl(value) {
|
|
547
|
+
const url = new URL(clean(value))
|
|
548
|
+
if (!["http:", "https:"].includes(url.protocol)) throw new Error("Csak HTTP/HTTPS URL használható.")
|
|
549
|
+
url.hash = ""
|
|
550
|
+
url.search = ""
|
|
551
|
+
return url.toString().replace(/\/$/, "")
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function safeHostname(value) {
|
|
555
|
+
try { return new URL(value).hostname.replace(/^www\./, "") } catch { return "" }
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
function titleFromSlug(slug) {
|
|
559
|
+
return slug.split("-").filter(Boolean).map((part) => part[0]?.toUpperCase() + part.slice(1)).join(" ")
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function secret(bytes = 32) {
|
|
563
|
+
return randomBytes(bytes).toString("base64url")
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
function readJson(path) {
|
|
567
|
+
return JSON.parse(readFileSync(path, "utf8"))
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
function writeJson(path, value) {
|
|
571
|
+
mkdirSync(dirname(path), { recursive: true })
|
|
572
|
+
writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`, "utf8")
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function clean(value) {
|
|
576
|
+
return String(value ?? "").trim()
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
function bool(value) {
|
|
580
|
+
return value === true || value === "true" || value === "1"
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
function printHelp() {
|
|
584
|
+
console.log(`HSZRDM Commerce project generator\n\nHasználat:\n npx @hszrdm/create-commerce <project-name> [opciók]\n\nFő opciók:\n --name <név>\n --slug <slug>\n --locale hu-HU\n --country HU\n --currency HUF\n --backend-url http://localhost:9000\n --storefront-url http://localhost:3000\n --admin-email <email>\n --admin-password <password>\n --database-url postgres://...\n --redis-url redis://...\n --postgres-port <port>\n --redis-port <port>\n --core-version 1.0.0\n --non-interactive\n --force\n\nInfrastruktúra:\n Ha --database-url és --redis-url meg van adva, a generátor Dockert nem használ.\n Ha nincsenek megadva, Docker Compose a fallback.\n\nFejlesztői kapcsolók:\n --skip-install\n --skip-docker\n --skip-bootstrap\n --skip-verify\n --skip-git\n\nLokális Core package teszthez:\n HSZRDM_CORE_PACKAGE=/abs/path/to/packages/core npx @hszrdm/create-commerce test-shop\n`)
|
|
585
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# -----------------------------------------------------------------------------
|
|
2
|
+
# MEDUSA WEBSHOP CORE - environment
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# APP_ENV is optional. Empty/unset means the Core follows NODE_ENV automatically.
|
|
5
|
+
# Use an explicit override only when you intentionally need it.
|
|
6
|
+
# APP_ENV=development
|
|
7
|
+
# NODE_ENV=development
|
|
8
|
+
# Never enable this in a normal production deployment. It only exists for an
|
|
9
|
+
# explicitly approved temporary sandbox runtime.
|
|
10
|
+
# ALLOW_PRODUCTION_SANDBOX=false
|
|
11
|
+
|
|
12
|
+
# -----------------------------------------------------------------------------
|
|
13
|
+
# Runtime / infrastructure
|
|
14
|
+
# -----------------------------------------------------------------------------
|
|
15
|
+
DATABASE_URL=postgres://postgres:postgres@localhost:5432/medusa_core
|
|
16
|
+
REDIS_URL=redis://localhost:6379
|
|
17
|
+
MEDUSA_BACKEND_URL=http://localhost:9000
|
|
18
|
+
STOREFRONT_URL=http://localhost:3000
|
|
19
|
+
MEDUSA_ADMIN_PATH=/app
|
|
20
|
+
|
|
21
|
+
# Local development can leave this empty. Production requires an absolute,
|
|
22
|
+
# durable path, for example /var/lib/medusa-webshop-core/uploads.
|
|
23
|
+
FILE_UPLOAD_DIR=
|
|
24
|
+
RELEASE_SHA=development
|
|
25
|
+
|
|
26
|
+
# -----------------------------------------------------------------------------
|
|
27
|
+
# Security
|
|
28
|
+
# -----------------------------------------------------------------------------
|
|
29
|
+
JWT_SECRET=replace-with-at-least-32-random-characters
|
|
30
|
+
COOKIE_SECRET=replace-with-at-least-32-random-characters
|
|
31
|
+
|
|
32
|
+
STORE_CORS=http://localhost:3000
|
|
33
|
+
ADMIN_CORS=http://localhost:9000,http://localhost:7001
|
|
34
|
+
AUTH_CORS=http://localhost:3000,http://localhost:9000,http://localhost:7001
|
|
35
|
+
|
|
36
|
+
# Settings -> Integrations encrypts provider secrets in the database and in the
|
|
37
|
+
# runtime snapshot. Use a separate, stable key in production.
|
|
38
|
+
INTEGRATION_SETTINGS_ENCRYPTION_KEY=replace-with-at-least-32-random-characters
|
|
39
|
+
# Optional explicit snapshot path. Empty = .core/ locally, or the durable upload
|
|
40
|
+
# directory parent when FILE_UPLOAD_DIR is configured.
|
|
41
|
+
INTEGRATION_SETTINGS_FILE=
|
|
42
|
+
|
|
43
|
+
# Shared secret for supported inbound shipping callbacks (currently FOXPOST/GLS).
|
|
44
|
+
# Required only when an integration using these callbacks is enabled.
|
|
45
|
+
SHIPPING_WEBHOOK_SECRET=
|
|
46
|
+
|
|
47
|
+
# -----------------------------------------------------------------------------
|
|
48
|
+
# Store identity
|
|
49
|
+
# -----------------------------------------------------------------------------
|
|
50
|
+
STORE_NAME=Example Store
|
|
51
|
+
STORE_SLUG=example-store
|
|
52
|
+
STORE_LOCALE=hu-HU
|
|
53
|
+
STORE_DEFAULT_CURRENCY=HUF
|
|
54
|
+
STORE_DEFAULT_COUNTRY=HU
|
|
55
|
+
VITE_ADMIN_BRAND_NAME=Example Store Admin
|
|
56
|
+
|
|
57
|
+
ORDER_EMAIL=orders@example.com
|
|
58
|
+
SUPPORT_EMAIL=support@example.com
|
|
59
|
+
BILLING_EMAIL=billing@example.com
|
|
60
|
+
SYSTEM_EMAIL=system@example.com
|
|
61
|
+
|
|
62
|
+
# -----------------------------------------------------------------------------
|
|
63
|
+
# Customer after-sales self-service
|
|
64
|
+
# -----------------------------------------------------------------------------
|
|
65
|
+
# These switches expose customer endpoints backed by Medusa's native
|
|
66
|
+
# return/exchange/claim workflows. They do not auto-approve or auto-refund.
|
|
67
|
+
AFTER_SALES_ENABLED=true
|
|
68
|
+
AFTER_SALES_RETURNS_ENABLED=true
|
|
69
|
+
AFTER_SALES_EXCHANGES_ENABLED=true
|
|
70
|
+
AFTER_SALES_CLAIMS_ENABLED=true
|
|
71
|
+
|
|
72
|
+
# Optional merchant policy page and text inserted into approved return e-mails.
|
|
73
|
+
# The Core intentionally does not hard-code legal return windows or eligibility.
|
|
74
|
+
AFTER_SALES_POLICY_URL=
|
|
75
|
+
AFTER_SALES_RETURN_INSTRUCTIONS=
|
|
76
|
+
|
|
77
|
+
# -----------------------------------------------------------------------------
|
|
78
|
+
# Technical SEO - optional overrides
|
|
79
|
+
# -----------------------------------------------------------------------------
|
|
80
|
+
# The SEO layer already falls back to STOREFRONT_URL, STORE_NAME,
|
|
81
|
+
# STORE_DEFAULT_COUNTRY and STORE_DEFAULT_CURRENCY. Only set these when the SEO
|
|
82
|
+
# value intentionally differs from the store default.
|
|
83
|
+
SEO_STOREFRONT_URL=
|
|
84
|
+
SEO_STORE_NAME=
|
|
85
|
+
SEO_ORGANIZATION_NAME=
|
|
86
|
+
SEO_ORGANIZATION_LOGO_URL=
|
|
87
|
+
SEO_DEFAULT_COUNTRY=
|
|
88
|
+
SEO_DEFAULT_CURRENCY=
|
|
89
|
+
|
|
90
|
+
# Optional explicit Medusa region / sales channel for Product Offer JSON-LD.
|
|
91
|
+
SEO_REGION_ID=
|
|
92
|
+
SEO_SALES_CHANNEL_ID=
|
|
93
|
+
|
|
94
|
+
SEO_PRODUCT_PATH_TEMPLATE=/{country_code}/products/{handle}
|
|
95
|
+
SEO_CATEGORY_PATH_TEMPLATE=/{country_code}/categories/{handle}
|
|
96
|
+
|
|
97
|
+
# Empty = enabled only in NODE_ENV=production. Set explicitly only when needed.
|
|
98
|
+
SEO_ALLOW_INDEXING=
|
|
99
|
+
# Extra comma-separated Disallow paths. Core defaults already include
|
|
100
|
+
# /app, /admin, /account, /cart and /checkout.
|
|
101
|
+
SEO_ROBOTS_DISALLOW=
|
|
102
|
+
|
|
103
|
+
# -----------------------------------------------------------------------------
|
|
104
|
+
# External integrations
|
|
105
|
+
# -----------------------------------------------------------------------------
|
|
106
|
+
# Do NOT copy every provider secret into the main .env.
|
|
107
|
+
# Configure integrations in Medusa Admin: Settings -> Integrációk.
|
|
108
|
+
#
|
|
109
|
+
# Legacy/bootstrap/fallback variable reference:
|
|
110
|
+
# apps/backend/.env.integrations.example
|
|
111
|
+
#
|
|
112
|
+
# The encrypted runtime snapshot is loaded before provider configuration and
|
|
113
|
+
# overrides matching fallback env values.
|