破坏性更改
复制一个包含安装步骤和此插件的完整 Markdown 指南的配置提示。
本文档解释了如何使用版本通道来处理应用程序中的破坏性更改。这一方法允许您维护应用程序的不同版本,同时确保用户接收兼容的更新。
示例场景
标题为“示例场景”的部分假设您有:
- 应用程序版本 1.2.3(旧版本)- 使用生产通道
- 应用程序版本 2.0.0(新版本,包含破坏性更改)- 使用 v2 通道
- 实时更新 1.2.4 (兼容 1.2.3)
- 实时更新 2.0.1 (兼容 2.0.0)
策略:始终使用defaultChannel为主要版本
标题:策略:始终使用defaultChannel为主要版本推荐方法: 为每个主要版本设置一个 defaultChannel 确保您始终可以将更新推送到特定用户组,而无需依赖动态通道分配。
// Version 1.x releasesdefaultChannel: 'v1'
// Version 2.x releasesdefaultChannel: 'v2'
// Version 3.x releases (future)defaultChannel: 'v3'标题:1. 为新版本创建频道
终端窗口# Create channel for version 2.xnpx @capgo/cli channel create v22. Update Capacitor Config for Version 2.0.0
2. 更新 Capacitor 配置为版本 2.0.0在发布应用商店版本 2.0.0之前,更新您的Capacitor配置:
import { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = { appId: 'com.example.app', appName: 'Example App', plugins: { CapacitorUpdater: { // ... other options defaultChannel: 'v2' // All 2.0.0 users will use v2 channel } }};
export default config;3. 管理独立的Code分支
Section titled “3. 独立管理Code分支”为保持应用程序版本之间的兼容性,创建独立的git分支:
# Create and maintain a branch for version 1.x updatesgit checkout -b v1-maintenancegit push origin v1-maintenance
# Your main branch continues with version 2.x developmentgit checkout main重要提示: 永远不要将JavaScript包推送到期望native code/APIs但没有的旧应用程序。始终从适当的分支中构建更新:
- v1-maintenance branch: 对1.x应用程序的更新(生产频道)
- : 对2.x应用程序的更新(v2频道)4. 将包上传到相应的频道
Section titled “4. 将包上传到相应的频道”
4. 上传包到相应的频道# For 1.x updates: Build from v1-maintenance branchgit checkout v1-maintenance# Make your 1.x compatible changes herenpx @capgo/cli bundle upload --channel production
# For 2.x updates: Build from main branchgit checkout main# Make your 2.x changes herenpx @capgo/cli bundle upload --channel v25. 启用自我赋值
标题:5. 启用自我赋值# Allow apps to self-assign to v2 channelnpx @capgo/cli channel set v2 --self-assign6. 部署到 App Store
标题:6. 部署到 App Store将版本 2.0.0 构建并部署到应用商店。所有下载此版本的用户(新用户或升级的用户)都会自动使用 v2 通道,因为它在应用程序包中配置了。
适应未来的版本
适应未来的版本当您发布3.0.0版本时,带有更多破坏性更改:
# Create channel for version 3.xnpx @capgo/cli channel create v3// capacitor.config.ts for version 3.0.0const config: CapacitorConfig = { // ... plugins: { CapacitorUpdater: { defaultChannel: 'v3' // Version 3.x users } }};现在您可以推送任何版本的更新:
production渠道 → 版本1.x用户v2渠道 → 版本2.x用户v3渠道 → 版本3.x用户
7. 清理 (迁移后)
清理 (迁移后) 部分所有用户都迁移到 2.x 版本后(计 3-4 个月):
- 删除
defaultChannel从您的 Capacitor 配置中 - 删除 v2 频道:
npx @capgo/cli channel delete v2- 删除 v1-maintenance Branch:
git branch -d v1-maintenancegit push origin --delete v1-maintenance始终在每个渠道中彻底测试更新之前部署
维护 1.x 版本更新
标题:维护 1.x 版本更新要发送与 1.x 版本兼容的更新,请执行以下操作:
- 切换到 v1-maintenance Branch:
git checkout v1-maintenance- 确认修改并提交:
# Make 1.x compatible changesgit add .git commit -m "Fix for v1.x"git push origin v1-maintenance- 构建并上传到生产频道:
npx @capgo/cli bundle upload --channel production继续从 Breaking Changes
标题:继续从 Breaking Changes如果您正在使用 重大变更 __CAPGO_KEEP_0__ 频道 频道 频道 频道 Beta 测试解决方案 Beta 测试解决方案中的产品工作流程 版本目标解决方案 版本目标解决方案中的产品工作流程 for the implementation detail in __CAPGO_KEEP_0__, and for the implementation detail in __CAPGO_KEEP_0__