跳转到内容

CLI 入职指南

Capgo CLI 提供交互式入门,为您的 Capacitor 应用程序设置实时更新。你会:

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

预计时间: 10-20 分钟(根据您的互联网速度和构建时间而有所不同)

使用 API 密钥运行入门命令:

Terminal window
npx @capgo/cli@latest init [APIKEY]

您将看到欢迎消息:

Capgo onboarding 🛫

CLI 将引导您完成 13 个互动步骤:

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

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

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

  • 构建您的应用程序并在设备/模拟器上运行它
  • 进行可见的代码更改(自动或手动)
  • 将更新后的捆绑包上传到 Capgo
  • 实时查看您设备上显示的实时更新

完成(步骤 13):

  • 您的应用程序已准备好进行实时更新! 🎉

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

检查内容:

  • Xcode(仅限 macOS)- 用于 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

您可能会被问到的问题:

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。

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

❓ 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 控制台配置通道

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

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

版本兼容性:

  • Capacitor 5:安装 @capgo/capacitor-updater v5
  • Capacitor 6:安装 @capgo/capacitor-updater v6
  • Capacitor 7:安装 @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

如果您选择是:

  • 更新将配置为在应用程序后台运行并重新打开时立即应用
  • directUpdate: 'always'autoSplashscreen: true 将添加到您的配置中
  • 您的 capacitor.config.ts 将自动更新
  • 增量更新将自动启用 - 这仅发送更新之间更改的文件而不是完整的捆绑包,从而使更新速度更快

如果您选择否:

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

CLI 会自动将所需的代码注入到您的主应用程序文件中。

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

添加了什么:

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

项目类型检测:

  • Nuxt.js:创建 plugins/capacitorUpdater.client.ts
  • 其他框架:添加到您的主条目文件中

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

🔐 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 配置

选择在入职期间要测试的平台。

📱 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

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

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

发生了什么:

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

如果缺少构建脚本:

系统会询问您是否要跳过构建或将构建脚本添加到 package.json

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

❓ 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

现在是时候通过进行可见的更改来测试 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

自动模式: CLI 将自动修改您的文件以添加可见的测试横幅或更改。

手动模式: 您可以自行更改(例如,更改文本、颜色或添加元素)。

版本处理:

❓ 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?

将更新后的应用程序包上传到 Capgo。

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

CLI 运行:

Terminal window
npx @capgo/cli@latest bundle upload

Delta 更新提示(如果启用了直接更新):

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

成功:

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

是时候看看更新的实际效果了!

🧪 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?

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

Welcome onboard ✈️!

恭喜!您已成功为您的应用设置 Capgo 实时更新。

完成入职后,您将拥有:

✅ 应用程序已注册

您的应用已通过生产渠道在 Capgo 中注册

✅ 已安装插件

Capacitor 更新程序插件已安装并配置

✅ 代码集成

集成代码已添加到您的应用程序中

✅ 更新已测试

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

对于后续更新,请使用:

Terminal window
npm run build
npx @capgo/cli@latest bundle upload --channel=production

有关更多部署选项,请参阅部署实时更新

如果您退出入职流程,您可以随时恢复:

Terminal window
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。

问题:package.json 中找不到构建脚本。

解决方案: 将构建脚本添加到您的 package.json 中:

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

问题: CLI 无法自动注入集成代码。

解决方案: 将代码手动添加到您的主文件中:

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

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

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

现在您已完成入职培训,请探索以下主题:

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