跳过内容

CLI 入门指南

Capgo CLI 提供了一个交互式引导程序,用于设置您的 Capacitor 应用的实时更新。您将:

  1. ✅ 在 Capgo 中注册您的应用
  2. 🔌 安装和配置更新插件
  3. 🚀 部署您的第一个实时更新
  4. 📱 在设备上测试更新

__CAPGO_KEEP_0__ 估计时间:

整个引导过程都是可恢复的 - 任何时候都可以退出并从您离开的地方继续。

开始引导

Run the onboarding command with your API key:

使用您的 __CAPGO_KEEP_0__ 密钥运行引导命令:
npx @capgo/cli@latest init [APIKEY]

复制到剪贴板

Capgo onboarding 🛫

注册过程

注册过程

The CLI will guide you through 13 interactive steps:

设置阶段(步骤1-6):

  • 检查开发环境(Xcode/Android Studio)
  • 将您的应用程序添加到Capgo并创建生产频道
  • 安装 @capgo/capacitor-updater 插件
  • 将所需的code注入您的应用程序
  • 可选:启用端到端加密
  • 选择测试平台(iOS或Android)

测试阶段(步骤7-12):

  • 在设备/模拟器上构建并运行您的应用
  • 做一个可见的 code 变更(自动或手动)
  • 将更新的捆绑包上传到 Capgo
  • 在实时看到您的设备上更新的效果

完成(步骤13):

  • 您的应用已准备好实时更新! 🎉

步骤1:检查前置条件

步骤1:检查前置条件的标题

CLI 检查您的开发环境以确保已安装必要的工具。

已檢查的項目:

  • Xcode (macOS only) - iOS 開發用
  • Android SDK - Android 開發用

可能的結果:

找到兩個環境:

✅ Xcode detected - iOS development ready
✅ Android SDK detected - Android development ready

⚠️ 未找到環境:

⚠️ Xcode not found
⚠️ Android SDK not found
❌ No development environment detected
📱 To develop mobile apps with Capacitor, you need:
• For iOS: Xcode (macOS only) - https://developer.apple.com/xcode/
• For Android: Android Studio - https://developer.android.com/studio

可能會被問到的問題:

步骤 2:添加您的应用

步骤 2:添加您的应用

CLI 将登录到 Capgo 并将您的应用添加到您的帐户中。

(spinner) Running: npm @capgo/cli@latest login ***
Login Done ✅
❓ Add {appId} in Capgo?

如果您的应用 ID 已经被占用:

CLI 将建议替代方案:

❌ App ID "com.example.app" is already taken
💡 Here are some suggestions:
1. com.example.app2
2. com.example.app3
3. com.example.app.new
4. com.example.app.app
❓ What would you like to do?

您可以选择建议的替代方案或输入自定义应用 ID。

Step 3: 创建生产渠道

Step 3: 创建生产渠道

渠道允许您管理应用程序的不同更新流。

❓ Create default channel production for {appId} in Capgo?

如果您选择是:

(spinner) Running: npm @capgo/cli@latest channel add production {appId} --default
Channel add Done ✅ (or "Channel already added ✅")

将会创建一个生产频道并将其设置为默认频道。这是大多数用户的推荐选项。

如果您选择否:

If you change your mind, run it for yourself with: "npm @capgo/cli@latest channel add production {appId} --default"

您需要在以后手动创建和配置频道。或者,您可以:

  • 在您的 capacitor.config.ts 文件
  • 使用 JavaScript setChannel() 方法动态设置频道
  • 从Capgo web 控制台中稍后配置频道

步骤 4: 安装更新插件

步骤 4: 安装更新插件

将会安装兼容你的CLI版本的插件。 @capgo/capacitor-updater 插件兼容你的Capacitor版本。

❓ Automatic Install "@capgo/capacitor-updater" dependency in {appId}?

版本兼容性:

  • Capacitor 5:安装v5 @capgo/capacitor-updater __CAPGO_KEEP_0__ 6:安装
  • Capacitor 6__CAPGO_KEEP_0__ 7:安装 @capgo/capacitor-updater v7
  • Capacitor 8:安装v8 @capgo/capacitor-updater v7
  • Capacitor 8+安装最新版本:

即时更新选项:

安装后,您将被询问:

❓ Do you want to set instant updates in {appId}?
Read more: https://capgo.app/docs/live-updates/update-behavior/#applying-updates-immediately

如果您选择是:

  • 更新将配置为在应用程序后台和重新打开时立即应用
  • autoUpdate: 'always'autoSplashscreen: true 将添加到您的配置中
  • 您的 capacitor.config.ts 将自动更新
  • 增量更新 将自动启用 - 这样只会发送更新之间变化的文件,而不是整个捆绑包,从而使更新速度大大提高

如果您选择否:

  • 更新将使用标准行为(在后台下载,下一次重启时应用)
  • 您始终可以通过修改您的配置来启用即时更新 capacitor.config.ts

第 5 步:添加集成 Code

第 5 步:添加集成 Code

集成 CLI 将自动将所需的 code 注入到主应用文件中。

❓ Automatic Add "CapacitorUpdater.notifyAppReady()" code and import in {appId}?

添加的内容:

import { CapacitorUpdater } from '@capgo/capacitor-updater'
CapacitorUpdater.notifyAppReady()

项目类型检测:

  • Nuxt.js:创建 plugins/capacitorUpdater.client.ts
  • 其他框架:添加到主入口文件

步骤6:设置加密(可选)

步骤 6:设置加密(可选)

端到端加密为您的更新添加了额外的安全层。

🔐 End-to-end encryption
✅ Use this for: Banking, healthcare, or apps with legal encryption requirements
⚠️ Note: Makes debugging harder - skip if you don't need it
❓ Enable end-to-end encryption for {appId} updates?

如果您启用加密,CLI 将:

  1. 生成加密密钥
  2. 提供同步 Capacitor 配置的选项

步骤 7:选择平台

📱 Platform selection for onboarding
This is just for testing during onboarding - your app will work on all platforms
❓ Which platform do you want to test with during this onboarding?
Options:
- iOS
- Android

步骤 8:构建您的项目

步骤 8:构建您的项目

CLI 将构建您的应用程序并将其同步到 Capacitor。

❓ Automatic build {appId} with "npm run build"?

发生了什么:

  1. 检测您的项目类型
  2. 运行您的构建脚本
  3. 执行 npx cap sync {platform}

如果构建脚本丢失:

您将被询问是否要跳过构建或添加一个构建脚本到您的 package.json.

第 9 步:在设备上运行

标题为“第 9 步:在设备上运行”

在设备或模拟器上测试您的应用的初始版本。

❓ Run {appId} on {PLATFORM} device now to test the initial version?

如果您选择 :

(spinner) Running: npx cap run {platform}
(device picker appears)
App started ✅
📱 Your app should now be running on your {platform} device with Capgo integrated
🔄 This is your baseline version - we'll create an update next

第 10 步:进行测试更改

标题为“第 10 步:进行测试更改”

现在是时候测试Capgo的更新系统了,通过进行一个可见的更改。

🎯 Now let's test Capgo by making a visible change and deploying an update!
❓ How would you like to test the update?
Options:
- Auto: Let Capgo CLI make a visible change for you
- Manual: I'll make changes myself

自动模式: The CLI will automatically modify your files to add a visible test banner or change.

手动模式: 您自己进行修改(例如,改变文本、颜色或添加元素)。

版本处理:

❓ How do you want to handle the version for this update?
Options:
- Auto: Bump patch version ({currentVersion} → {nextVersion})
- Manual: I'll provide the version number

使用修改的内容构建:

❓ Build {appId} with changes before uploading?

步骤 11: 上传捆绑包

步骤 11: 上传捆绑包

将您的更新后的应用捆绑包上传到 Capgo。

❓ Upload the updated {appId} bundle (v{version}) to Capgo?

CLI 运行:

终端窗口
npx @capgo/cli@latest bundle upload

Delta更新提示(如果启用了即时应用模式):

💡 Instant updates are enabled in your config
Delta updates send only changed files instead of the full bundle
❓ Enable delta updates for this upload? (Recommended with instant updates)

成功:

✅ Update v{version} uploaded successfully!
🎉 Your updated bundle is now available on Capgo

第 12 步:在设备上测试更新

第 12 步:在设备上测试更新

亲眼见到更新的效果!

🧪 Time to test the Capgo update system!
📱 Go to your device where the app is running

实时更新:

🔄 IMPORTANT: Background your app (swipe up/press home button) and then reopen it
⏱️ The update should be downloaded and applied automatically

标准更新:

📱 With standard updates, you will need to:
1. Background the app (swipe up/press home button) to start download
2. Wait a few seconds for download to complete
3. Background and foreground again to see the update

监控日志:

❓ Monitor Capgo logs to verify the update worked?

如果您选择 ,您将看到从设备实时显示的更新过程日志。

第 13 步:完成

第 13 步:完成
Welcome onboard ✈️!

恭喜!您成功设置了Capgo实时更新功能。

您已经完成的工作

标题:您已经完成的工作

完成入门流程后,您已经完成以下工作:

✅ 应用程序已注册

您的应用程序已在Capgo中注册,生产频道

✅ 插件已安装

已安装并配置Capacitor更新器插件

✅ Code已集成

已添加code集成到您的应用程序

✅ 更新已测试

您已成功部署并接收到实时更新

对于后续的更新,请使用:

终端窗口
npm run build
npx @capgo/cli@latest bundle upload --channel=production

更多部署选项,请参见 实时更新部署.

如果您退出入门过程,可以随时恢复:

终端窗口
npx @capgo/cli@latest init [APIKEY]

您会看到:

You have already got to the step {stepNumber}/13 in the previous session
❓ Would you like to continue from where you left off?

故障排除

故障排除部分

没有开发环境

没有开发环境部分

问题: Xcode或Android SDK 未检测到。

解决方案:

应用 ID 已经被占用

标题:应用 ID 已经被占用

问题: 您的应用 ID 已经注册过了。

translations.0 translations.1

translations.2

translations.3

translations.4 translations.5 package.json.

translations.6 translations.7 package.json:

{
"scripts": {
"build": "your-build-command"
}
}

translations.9

translations.10

translations.11 CLI 不能自动注入code

解决方案: 手动将code添加到主文件中:

import { CapacitorUpdater } from '@capgo/capacitor-updater'
CapacitorUpdater.notifyAppReady()

Capacitor版本过低

标题:Capacitor版本过低

问题: 您的Capacitor版本低于v5。

解决方案: 将Capacitor升级到v5或更高版本:

您已经完成了入门流程后,探索这些主题:

获取帮助

获取帮助

如果您在入门过程中遇到问题:

如果您正在使用 CLI 入门指南 来规划仪表板和API 操作,连接它到 API 概览 查看API 概览中的实施细节 简介 简介中的实现细节 API Keys API Keys中的实现细节 设备 简介中的实现细节 设备 简介中的实现细节