@pradip1995/create-storefront-app 0.3.1 → 0.4.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.
@@ -1,16 +1,13 @@
1
1
  import { cpSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs"
2
2
  import { join, dirname } from "path"
3
3
  import { fileURLToPath } from "url"
4
- import { buildBackendPackageJson, VERSIONS } from "./build-backend-package.js"
4
+ import { buildBackendDependencies, VERSIONS } from "./build-backend-package.js"
5
5
  import { buildDockerTemplateVars } from "./docker-template-vars.js"
6
- import { createRequire } from "module"
7
-
8
- const require = createRequire(import.meta.url)
9
- const { buildHomepageConfigDefaults } = require("./build-homepage-defaults.cjs")
6
+ import { FRAMEWORK_COMPILER_VERSION } from "./versions.js"
10
7
 
11
8
  const __dirname = dirname(fileURLToPath(import.meta.url))
12
9
  const PKG_ROOT = join(__dirname, "..")
13
- const BACKEND_TEMPLATE = join(PKG_ROOT, "templates", "backend")
10
+ const BACKEND_CURSOR = join(PKG_ROOT, "templates", "backend", ".cursor")
14
11
 
15
12
  const REGION_CURRENCY = {
16
13
  in: { currency: "inr", name: "India" },
@@ -32,6 +29,16 @@ function regionMeta(defaultRegion) {
32
29
  )
33
30
  }
34
31
 
32
+ function buildPluginsConfig(preset) {
33
+ const { medusa, plugins } = buildBackendDependencies(preset)
34
+ return { medusa, plugins }
35
+ }
36
+
37
+ function writeJson(path, data) {
38
+ writeFileSync(path, `${JSON.stringify(data, null, 2)}\n`)
39
+ }
40
+
41
+ /** Scaffold config-only backend/ — Medusa source is generated by backend-build. */
35
42
  export function scaffoldBackend(backendRoot, args) {
36
43
  const { preset, name, backendUrl, baseUrl, defaultRegion } = args
37
44
  const meta = regionMeta(defaultRegion)
@@ -51,56 +58,66 @@ export function scaffoldBackend(backendRoot, args) {
51
58
 
52
59
  mkdirSync(backendRoot, { recursive: true })
53
60
 
54
- const medusaConfigSrc =
55
- preset === "minimal"
56
- ? join(BACKEND_TEMPLATE, "medusa-config.minimal.ts")
57
- : join(BACKEND_TEMPLATE, "medusa-config.full.ts")
58
- writeFileSync(join(backendRoot, "medusa-config.ts"), readFileSync(medusaConfigSrc, "utf8"))
59
-
60
- cpSync(join(BACKEND_TEMPLATE, "tsconfig.json"), join(backendRoot, "tsconfig.json"))
61
- cpSync(join(BACKEND_TEMPLATE, "gitignore"), join(backendRoot, ".gitignore"))
62
- cpSync(join(PKG_ROOT, "templates/shared/npmrc"), join(backendRoot, ".npmrc"))
63
- cpSync(join(BACKEND_TEMPLATE, "config"), join(backendRoot, "config"), { recursive: true })
64
- cpSync(join(BACKEND_TEMPLATE, "src"), join(backendRoot, "src"), { recursive: true })
65
- cpSync(join(BACKEND_TEMPLATE, "scripts"), join(backendRoot, "scripts"), { recursive: true })
66
-
67
- const homepageSchema = JSON.parse(
68
- readFileSync(join(backendRoot, "config/homepage-config.json"), "utf8")
69
- )
70
- writeFileSync(
71
- join(backendRoot, "config/homepage-config.defaults.json"),
72
- `${JSON.stringify(buildHomepageConfigDefaults(homepageSchema), null, 2)}\n`
73
- )
61
+ writeJson(join(backendRoot, "backend.config.json"), {
62
+ preset,
63
+ projectName: name,
64
+ defaultRegion,
65
+ })
66
+
67
+ writeJson(join(backendRoot, "plugins.config.json"), buildPluginsConfig(preset))
74
68
 
75
69
  writeFileSync(
76
- join(backendRoot, "config", "medusa-plugin-versions.json"),
77
- JSON.stringify(VERSIONS, null, 2) + "\n"
70
+ join(backendRoot, ".gitignore"),
71
+ readFileSync(join(PKG_ROOT, "templates/backend/gitignore"), "utf8")
78
72
  )
79
-
80
- const seedContent = applyTemplate(
81
- readFileSync(join(BACKEND_TEMPLATE, "src/scripts/seed.ts"), "utf8"),
82
- templateVars
73
+ writeFileSync(
74
+ join(backendRoot, ".npmrc"),
75
+ readFileSync(join(PKG_ROOT, "templates/shared/npmrc"), "utf8")
83
76
  )
84
- mkdirSync(join(backendRoot, "src/scripts"), { recursive: true })
85
- writeFileSync(join(backendRoot, "src/scripts/seed.ts"), seedContent)
86
77
 
78
+ const envTemplate = join(PKG_ROOT, "templates/backend/env.template")
87
79
  writeFileSync(
88
80
  join(backendRoot, ".env.template"),
89
- applyTemplate(readFileSync(join(BACKEND_TEMPLATE, "env.template"), "utf8"), templateVars)
81
+ applyTemplate(readFileSync(envTemplate, "utf8"), templateVars)
90
82
  )
91
83
  writeFileSync(
92
84
  join(backendRoot, ".env"),
93
- applyTemplate(readFileSync(join(BACKEND_TEMPLATE, "env.template"), "utf8"), templateVars)
85
+ applyTemplate(readFileSync(envTemplate, "utf8"), templateVars)
94
86
  )
95
-
96
87
  writeFileSync(
97
- join(backendRoot, "package.json"),
98
- JSON.stringify(buildBackendPackageJson(preset, name), null, 2) + "\n"
88
+ join(backendRoot, ".env.example"),
89
+ applyTemplate(readFileSync(envTemplate, "utf8"), {
90
+ ...templateVars,
91
+ DATABASE_URL: "postgres://user:pass@localhost:5432/medusa",
92
+ })
99
93
  )
100
94
 
101
- const backendCursor = join(BACKEND_TEMPLATE, ".cursor")
102
- if (existsSync(backendCursor)) {
103
- cpSync(backendCursor, join(backendRoot, ".cursor"), { recursive: true })
95
+ const backendReadme = join(PKG_ROOT, "templates/backend/README.md")
96
+ if (existsSync(backendReadme)) {
97
+ writeFileSync(join(backendRoot, "README.md"), readFileSync(backendReadme, "utf8"))
98
+ }
99
+
100
+ writeJson(join(backendRoot, "package.json"), {
101
+ name: `${name}-backend`,
102
+ private: true,
103
+ scripts: {
104
+ "backend:build": "backend-build",
105
+ dev: "npm run backend:build && cd .generated-backend && npm install && npm run dev",
106
+ build:
107
+ "npm run backend:build && cd .generated-backend && npm install && npm run build",
108
+ start:
109
+ "npm run backend:build && cd .generated-backend && npm install && npm run start",
110
+ seed: "npm run backend:build && cd .generated-backend && npm install && npm run seed",
111
+ "dynamic-config:defaults":
112
+ "npm run backend:build && cd .generated-backend && npm run dynamic-config:defaults",
113
+ },
114
+ dependencies: {
115
+ "@pradip1995/framework-compiler": FRAMEWORK_COMPILER_VERSION,
116
+ },
117
+ })
118
+
119
+ if (existsSync(BACKEND_CURSOR)) {
120
+ cpSync(BACKEND_CURSOR, join(backendRoot, ".cursor"), { recursive: true })
104
121
  }
105
122
 
106
123
  return backendRoot
package/lib/versions.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /** Published package semver ranges — bump when releasing framework/components. */
2
2
  export const COMMERCE_CORE_VERSION = "^4.0.2"
3
3
  export const FRAMEWORK_VERSION = "^0.2.1"
4
- export const FRAMEWORK_COMPILER_VERSION = "^0.2.6"
4
+ export const FRAMEWORK_COMPILER_VERSION = "^0.3.0"
5
5
  export const COMPONENTS_VERSION = ">=0.2.0 <0.4.0"
6
6
 
7
7
  export const FRAMEWORK_PACKAGES = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pradip1995/create-storefront-app",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Scaffold a segment-based Medusa storefront using @pradip1995/framework packages",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,54 +1,49 @@
1
1
  ---
2
- description: Medusa backend — config, plugins, env, seed
2
+ description: Medusa backend — config-only client, generated on dev/build
3
3
  globs: backend/**/*
4
4
  alwaysApply: false
5
5
  ---
6
6
 
7
- # Medusa backend
7
+ # Medusa backend (config client)
8
8
 
9
- ## Key files
9
+ Generated Medusa source lives in `.generated-backend/` (gitignored). Same pattern as `storefront/.generated-app/`.
10
+
11
+ ## Committed source
10
12
 
11
13
  | File | Purpose |
12
14
  |------|---------|
13
- | `medusa-config.ts` | Plugins + modules wiring |
14
- | `config/medusa-plugin-versions.json` | npm version map for all plugins |
15
- | `config/homepage-config.json` | Dynamic-config schema — **synced from storefront build** when sections change |
15
+ | `plugins.config.json` | Medusa core + plugin npm versions; optional `enabled` array |
16
+ | `backend.config.json` | Preset (`full`/`minimal`), default region |
16
17
  | `.env` | Database, CORS, secrets, integrations |
17
- | `src/scripts/seed.ts` | Region, sales channel, publishable API key, sample product |
18
18
 
19
19
  ## Commands
20
20
 
21
21
  ```bash
22
22
  cd backend
23
- npm run dev # medusa develop
24
- npm run build # medusa build
25
- npm run seed # medusa exec ./src/scripts/seed.ts
23
+ npm run dev # backend-build → medusa develop
24
+ npm run build # backend-build → medusa build
25
+ npm run seed # seed region, API key, sample product
26
+ npm run backend:build # regenerate .generated-backend/ only
26
27
  ```
27
28
 
29
+ **Do not edit** `.generated-backend/` — overwritten every build.
30
+
28
31
  ## Docker
29
32
 
30
- From project root: `make up-infra` then local `npm run dev`, or `make up` for full containerized stack. See `Makefile`.
33
+ From project root: `make up-infra` then local `npm run dev:backend`, or `make up` for full stack. See `Makefile`.
31
34
 
32
35
  ## After seed
33
36
 
34
- From project root, `npm run seed` or `make seed` syncs the publishable key into `storefront/.env.local` (via `scripts/sync-publishable-key.mjs`, reads from Postgres — no backend code changes).
37
+ From project root, `npm run seed` or `make seed` syncs the publishable key into `storefront/.env.local` (via `scripts/sync-publishable-key.mjs`).
35
38
 
36
- ## Plugin versions
39
+ ## Plugins
37
40
 
38
- Edit `config/medusa-plugin-versions.json`, then update `package.json` dependencies to match and run `npm install`.
41
+ Edit `plugins.config.json` add/remove plugin keys or change versions, then run `npm run dev` or `backend:build`.
39
42
 
40
- ## CORS
41
-
42
- `STORE_CORS` and `AUTH_CORS` must include the storefront URL (`STOREFRONT_URL`).
43
+ `medusa-config.ts` is generated from the enabled plugin list.
43
44
 
44
45
  ## Dynamic config
45
46
 
46
- Homepage fields in Admin come from `config/homepage-config.json` (registered in `medusa-config.ts`).
47
-
48
- After editing the schema, run:
49
-
50
- ```bash
51
- npm run dynamic-config:defaults
52
- ```
47
+ Homepage admin fields sync from `storefront/pages.config.json` on `storefront:build` into `.generated-backend/config/homepage-config.json`.
53
48
 
54
- The storefront reads **runtime values** from `GET /store/dynamic-config` — it does not generate or import schema files.
49
+ Restart backend after schema changes. Storefront reads runtime values from `GET /store/dynamic-config`.
@@ -0,0 +1,26 @@
1
+ # Backend (config-only)
2
+
3
+ Medusa source is **generated** into `.generated-backend/` — same pattern as `storefront/.generated-app/`.
4
+
5
+ ## Committed source
6
+
7
+ | File | Edit when |
8
+ |------|-----------|
9
+ | `plugins.config.json` | Add/remove plugins or change npm versions |
10
+ | `backend.config.json` | Change preset (`full`/`minimal`) or default region |
11
+ | `.env` | Database URL, secrets, optional integrations |
12
+
13
+ ## Commands
14
+
15
+ ```bash
16
+ npm run dev # backend-build → medusa develop
17
+ npm run build # backend-build → medusa build
18
+ npm run seed # seed demo data
19
+ npm run backend:build # regenerate .generated-backend/ only
20
+ ```
21
+
22
+ **Do not edit** `.generated-backend/` — changes are overwritten on the next build.
23
+
24
+ ## Homepage admin schema
25
+
26
+ Synced from storefront segments — see `storefront/pages.config.json` and run `npm run storefront:build` in the storefront folder.
@@ -1,23 +1,29 @@
1
- # Dynamic config (backend)
1
+ # Backend config (committed)
2
+
3
+ This folder is **config-only**. Medusa source is generated into `.generated-backend/` on `npm run dev` or `npm run build` — do not commit that folder.
4
+
5
+ ## Source files
2
6
 
3
7
  | File | Purpose |
4
8
  |------|---------|
5
- | `homepage-config.json` | **Schema** for Medusa Admin **auto-synced** from storefront build |
6
- | `homepage-config.defaults.json` | Default values from schema `defaultValue` fields (auto-synced) |
9
+ | `plugins.config.json` | Medusa core + plugin npm versions; optional `enabled` array to override preset |
10
+ | `backend.config.json` | Preset (`full` \| `minimal`), default region, project name |
11
+ | `.env` / `.env.template` | Secrets and service URLs (DATABASE_URL, CORS, optional integrations) |
12
+
13
+ ## Generated (gitignored)
7
14
 
8
- ## Workflow
15
+ Running `npm run backend:build` (or `dev` / `build`) writes:
9
16
 
10
- 1. Edit **`storefront/pages.config.json`** (add/remove/reorder segments).
11
- 2. Run **`npm run storefront:build`** in `storefront/` (or `npm run dev:storefront`).
12
- 3. `storefront-build` writes filtered schema here based on segments + workflows in use.
13
- 4. Restart Medusa backend so Admin picks up schema changes.
17
+ - `.generated-backend/medusa-config.ts` assembled from `plugins.config.json`
18
+ - `.generated-backend/package.json` Medusa dependencies
19
+ - `.generated-backend/src/`, `scripts/`, `config/`
14
20
 
15
- Optional manual refresh of defaults only:
21
+ ## Dynamic homepage schema
16
22
 
17
- ```bash
18
- cd backend && npm run dynamic-config:defaults
19
- ```
23
+ Homepage admin fields are **not** edited here manually. They sync from the storefront:
20
24
 
21
- Runtime content is edited in **Medusa Admin** (Dynamic Config). The storefront loads values via `GET /store/dynamic-config`.
25
+ 1. Edit `storefront/pages.config.json` (segments/workflows).
26
+ 2. Run `npm run storefront:build` in `storefront/` — writes filtered schema to `backend/.generated-backend/config/homepage-config.json`.
27
+ 3. Run `npm run backend:build` or `dev:backend` — preserves synced schema when regenerating.
22
28
 
23
- Override entire schema: add `storefront/dynamic-config.schema.json` (see framework docs).
29
+ Restart the backend after schema changes.
@@ -1,4 +1,5 @@
1
1
  node_modules
2
+ .generated-backend
2
3
  .medusa
3
4
  .cache
4
5
  static
@@ -2,10 +2,14 @@ FROM node:24-alpine AS builder
2
2
 
3
3
  WORKDIR /app
4
4
 
5
- COPY package.json package-lock.json* ./
5
+ COPY package.json .npmrc plugins.config.json backend.config.json ./
6
6
  RUN npm install --prefer-offline --no-audit --legacy-peer-deps
7
7
 
8
- COPY . .
8
+ RUN npm run backend:build
9
+
10
+ WORKDIR /app/.generated-backend
11
+
12
+ RUN npm install --prefer-offline --no-audit --legacy-peer-deps
9
13
  RUN npm run build
10
14
 
11
15
  RUN if [ -d templates ]; then cp -r templates .medusa/server/; fi
@@ -16,11 +20,12 @@ WORKDIR /app
16
20
 
17
21
  ENV NODE_ENV=production
18
22
 
19
- COPY --from=builder /app/.medusa/server ./
20
- COPY --from=builder /app/medusa-config.ts ./medusa-config.ts
21
- COPY --from=builder /app/config ./config
22
- COPY --from=builder /app/package.json ./package.json
23
- COPY --from=builder /app/package-lock.json* ./
23
+ COPY --from=builder /app/.generated-backend/.medusa/server ./
24
+ COPY --from=builder /app/.generated-backend/medusa-config.ts ./medusa-config.ts
25
+ COPY --from=builder /app/.generated-backend/config ./config
26
+ COPY --from=builder /app/.generated-backend/src ./src
27
+ COPY --from=builder /app/.generated-backend/package.json ./package.json
28
+ COPY --from=builder /app/.generated-backend/package-lock.json* ./
24
29
 
25
30
  RUN npm install --omit=dev --prefer-offline --no-audit --legacy-peer-deps \
26
31
  && npm install --save-prod ts-node typescript --prefer-offline --no-audit --legacy-peer-deps
@@ -7,15 +7,17 @@ alwaysApply: true
7
7
 
8
8
  ```
9
9
  <project>/
10
- backend/ Medusa v2 API + Admin
11
- storefront/ Segment-based Next.js (config client)
10
+ backend/ Config-only Medusa client .generated-backend/
11
+ storefront/ Config-only Next.js client → .generated-app/
12
12
  ```
13
13
 
14
+ Both folders are **config clients**. Generated code is gitignored.
15
+
14
16
  ## Dev (local Node)
15
17
 
16
18
  ```bash
17
- npm run dev:backend # terminal 1
18
- npm run dev:storefront # terminal 2
19
+ npm run dev:backend # terminal 1 — backend-build + medusa develop
20
+ npm run dev:storefront # terminal 2 — storefront-build + next dev
19
21
  ```
20
22
 
21
23
  ## Dev (Docker)
@@ -31,7 +33,7 @@ See `Makefile` and command `docker-dev`.
31
33
  ## First-time backend
32
34
 
33
35
  1. Set `DATABASE_URL` in `backend/.env`
34
- 2. `npm run dev:backend` (migrations)
36
+ 2. `npm run dev:backend` (generates backend + migrations)
35
37
  3. `npm run seed` (region, API key, sample product)
36
38
  4. Run `npm run seed` from project root (syncs publishable key to `storefront/.env.local` via Postgres)
37
39
 
@@ -42,14 +44,16 @@ npm run build:backend
42
44
  npm run build:storefront
43
45
  ```
44
46
 
45
- ## Where to edit
47
+ ## Where to edit (committed source only)
46
48
 
47
49
  | Goal | Path |
48
50
  |------|------|
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) |
51
+ | Medusa plugins + versions | `backend/plugins.config.json` |
52
+ | Backend preset / region | `backend/backend.config.json` |
53
+ | Homepage admin fields | driven by `storefront/pages.config.json` synced on `storefront:build` |
52
54
  | Storefront sections | `storefront/pages.config.json` |
53
55
  | Brand colors | `storefront/theme-overrides.css` |
54
56
 
57
+ **Never edit** `backend/.generated-backend/` or `storefront/.generated-app/` — regenerated every dev/build.
58
+
55
59
  Cursor guides live in `backend/.cursor/` and `storefront/.cursor/`.
@@ -24,7 +24,7 @@ This folder (`storefront/`) is a **config client**, not a hand-written Next.js a
24
24
  |------|---------|
25
25
  | `.generated-app/` | Full Next.js app from `storefront-build` |
26
26
 
27
- Homepage content (hero, promo, logo, etc.) comes from Medusa `GET /store/dynamic-config`. The **schema** in `../backend/config/homepage-config.json` is updated automatically when you run `npm run storefront:build` after changing `pages.config.json`.
27
+ Homepage content (hero, promo, logo, etc.) comes from Medusa `GET /store/dynamic-config`. The **schema** in `../backend/.generated-backend/config/homepage-config.json` is updated automatically when you run `npm run storefront:build` after changing `pages.config.json`.
28
28
 
29
29
  After any change to config, deps, or `theme-overrides.css`:
30
30
 
@@ -93,8 +93,9 @@ make clean # remove containers + volumes
93
93
  |------|--------|
94
94
  | Home sections | `storefront/pages.config.json` |
95
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` (auto-synced on `storefront:build`) |
96
+ | Medusa plugins | `backend/plugins.config.json` |
97
+ | Plugin preset / region | `backend/backend.config.json` |
98
+ | Homepage admin fields | auto-synced to `backend/.generated-backend/config/` on `storefront:build` |
98
99
  | Docker secrets | `docker/.env` |
99
100
 
100
101
  Cursor guides: `.cursor/` in each folder.
@@ -4,3 +4,5 @@ node_modules
4
4
  .env
5
5
  .env.local
6
6
  docker/.env
7
+ backend/.generated-backend
8
+ storefront/.generated-app