Learn how to use the Pika Framework sync system to receive updates from the framework repository while preserving your custom code and configurations.
What You'll Accomplish
Section titled “What You'll Accomplish”By the end of this guide, you will:
- Understand how the sync system works
- Configure protected and unprotected areas
- Use sync commands effectively
- Handle package.json merging
- Manage file conflicts during sync
- Follow best practices for framework updates
Prerequisites
Section titled “Prerequisites”- A Pika project set up locally
- Basic understanding of git
- Familiarity with your customization areas
- Node.js and pnpm installed
Understanding the Sync System
Section titled “Understanding the Sync System”Your Pika project is a fork of the Pika framework that you can version control. The sync system intelligently merges framework updates with your changes.
How It Works
Section titled “How It Works”- Downloads Latest Framework: Gets latest code from GitHub
- Compares Changes: Identifies differences between your project and framework
- Smart Merging: Preserves protected areas and your customizations
- Package.json Intelligence: Intelligently merges dependencies and scripts
- Handles Conflicts: Asks you how to resolve conflicts
Protection System
Section titled “Protection System”Multiple layers protect your work:
- Default Protected Areas: Core customization directories
- Custom Protection: Paths starting with
custom-automatically protected - User Protected Areas: Additional files you specify
- User Unprotected Areas: Protected files you explicitly allow to sync
Step 1: Understand Protection Patterns
Section titled “Step 1: Understand Protection Patterns”The sync system uses glob patterns to match files.
Pattern Types
Section titled “Pattern Types”Directory Patterns - End with / to protect entire subtree:
"userProtectedAreas": [ "services/custom/", // Protects entire directory "services/custom/**" // Alternative syntax]Exact Path Patterns - Specific file protection:
"userProtectedAreas": [ "apps/pika-chat/my-file.ts" // Specific file only]Filename Patterns - Match anywhere in project:
"userProtectedAreas": [ "cdk.context.json", // All files with this name ".env", // All .env files ".env*" // All files starting with .env]Pattern Matching Examples
Section titled “Pattern Matching Examples”| Pattern | Matches | Doesn't Match |
|---|---|---|
services/custom/ | services/custom/api.ts<br>services/custom/auth/config.ts | services/custom-api/ |
pika-config.ts | pika-config.ts<br>apps/chat/pika-config.ts | pika-config.backup.ts |
.env* | .env<br>.env.local<br>.env.production | custom.env |
Step 2: Configure Sync Settings
Section titled “Step 2: Configure Sync Settings”Edit .pika-sync.json to customize sync behavior.
Location: .pika-sync.json (root directory)
{ "pikaVersion": "1.0.0", "createdAt": "2024-01-01T00:00:00.000Z", "lastSync": "2024-01-01T00:00:00.000Z",
"protectedAreas": [ // Framework-managed, don't edit ],
"userProtectedAreas": [ // Your additional protected files "my-custom-config.ts", "apps/my-custom-app/", "services/api/my-service.ts", "Dockerfile", ".env.production" ],
"userUnprotectedAreas": [ // Protected files you want to allow updates for "package.json", "pnpm-lock.yaml" ]}Configuration Sections
Section titled “Configuration Sections”protectedAreas
- Framework-managed list
- Don't edit this section
- Updated automatically by framework
userProtectedAreas
- Additional files you want to protect
- Supports glob patterns
- Your customizations persist here
userUnprotectedAreas
- Default protected files you want to allow updates for
- Removes items from default protected list
- Use exact pattern strings from
protectedAreas
Step 3: Default Protected Areas
Section titled “Step 3: Default Protected Areas”The following areas are automatically protected:
Core Customization Areas
Section titled “Core Customization Areas”apps/pika-chat/src/lib/client/features/chat/message-segments/custom-components/apps/pika-chat/src/lib/server/auth-provider/services/custom/apps/custom/
Configuration Files
Section titled “Configuration Files”.env,.env.local,.env.*pika-config.ts.pika-sync.json.gitignore,package.json,pnpm-lock.yaml
Automatic Protection
Section titled “Automatic Protection”Step 4: Use Sync Commands
Section titled “Step 4: Use Sync Commands”Preview Changes
Section titled “Preview Changes”See what would be updated without applying changes:
pika sync --dry-runOutput shows:
- Files that would be updated
- Files that would be added
- Files that would be deleted
- Protected files being preserved
View Detailed Diffs
Section titled “View Detailed Diffs”pika sync --diffShows line-by-line changes for each file.
Visual Diff in IDE
Section titled “Visual Diff in IDE”pika sync --visual-diffOpens diffs in your IDE (Cursor or VS Code) for visual review.
Apply Updates
Section titled “Apply Updates”pika syncDownloads and applies framework updates.
Debug Mode
Section titled “Debug Mode”pika sync --debugEnables detailed logging for troubleshooting.
Sync from Specific Branch
Section titled “Sync from Specific Branch”pika sync --branch developSync from a different framework branch.
Step 5: Handle Package.json Merging
Section titled “Step 5: Handle Package.json Merging”The sync system intelligently merges package.json files.
How It Works
Section titled “How It Works”- Compares Top-Level Attributes: Analyzes each attribute
- Preserves Your Additions: Your custom scripts/dependencies stay
- Adds Framework Additions: New framework scripts/dependencies added
- Resolves Conflicts: Framework version wins for conflicts
Example Merge
Section titled “Example Merge”Your package.json:
{ "name": "my-project", "scripts": { "dev": "vite", "build": "vite build", "my-custom-script": "echo 'custom'" }, "dependencies": { "react": "^18.0.0", "my-custom-package": "^1.0.0" }}Framework package.json:
{ "name": "pika-project", "scripts": { "dev": "vite", "build": "vite build", "test": "vitest" }, "dependencies": { "react": "^18.0.0", "vite": "^5.0.0" }}Result after sync:
{ "name": "pika-project", // Framework wins "scripts": { "dev": "vite", // Same "build": "vite build", // Same "test": "vitest", // Added from framework "my-custom-script": "echo 'custom'" // Preserved }, "dependencies": { "react": "^18.0.0", // Same "vite": "^5.0.0", // Added from framework "my-custom-package": "^1.0.0" // Preserved }}Interactive Confirmation
Section titled “Interactive Confirmation”For each package.json with changes:
Package.json changes detected in apps/pika-chat/package.json: • Modified attributes: name • Added scripts: test • Added dependencies: vite • Your additions will be preserved: my-custom-script, my-custom-package
Apply package.json changes to apps/pika-chat/package.json? (Y/n)Step 6: Resolve File Conflicts
Section titled “Step 6: Resolve File Conflicts”When you modify files outside protected areas, sync detects and asks what to do.
Resolution Options
Section titled “Resolution Options”For each modified file:
- Overwrite: Use framework version (lose your changes)
- Protect: Add file to
userProtectedAreas - Skip: Skip for now (will ask again next sync)
- Cancel: Cancel entire sync operation
Example Interaction
Section titled “Example Interaction”File 'apps/pika-chat/src/routes/+page.svelte' has been modified.What would you like to do?
1. Overwrite with framework version2. Protect this file (add to userProtectedAreas)3. Skip this file for now4. Cancel sync
Enter your choice (1-4): 2
Added 'apps/pika-chat/src/routes/+page.svelte' to userProtectedAreasRecommended Workflow
Section titled “Recommended Workflow”Regular Sync Workflow
Section titled “Regular Sync Workflow”# 1. Check current statuspika sync --dry-run
# 2. Review changes in detailpika sync --diff
# 3. Review visually (optional)pika sync --visual-diff
# 4. Apply updatespika sync
# 5. Test your applicationpnpm run dev
# 6. Commit sync resultsgit add .git commit -m "chore: sync with pika framework v1.2.0"Before Major Changes
Section titled “Before Major Changes”# Create a branch for the syncgit checkout -b sync-pika-v2
# Preview changespika sync --dry-run
# Apply syncpika sync
# Test thoroughlypnpm run testpnpm run build
# Merge if successfulgit checkout maingit merge sync-pika-v2Best Practices
Section titled “Best Practices”Regular Syncing
Section titled “Regular Syncing”# Sync weekly or monthlypika sync --dry-run # Check what's newpika sync # Apply if readyDocument Customizations
Section titled “Document Customizations”Keep a record of why files are protected:
{ "userProtectedAreas": [ // Protected for custom branding "apps/pika-chat/src/routes/+layout.svelte",
// Protected for custom auth integration "apps/pika-chat/src/lib/server/auth-provider/",
// Protected for internal tooling "services/custom/" ]}Use Custom Prefix
Section titled “Use Custom Prefix”Name custom files/directories with custom- prefix for automatic protection:
services/ ├── pika/ # Framework code, will sync └── custom-api/ # Your code, auto-protectedTest After Sync
Section titled “Test After Sync”# After sync, always testpika sync
# Run testspnpm run test
# Check buildpnpm run build
# Test locallypnpm run devVersion Control
Section titled “Version Control”# Commit sync configurationgit add .pika-sync.jsongit commit -m "chore: update sync configuration"
# Commit sync resultsgit add .git commit -m "chore: sync with pika v1.2.0"Sample Applications
Section titled “Sample Applications”The sync system handles samples intelligently:
services/samples/weather- Sample weather serviceapps/samples/enterprise-site- Sample enterprise site
Behavior:
- Synced automatically if you haven't modified them
- Your modifications preserved if you change them
- Not restored if you delete them
- Learn from samples while keeping customizations
Testing Checklist
Section titled “Testing Checklist”Verify sync system working correctly:
Troubleshooting
Section titled “Troubleshooting”Files Being Overwritten
Section titled “Files Being Overwritten”- Check file is in
userProtectedAreas - Verify pattern matches file path
- Use
--debugto see why file not protected - Add to
userProtectedAreasif needed
Package.json Changes Lost
Section titled “Package.json Changes Lost”- Ensure using
pika synccommand (not manual file copy) - Check interactive prompts and answer 'Y'
- Review sync output for package.json processing
- Verify dependencies still present after sync
Sync Conflicts
Section titled “Sync Conflicts”- Review file diff carefully
- Choose appropriate resolution option
- Consider protecting file if repeatedly conflicts
- Document why file protected
Sync Command Not Found
Section titled “Sync Command Not Found”# Install pika CLI globallynpm install -g pika-cli
# Or use via npxnpx pika syncNext Steps
Section titled “Next Steps”- Use Stack Management - Manage infrastructure
- Customize the UI - Protected customization areas
- Troubleshooting - Debug issues
Related Documentation
Section titled “Related Documentation”- Project Structure - Understand project layout
- Customization Guide - Where to customize
- Pika Releases - Framework versions