mirror of
https://github.com/hanzo-apps/cms.git
synced 2026-10-30 14:47:33 +00:00
- payload -> @hanzo/cms (core), bin payload -> hanzo-cms - create-payload-app -> @hanzo/create-cms-app - @payloadcms/<x> -> @hanzo/cms-<x> across the whole dependency graph - 3545 files, 72 package.json, 4419 scoped refs, 3852 core import specifiers, 82 scss imports - MIT attribution to Payload CMS Inc. preserved (LICENSE.md, author emails) Upstream: github.com/payloadcms/payload @ v3.85.2 (MIT)
3.7 KiB
3.7 KiB
@hanzo/create-cms-app
Package for creating new Payload projects with custom configurations.
Architecture
AST-Based File Modification
@hanzo/create-cms-app uses AST (Abstract Syntax Tree) parsing with ts-morph to modify template files during project creation.
3-Phase Pipeline:
- Detection - Parse files and locate expected structures
- Transformation - Pure functions modify AST
- Modification - Validate, write, format with prettier
File Structure
src/lib/ast/
├── types.ts # Shared types for AST operations
├── utils.ts # Low-level AST helpers
├── utils.spec.ts # Unit tests for utils
├── payload-config.ts # Payload config transformations
├── payload-config.spec.ts # Unit tests for payload-config
├── package-json.ts # package.json modifications
└── package-json.spec.ts # Unit tests for package-json
Key Functions
High-level API:
configurePayloadConfig(filePath, options)- Main entry point for payload configupdatePackageJson(filePath, options)- Update package.json
Transformations:
addDatabaseAdapter(sourceFile, adapter, envVar)- Add/replace db adapteraddStorageAdapter(sourceFile, adapter)- Add storage pluginremoveSharp(sourceFile)- Remove sharp dependency
Templates
All templates follow standard structure:
buildConfig()call with object literal argumentdbproperty for database adapterpluginsarray (can be empty)
No comment markers needed - AST finds structure by code patterns.
Package Management Flows
@hanzo/create-cms-app has two distinct flows for handling package installation:
Flow 1: --init-next (Next.js Integration)
sequenceDiagram
participant CLI
participant initNext
participant FS as File System
participant PM as Package Manager
participant AST as AST Operations
CLI->>initNext: --init-next with dbType
initNext->>FS: Copy template files
initNext->>PM: pnpm add payload @hanzo/cms-next @hanzo/cms-db-{type}
PM->>FS: Install packages to node_modules
initNext->>AST: configurePayloadConfig(filePath, {db})
AST->>FS: Update payload.config.ts (imports/config)
AST->>FS: Update package.json (dependencies)
initNext->>CLI: ✓ Project ready
Key points:
- Uses
pnpm addto install specific packages - Packages installed before AST modifications
- No final
pnpm installstep
Flow 2: Template/Example Creation
sequenceDiagram
participant CLI
participant createProject
participant FS as File System
participant AST as AST Operations
participant PM as Package Manager
CLI->>createProject: --template with dbType
createProject->>FS: Copy template/example files
createProject->>AST: configurePayloadConfig(projectDir, {db})
AST->>FS: Update payload.config.ts (imports/config)
AST->>FS: Update package.json (dependencies)
createProject->>PM: pnpm install
PM->>FS: Install packages from package.json
createProject->>CLI: ✓ Project ready
Key points:
- Updates package.json first
- Single
pnpm installat end installs all dependencies - Package manager resolves dependencies from package.json
Package Operations:
- Install: Runs actual
pnpm addorpnpm installcommand (Flow 1 or Flow 2 respectively) - Package removal: AST removes imports and updates package.json (orphaned packages cleaned up on next install)
- No explicit
pnpm remove- package.json modifications only
Testing
Unit tests: Test individual transformation functions Integration tests: Test full @hanzo/create-cms-app flows
Run tests: pnpm --filter @hanzo/create-cms-app test