Skip to content

Configure Sync System

Learn how to use the Pika Framework sync system to receive updates from the framework repository while preserving your custom code and configurations.

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
  • A Pika project set up locally
  • Basic understanding of git
  • Familiarity with your customization areas
  • Node.js and pnpm installed

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.

  1. Downloads Latest Framework: Gets latest code from GitHub
  2. Compares Changes: Identifies differences between your project and framework
  3. Smart Merging: Preserves protected areas and your customizations
  4. Package.json Intelligence: Intelligently merges dependencies and scripts
  5. Handles Conflicts: Asks you how to resolve conflicts

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

The sync system uses glob patterns to match files.

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
]
PatternMatchesDoesn't Match
services/custom/services/custom/api.ts<br>services/custom/auth/config.tsservices/custom-api/
pika-config.tspika-config.ts<br>apps/chat/pika-config.tspika-config.backup.ts
.env*.env<br>.env.local<br>.env.productioncustom.env

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"
]
}

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

The following areas are automatically protected:

  • apps/pika-chat/src/lib/client/features/chat/message-segments/custom-components/
  • apps/pika-chat/src/lib/server/auth-provider/
  • services/custom/
  • apps/custom/
  • .env, .env.local, .env.*
  • pika-config.ts
  • .pika-sync.json
  • .gitignore, package.json, pnpm-lock.yaml

See what would be updated without applying changes:

Terminal window
pika sync --dry-run

Output shows:

  • Files that would be updated
  • Files that would be added
  • Files that would be deleted
  • Protected files being preserved
Terminal window
pika sync --diff

Shows line-by-line changes for each file.

Terminal window
pika sync --visual-diff

Opens diffs in your IDE (Cursor or VS Code) for visual review.

Terminal window
pika sync

Downloads and applies framework updates.

Terminal window
pika sync --debug

Enables detailed logging for troubleshooting.

Terminal window
pika sync --branch develop

Sync from a different framework branch.

The sync system intelligently merges package.json files.

  1. Compares Top-Level Attributes: Analyzes each attribute
  2. Preserves Your Additions: Your custom scripts/dependencies stay
  3. Adds Framework Additions: New framework scripts/dependencies added
  4. Resolves Conflicts: Framework version wins for conflicts

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
}
}

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)

When you modify files outside protected areas, sync detects and asks what to do.

For each modified file:

  1. Overwrite: Use framework version (lose your changes)
  2. Protect: Add file to userProtectedAreas
  3. Skip: Skip for now (will ask again next sync)
  4. Cancel: Cancel entire sync operation
File 'apps/pika-chat/src/routes/+page.svelte' has been modified.
What would you like to do?
1. Overwrite with framework version
2. Protect this file (add to userProtectedAreas)
3. Skip this file for now
4. Cancel sync
Enter your choice (1-4): 2
Added 'apps/pika-chat/src/routes/+page.svelte' to userProtectedAreas
Terminal window
# 1. Check current status
pika sync --dry-run
# 2. Review changes in detail
pika sync --diff
# 3. Review visually (optional)
pika sync --visual-diff
# 4. Apply updates
pika sync
# 5. Test your application
pnpm run dev
# 6. Commit sync results
git add .
git commit -m "chore: sync with pika framework v1.2.0"
Terminal window
# Create a branch for the sync
git checkout -b sync-pika-v2
# Preview changes
pika sync --dry-run
# Apply sync
pika sync
# Test thoroughly
pnpm run test
pnpm run build
# Merge if successful
git checkout main
git merge sync-pika-v2
Terminal window
# Sync weekly or monthly
pika sync --dry-run # Check what's new
pika sync # Apply if ready

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/"
]
}

Name custom files/directories with custom- prefix for automatic protection:

services/
├── pika/ # Framework code, will sync
└── custom-api/ # Your code, auto-protected
Terminal window
# After sync, always test
pika sync
# Run tests
pnpm run test
# Check build
pnpm run build
# Test locally
pnpm run dev
Terminal window
# Commit sync configuration
git add .pika-sync.json
git commit -m "chore: update sync configuration"
# Commit sync results
git add .
git commit -m "chore: sync with pika v1.2.0"

The sync system handles samples intelligently:

  • services/samples/weather - Sample weather service
  • apps/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

Verify sync system working correctly:

  • Check file is in userProtectedAreas
  • Verify pattern matches file path
  • Use --debug to see why file not protected
  • Add to userProtectedAreas if needed
  • Ensure using pika sync command (not manual file copy)
  • Check interactive prompts and answer 'Y'
  • Review sync output for package.json processing
  • Verify dependencies still present after sync
  • Review file diff carefully
  • Choose appropriate resolution option
  • Consider protecting file if repeatedly conflicts
  • Document why file protected
Terminal window
# Install pika CLI globally
npm install -g pika-cli
# Or use via npx
npx pika sync