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.username | string | 是 | Apple ID(邮箱) |
options.password | string | 是 | 应用专用密码 |
options.teamId | string | 否 | 团队 ID(多团队账号需要) |
options.provider | string | 否 | 提供商短名称 |
options.altoolPath | string | 否 | altool 可执行文件路径 |
返回值
| 类型 | 说明 |
|---|---|
{ validate, upload, listProviders, isExecuting, error } | Altool 操作对象 |
工作原理
查找 altool:
- 如果提供路径,使用指定路径
- 否则在系统中查找 altool(通常在 Xcode 中)
validate(filePath):
- 构建验证命令:
altool --validate-app -f filePath -u username -p password ... - 执行命令
- 解析输出,检查是否包含错误
- 返回验证结果
- 构建验证命令:
upload(filePath):
- 构建上传命令:
altool --upload-app -f filePath -u username -p password ... - 执行命令
- 解析输出
- 返回上传结果
- 构建上传命令:
listProviders():
- 执行
altool --list-providers命令 - 解析输出获取提供商列表
- 执行
状态管理:
isExecuting: 执行中标志error: 错误信息
需要 macOS 环境和已安装 Xcode 命令行工具。