Skip to content

useAltool

封装 macOS altool 命令行工具的 Hook,用于验证和上传应用到 App Store Connect。

函数签名

typescript
function useAltool(options: AltoolOptions): {
  validate: (filePath: string) => Promise<AltoolResult>
  upload: (filePath: string) => Promise<AltoolResult>
  listProviders: () => Promise<string[]>
  isExecuting: Ref<boolean>
  error: Ref<Error | null>
}

interface AltoolOptions {
  username: string          // Apple ID
  password: string          // 应用专用密码
  teamId?: string          // 团队 ID
  provider?: string        // 提供商
  altoolPath?: string      // altool 路径,默认自动查找
}

interface AltoolResult {
  success: boolean
  output: string
  error?: string
}

参数

参数名类型必填说明
options.usernamestringApple ID(邮箱)
options.passwordstring应用专用密码
options.teamIdstring团队 ID(多团队账号需要)
options.providerstring提供商短名称
options.altoolPathstringaltool 可执行文件路径

返回值

类型说明
{ validate, upload, listProviders, isExecuting, error }Altool 操作对象

工作原理

  1. 查找 altool

    • 如果提供路径,使用指定路径
    • 否则在系统中查找 altool(通常在 Xcode 中)
  2. validate(filePath)

    • 构建验证命令:altool --validate-app -f filePath -u username -p password ...
    • 执行命令
    • 解析输出,检查是否包含错误
    • 返回验证结果
  3. upload(filePath)

    • 构建上传命令:altool --upload-app -f filePath -u username -p password ...
    • 执行命令
    • 解析输出
    • 返回上传结果
  4. listProviders()

    • 执行 altool --list-providers 命令
    • 解析输出获取提供商列表
  5. 状态管理

    • isExecuting: 执行中标志
    • error: 错误信息

需要 macOS 环境和已安装 Xcode 命令行工具。