@hszrdm/create-commerce
v1.29.0
Published
Create a complete HSZRDM Commerce webshop project.
Downloads
7,163
Readme
@hszrdm/create-commerce
Creates a complete standalone HSZRDM Commerce webshop project.
npx @hszrdm/create-commerce my-shopThe generator creates:
- a Medusa backend powered by
@hszrdm/core; - a client-owned Next.js storefront;
- random application and integration secrets;
- Medusa + Core migrations;
- Store / Region / Sales Channel / Stock Location bootstrap;
- a publishable storefront API key linked to the Sales Channel;
- the first HSZRDM Commerce admin user;
- backend/storefront typecheck, test and build verification;
- Git initialization with generated build artifacts ignored;
- production deployment, backup and restore assets.
Generated project structure includes:
my-shop/
├── backend/
├── storefront/
├── deploy/
│ ├── install.sh
│ ├── deploy.sh
│ ├── backup.sh
│ └── restore.sh
├── ecosystem.config.cjs
├── docker-compose.yml
├── hszrdm-commerce.json
├── package.json
└── README.mdThe deploy/ directory and ecosystem.config.cjs are materialized automatically during the first npm install. If the generator is run with --skip-install, running npm install later creates them.
Core upgrades and customer-owned frontends
Backend Core is the versioned @hszrdm/core npm dependency. The customer
adds Medusa modules, APIs, workflows, jobs and subscribers under
backend/src/project/. The generator's prepare:project step exposes them
through standard Medusa paths without duplicating the Core implementation.
Reference frontend lives under starters/storefront-next/ in the Core
repository. Each generated storefront/ is customer-owned: the customer
can build their own branding, layouts and pages. Changing or releasing the
reference frontend does not automatically overwrite customer files.
Backend upgrades and frontend synchronization are separate operations.
Run them in a clean Git checkout on a feature branch, not the live VPS.
First publish matching @hszrdm/core and @hszrdm/create-commerce versions.
1. Upgrade Core backend independently
npx @hszrdm/create-commerce@<new-version> upgrade --dir .
# Review the UPDATE, REVIEW and CONFLICT output:
npx @hszrdm/create-commerce@<new-version> upgrade --dir . --apply
npm ci
npm run verify
git diff --checkThe backend command updates verified, unchanged starter infrastructure,
package versions (including older shops that pin Core at workspace and root
level), the Core-owned npm root security overrides, and the lockfile. It
preserves backend/src/project/ and customer-owned files. Production backup entry points (deploy/backup.sh and backend/scripts/production-assets/backup.sh) always remain customer-owned and appear as REVIEW even when an older manifest tracks them, because automatic replacement could switch the backup format or environment contract. Changed or
untracked backend starter overlays are kept unchanged and marked REVIEW
for compatibility checks. Unsafe paths, mismatched Core pins and overridden
security pins are CONFLICT and block application. Never deploy before
resolving compatibility reviews and running the full test suite.
The backend command deliberately does not modify storefront/ or
storefront/package.json. Updating the backend package and database
migrations does not, by itself, guarantee custom frontend compatibility.
2. Compare and optionally sync the reference frontend
npx @hszrdm/create-commerce@<new-version> frontend:sync --dir .
# Optional unified diffs for modified client files:
npx @hszrdm/create-commerce@<new-version> frontend:sync --dir . --diff
# Explicit opt-in: copies only provably unmodified reference files and
# adds missing reference files; leaves customer-modified paths untouched.
npx @hszrdm/create-commerce@<new-version> frontend:sync --dir . --apply
npm ci
npm run verify
git diff --checkThe preview lists SAFE files, REVIEW customer changes and
PACKAGE REVIEW Next/React dependency differences. Existing customer edits
and deleted files with known baselines are never force-restored. The frontend
package dependencies, theme, layout and any modified pages/components remain
owned by the customer and must be reconciled manually where necessary.
The preview/apply does not bump hszrdm-commerce.json Core backend version,
touch the DB, change secrets or deploy anything.
The hszrdm-managed.json manifest stores the last accepted file hashes;
frontend baselines are not falsely advanced by a backend-only upgrade.
Avoid re-baselining modified customer files as if they were canonical.
New projects expose npm run upgrade:core and npm run sync:frontend
as previews, with npm run <script> -- --apply for the explicit operation.
For reproducible releases pin the generator version, not @latest.
3. Review, commit and deploy
Commit package.json, package-lock.json, backend/,
storefront/, hszrdm-commerce.json and hszrdm-managed.json only
after reviewing all changes and passing npm run verify. Test checkout,
payments, order fulfillment, shipping and customer modules in staging, then
deploy the committed customer branch.
Legacy shops without a reliable manifest must not treat customized
starter files as Core-owned. Run previews first and manually review existing
overlays. Never use --force to regenerate an existing webshop.
Production commands
Fresh server install
On a new VPS/server, deploy/install.sh can bootstrap the production environment automatically.
bash deploy/install.shIf backend/.env does not exist, the installer:
- copies the canonical
backend/.env.exampletobackend/.env; - reads project identity from
hszrdm-commerce.json; - asks for PostgreSQL, Redis, public backend URL and public storefront URL;
- generates fresh JWT, cookie, integration-encryption and shipping-webhook secrets;
- fills store identity, CORS, SEO and default project e-mail values;
- creates
storefront/.env.localfrom the storefront env example; - runs
env:verify, migrations and Core bootstrap; - creates a Store API publishable key when the storefront does not already have one;
- builds and starts/reloads the apps through PM2;
- runs backend/storefront healthchecks.
If backend/.env or storefront/.env.local already exists, the installer preserves them instead of regenerating secrets.
For non-interactive/server automation, supply the server-specific values through:
HSZRDM_INSTALL_DATABASE_URL='postgres://...' \
HSZRDM_INSTALL_REDIS_URL='redis://...' \
HSZRDM_INSTALL_BACKEND_URL='https://api.example.com' \
HSZRDM_INSTALL_STOREFRONT_URL='https://example.com' \
HSZRDM_INSTALL_UPLOAD_DIR='/var/lib/hszrdm-commerce/my-shop/uploads' \
bash deploy/install.shHSZRDM_INSTALL_UPLOAD_DIR is optional. Its default is /var/lib/hszrdm-commerce/<project-slug>/uploads.
Normal deployment
bash deploy/deploy.shThe deploy script creates a backup first, pulls with git pull --ff-only, installs exact dependencies, verifies the env contract, runs migrations/Core init, builds, reloads PM2 and performs healthchecks.
Manual backup
bash deploy/backup.shRestore an existing webshop
bash deploy/restore.sh /path/to/hszrdm-commerce-YYYYMMDDTHHMMSSZ.tar.gz --yesFor an existing webshop moved to another VPS, use restore, not a fresh env bootstrap. Restore brings back the original backend/storefront env files, database, encrypted Core runtime state and uploads. This preserves encryption keys and existing integration credentials.
Backups contain the PostgreSQL dump, backend/storefront environment files, encrypted Core runtime state and uploaded files when present. Backup archives therefore contain secrets and customer data and must be stored securely.
The default local backup retention is 5 archives. It can be changed with:
HSZRDM_BACKUP_RETENTION=10 bash deploy/backup.shA different backup directory can be supplied with HSZRDM_BACKUP_DIR.
PostgreSQL and Redis
Docker is optional.
Use an existing PostgreSQL + Redis pair:
npx @hszrdm/create-commerce my-shop \
--database-url "postgres://user@localhost:5432/my_shop" \
--redis-url "redis://localhost:6379"When both URLs are provided, Docker is not used.
If no external URLs are provided, Docker Compose is the convenience fallback and starts isolated PostgreSQL and Redis services when Docker is available.
The two external connection options must always be supplied together.
Non-interactive example
npx @hszrdm/create-commerce my-shop \
--database-url "postgres://user@localhost:5432/my_shop" \
--redis-url "redis://localhost:6379" \
--admin-email "[email protected]" \
--non-interactiveIf no admin password is supplied, the generator creates a random password and prints it once at the end. It is not written to project metadata.
Use --help for all options.
