@pradip1995/create-storefront-app 0.2.3 → 0.3.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.
Files changed (48) hide show
  1. package/bin/create-storefront-app.js +141 -59
  2. package/lib/build-backend-package.js +54 -0
  3. package/lib/build-homepage-defaults.cjs +50 -0
  4. package/lib/deps.js +3 -1
  5. package/lib/docker-template-vars.js +32 -0
  6. package/lib/medusa-plugin-versions.json +55 -0
  7. package/lib/scaffold-backend.js +107 -0
  8. package/lib/scaffold-docker.js +82 -0
  9. package/lib/versions.js +4 -3
  10. package/package.json +3 -2
  11. package/templates/backend/.cursor/commands/seed-backend.md +16 -0
  12. package/templates/backend/.cursor/rules/medusa-backend.mdc +55 -0
  13. package/templates/backend/config/README.md +21 -0
  14. package/templates/backend/config/homepage-config.json +568 -0
  15. package/templates/backend/env.template +53 -0
  16. package/templates/backend/gitignore +8 -0
  17. package/templates/backend/medusa-config.full.ts +251 -0
  18. package/templates/backend/medusa-config.minimal.ts +141 -0
  19. package/templates/backend/scripts/build-dynamic-config-defaults.mjs +25 -0
  20. package/templates/backend/scripts/build-homepage-defaults.cjs +50 -0
  21. package/templates/backend/src/config/product-metadata-descriptors.ts +27 -0
  22. package/templates/backend/src/scripts/seed.ts +212 -0
  23. package/templates/backend/tsconfig.json +24 -0
  24. package/templates/docker/Makefile +86 -0
  25. package/templates/docker/backend/.dockerignore +8 -0
  26. package/templates/docker/backend/Dockerfile +30 -0
  27. package/templates/docker/data/README.md +12 -0
  28. package/templates/docker/data/dump.sql +3 -0
  29. package/templates/docker/docker/.env.example +36 -0
  30. package/templates/docker/docker/frontend.build.defaults +7 -0
  31. package/templates/docker/docker/gitignore +1 -0
  32. package/templates/docker/docker/postgres/01-create-postgres-role.sql +9 -0
  33. package/templates/docker/docker/postgres/docker-entrypoint-wrapper.sh +49 -0
  34. package/templates/docker/docker-compose.infra.yml +64 -0
  35. package/templates/docker/docker-compose.yml +138 -0
  36. package/templates/docker/storefront/.dockerignore +9 -0
  37. package/templates/docker/storefront/Dockerfile +53 -0
  38. package/templates/root/.cursor/commands/docker-dev.md +32 -0
  39. package/templates/root/.cursor/rules/monorepo-layout.mdc +55 -0
  40. package/templates/shared/.cursor/commands/change-theme-colors.md +1 -1
  41. package/templates/shared/.cursor/commands/fix-segment-issue.md +2 -2
  42. package/templates/shared/.cursor/commands/rebuild-storefront.md +1 -1
  43. package/templates/shared/.cursor/rules/customize-theme.mdc +1 -1
  44. package/templates/shared/.cursor/rules/storefront-architecture.mdc +3 -2
  45. package/templates/shared/.cursor/skills/fix-segment-issues/SKILL.md +1 -1
  46. package/templates/shared/README.md +100 -0
  47. package/templates/shared/root-gitignore +6 -0
  48. package/templates/shared/storefront-only-README.md +25 -0
@@ -0,0 +1,9 @@
1
+ node_modules
2
+ .generated-app
3
+ .next
4
+ .git
5
+ .env
6
+ .env.*
7
+ npm-debug.log*
8
+ Dockerfile
9
+ .dockerignore
@@ -0,0 +1,53 @@
1
+ # syntax=docker/dockerfile:1
2
+
3
+ # Use slim (glibc) — Alpine musl sharp corrupts AVIF product images.
4
+ FROM node:24-slim AS builder
5
+
6
+ RUN apt-get update && apt-get install -y --no-install-recommends \
7
+ libvips42 \
8
+ libheif1 \
9
+ && rm -rf /var/lib/apt/lists/*
10
+
11
+ WORKDIR /app
12
+
13
+ COPY package.json .npmrc ./
14
+ RUN npm install --prefer-offline --no-audit --legacy-peer-deps \
15
+ && npm rebuild sharp
16
+
17
+ COPY pages.config.json storefront.config.json theme-overrides.css ./
18
+ COPY public ./public/
19
+
20
+ RUN npm run storefront:build
21
+
22
+ WORKDIR /app/.generated-app
23
+
24
+ RUN npm install --prefer-offline --no-audit --legacy-peer-deps \
25
+ && npm rebuild sharp
26
+
27
+ RUN --mount=type=secret,id=frontend_defaults \
28
+ --mount=type=secret,id=app_env \
29
+ sh -c 'cat /run/secrets/frontend_defaults /run/secrets/app_env > .env.production' \
30
+ && npm run build \
31
+ && npm prune --omit=dev
32
+
33
+ FROM node:24-slim AS runner
34
+
35
+ RUN apt-get update && apt-get install -y --no-install-recommends \
36
+ libvips42 \
37
+ libheif1 \
38
+ && rm -rf /var/lib/apt/lists/*
39
+
40
+ WORKDIR /app
41
+
42
+ ENV NODE_ENV=production
43
+ ENV PORT=8000
44
+
45
+ COPY --from=builder /app/.generated-app/package.json ./package.json
46
+ COPY --from=builder /app/.generated-app/.next ./.next
47
+ COPY --from=builder /app/.generated-app/public ./public
48
+ COPY --from=builder /app/.generated-app/next.config.js ./next.config.js
49
+ COPY --from=builder /app/.generated-app/node_modules ./node_modules
50
+
51
+ EXPOSE 8000
52
+
53
+ CMD ["npm", "run", "start"]
@@ -0,0 +1,32 @@
1
+ # Docker dev
2
+
3
+ ## Full stack in Docker
4
+
5
+ ```bash
6
+ make up
7
+ make migrate
8
+ make seed
9
+ make admin-create
10
+ ```
11
+
12
+ ## Infra only + local Node
13
+
14
+ ```bash
15
+ make up-infra
16
+ npm run dev:backend # terminal 1
17
+ npm run dev:storefront # terminal 2
18
+ ```
19
+
20
+ ## After seed
21
+
22
+ Copy publishable API key into:
23
+
24
+ - `storefront/.env.local` (local dev)
25
+ - `docker/frontend.build.defaults` + rebuild storefront image (Docker)
26
+
27
+ ```bash
28
+ make build-storefront
29
+ make up-storefront
30
+ ```
31
+
32
+ Mailpit: http://localhost:8025
@@ -0,0 +1,55 @@
1
+ ---
2
+ description: Monorepo layout — backend + storefront dev workflow
3
+ alwaysApply: true
4
+ ---
5
+
6
+ # Project layout
7
+
8
+ ```
9
+ <project>/
10
+ backend/ Medusa v2 API + Admin
11
+ storefront/ Segment-based Next.js (config client)
12
+ ```
13
+
14
+ ## Dev (local Node)
15
+
16
+ ```bash
17
+ npm run dev:backend # terminal 1
18
+ npm run dev:storefront # terminal 2
19
+ ```
20
+
21
+ ## Dev (Docker)
22
+
23
+ ```bash
24
+ make up # full stack in containers
25
+ make up-infra # postgres + redis + mailpit only, then npm run dev:* locally
26
+ make migrate && make seed && make admin-create
27
+ ```
28
+
29
+ See `Makefile` and command `docker-dev`.
30
+
31
+ ## First-time backend
32
+
33
+ 1. Set `DATABASE_URL` in `backend/.env`
34
+ 2. `npm run dev:backend` (migrations)
35
+ 3. `npm run seed` (region, API key, sample product)
36
+ 4. Copy publishable key → `storefront/.env.local`
37
+
38
+ ## Build
39
+
40
+ ```bash
41
+ npm run build:backend
42
+ npm run build:storefront
43
+ ```
44
+
45
+ ## Where to edit
46
+
47
+ | Goal | Path |
48
+ |------|------|
49
+ | Medusa plugins / modules | `backend/medusa-config.ts` |
50
+ | Plugin npm versions | `backend/config/medusa-plugin-versions.json` |
51
+ | Homepage admin fields | `backend/config/homepage-config.json` (+ `npm run dynamic-config:defaults` in backend) |
52
+ | Storefront sections | `storefront/pages.config.json` |
53
+ | Brand colors | `storefront/theme-overrides.css` |
54
+
55
+ Cursor guides live in `backend/.cursor/` and `storefront/.cursor/`.
@@ -21,7 +21,7 @@
21
21
 
22
22
  ## Hero & section content
23
23
 
24
- Configure in **Medusa Admin** dynamic-config (`homepage-config`), not in this repo. Schema: `dynamic-config.generated.json`.
24
+ Configure in **Medusa Admin** dynamic-config (`homepage-config`). Schema: `backend/config/homepage-config.json`.
25
25
 
26
26
  ## Switch full theme preset (advanced)
27
27
 
@@ -40,8 +40,8 @@ Symptoms: hero is plain text, nav not transparent, sections unstyled.
40
40
  ## 5. Empty segment but API works
41
41
 
42
42
  - Segment may need workflow data (e.g. new-arrivals needs products with tags)
43
- - Check Medusa dynamic-config for that section's fields
44
- - Compare with working `dynamic-config.defaults.json` in project root
43
+ - Check Medusa Admin dynamic-config for that section's fields
44
+ - Confirm `NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY` is set and backend `/store/dynamic-config` returns data
45
45
 
46
46
  ## 6. Package version mismatch
47
47
 
@@ -16,4 +16,4 @@ npm run start
16
16
 
17
17
  **Do not** edit files inside `.generated-app/` — they are overwritten every build.
18
18
 
19
- Verify build output includes your segments and `dynamic-config: wrote dynamic-config.generated.json`.
19
+ Verify build output lists your segments. Homepage content is loaded from Medusa Admin via `/store/dynamic-config`, not generated in the storefront build.
@@ -54,4 +54,4 @@ NEXT_PUBLIC_HOME_PAGE_DESCRIPTION=Subtext
54
54
 
55
55
  ## Medusa admin content
56
56
 
57
- Hero banners, promo text, testimonials, features → Medusa **dynamic-config** (`homepage-config`). Import `dynamic-config.generated.json` into your backend plugin.
57
+ Hero banners, promo text, testimonials, features → Medusa **dynamic-config** (`homepage-config`). Edit schema in `backend/config/homepage-config.json`; storefront loads values from `GET /store/dynamic-config`.
@@ -5,7 +5,7 @@ alwaysApply: true
5
5
 
6
6
  # Storefront architecture
7
7
 
8
- This project is a **config client**, not a hand-written Next.js app.
8
+ This folder (`storefront/`) is a **config client**, not a hand-written Next.js app. The Medusa backend lives in `../backend/`.
9
9
 
10
10
  ## You edit (client root)
11
11
 
@@ -23,7 +23,8 @@ This project is a **config client**, not a hand-written Next.js app.
23
23
  | Path | Purpose |
24
24
  |------|---------|
25
25
  | `.generated-app/` | Full Next.js app from `storefront-build` |
26
- | `dynamic-config.generated.json` | Medusa admin schema export |
26
+
27
+ Homepage content (hero, promo, logo, etc.) is **not** generated here — it comes from Medusa `GET /store/dynamic-config`. Schema lives in `../backend/config/homepage-config.json`.
27
28
 
28
29
  After any change to config, deps, or `theme-overrides.css`:
29
30
 
@@ -48,7 +48,7 @@ Symptom: hero shows raw text, nav not styled, shop-by-category flat.
48
48
 
49
49
  - Products needed for carousels (catalog + region)
50
50
  - Dynamic-config in Medusa for hero/testimonials
51
- - Compare with `dynamic-config.defaults.json` in project root
51
+ - Confirm backend is running and `/store/dynamic-config` returns expected JSON
52
52
 
53
53
  ### 6. Version drift
54
54
 
@@ -0,0 +1,100 @@
1
+ # {{PROJECT_NAME}}
2
+
3
+ Full-stack Medusa shop: **backend** (Medusa v2) + **storefront** (segment-based Next.js).
4
+
5
+ Run **with Docker**, **Docker infra + local Node**, or **fully local** (PostgreSQL + Redis on host).
6
+
7
+ ## Prerequisites
8
+
9
+ - **Node.js 20+**
10
+ - **npm 9+**
11
+ - **Docker Desktop** (optional — for `make up` / `make up-infra`)
12
+ - **PostgreSQL + Redis** on host when running fully local without Docker infra
13
+
14
+ All `@pradip1995/*` packages and Medusa plugins resolve from the **public npm registry** — no monorepo or private registry required.
15
+
16
+ ## Option A — Full stack in Docker
17
+
18
+ ```bash
19
+ make env-init # docker/.env from example (already created on scaffold)
20
+ make up # build + start postgres, redis, mailpit, backend, storefront
21
+ make migrate # DB migrations (fresh DB may need two runs)
22
+ make seed # region, publishable key, sample product
23
+ make admin-create
24
+ ```
25
+
26
+ | Service | URL |
27
+ |------------|-----|
28
+ | Storefront | {{BASE_URL}}/{{DEFAULT_REGION}} |
29
+ | Admin | {{BACKEND_URL}}/app |
30
+ | API | {{BACKEND_URL}} |
31
+ | Mailpit | http://localhost:8025 |
32
+
33
+ After `make seed`, update `docker/frontend.build.defaults` and `storefront/.env.local` with the publishable key, then `make build-storefront` if using Docker for the storefront.
34
+
35
+ Default admin: `make admin-create` (see `Makefile` for `ADMIN_EMAIL` / `ADMIN_PASSWORD`).
36
+
37
+ ## Option B — Docker infra + local Node dev
38
+
39
+ ```bash
40
+ make up-infra # postgres, redis, mailpit only
41
+ npm run dev:backend # terminal 1 — uses backend/.env DATABASE_URL
42
+ npm run seed # from project root, or cd backend && npm run seed
43
+ npm run dev:storefront # terminal 2
44
+ ```
45
+
46
+ `backend/.env` `DATABASE_URL` matches Docker postgres credentials from scaffold.
47
+
48
+ For OTP/email in local backend with infra Docker, set `SMTP_HOST=localhost` and `SMTP_PORT=1025` (Mailpit exposes SMTP when using `docker-compose.infra.yml`).
49
+
50
+ ## Option C — Fully local (no Docker)
51
+
52
+ ```bash
53
+ cd backend && npm install
54
+ # Edit .env — PostgreSQL + Redis on localhost
55
+ npm run dev
56
+ npm run seed
57
+
58
+ cd ../storefront && npm install
59
+ # Edit .env.local — publishable key from Admin
60
+ npm run dev
61
+ ```
62
+
63
+ ## Daily dev (local Node)
64
+
65
+ ```bash
66
+ npm run dev:backend # terminal 1
67
+ npm run dev:storefront # terminal 2
68
+ ```
69
+
70
+ ## Build production
71
+
72
+ ```bash
73
+ npm run build:backend
74
+ npm run build:storefront
75
+ # or
76
+ make build
77
+ ```
78
+
79
+ ## Docker commands
80
+
81
+ ```bash
82
+ make help # all targets
83
+ make up-infra # postgres + redis + mailpit
84
+ make up-backend # infra + backend container
85
+ make logs # tail logs
86
+ make db-shell # psql
87
+ make clean # remove containers + volumes
88
+ ```
89
+
90
+ ## Customize
91
+
92
+ | Goal | Where |
93
+ |------|--------|
94
+ | Home sections | `storefront/pages.config.json` |
95
+ | Colors / fonts | `storefront/theme-overrides.css` |
96
+ | Medusa plugins | `backend/medusa-config.ts` + `backend/config/medusa-plugin-versions.json` |
97
+ | Homepage admin fields | `backend/config/homepage-config.json` |
98
+ | Docker secrets | `docker/.env` |
99
+
100
+ Cursor guides: `.cursor/` in each folder.
@@ -0,0 +1,6 @@
1
+ node_modules
2
+ .DS_Store
3
+ *.log
4
+ .env
5
+ .env.local
6
+ docker/.env
@@ -0,0 +1,25 @@
1
+ # {{PROJECT_NAME}}
2
+
3
+ Segment-based Medusa storefront (config client).
4
+
5
+ ## Setup
6
+
7
+ ```bash
8
+ npm install
9
+ # Edit .env.local — Medusa URL + publishable key
10
+ npm run dev
11
+ ```
12
+
13
+ Storefront: {{BASE_URL}}/{{DEFAULT_REGION}}
14
+
15
+ ## Customize
16
+
17
+ | Goal | File |
18
+ |------|------|
19
+ | Home sections | `pages.config.json` |
20
+ | Colors / fonts | `theme-overrides.css` |
21
+ | Brand assets | `public/` |
22
+
23
+ After config changes: `npm run storefront:build && npm run dev`
24
+
25
+ Cursor guides: `.cursor/`