| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- #!/bin/bash
- # ============================================
- # Claude AI Installer macOS 构建脚本
- # Build script for macOS using Tauri
- # 此脚本作为 scripts/build.js 的简单入口
- # ============================================
- # 颜色定义
- RED='\033[0;31m'
- GREEN='\033[0;32m'
- YELLOW='\033[0;33m'
- BLUE='\033[0;34m'
- CYAN='\033[0;36m'
- NC='\033[0m' # No Color
- # 切换到脚本所在目录
- cd "$(dirname "$0")"
- # 显示帮助信息
- show_help() {
- echo ""
- echo " Claude AI Installer macOS 构建脚本 (Tauri)"
- echo ""
- echo " 用法:"
- echo " ./build-mac.sh [参数]"
- echo ""
- echo " 参数:"
- echo " --debug, -d 以调试模式构建"
- echo " --skip-frontend, -s 跳过前端构建"
- echo " --target, -t 指定目标架构 (aarch64 或 x86_64)"
- echo " --universal, -u 构建通用二进制 (同时支持 ARM 和 Intel)"
- echo " --help, -h 显示此帮助信息"
- echo ""
- echo " 示例:"
- echo " ./build-mac.sh 完整发布构建 (当前架构)"
- echo " ./build-mac.sh --debug 调试构建"
- echo " ./build-mac.sh -t aarch64 构建 Apple Silicon 版本"
- echo " ./build-mac.sh -t x86_64 构建 Intel 版本"
- echo " ./build-mac.sh --universal 构建通用二进制"
- echo ""
- echo " 输出 (发布模式):"
- echo " src-tauri/target/release/bundle/dmg/*.dmg (DMG 安装包)"
- echo " src-tauri/target/release/bundle/macos/*.app (应用程序)"
- echo " src-tauri/target/release/claude-ai-installer (可执行文件)"
- echo ""
- echo " 输出 (调试模式):"
- echo " src-tauri/target/debug/claude-ai-installer (调试版可执行文件)"
- echo ""
- echo " 前置要求:"
- echo " - Rust (https://rustup.rs/)"
- echo " - Node.js (https://nodejs.org/)"
- echo " - Xcode Command Line Tools"
- echo ""
- echo " 注意: 此脚本调用 scripts/build.js 执行实际构建"
- echo ""
- }
- # 检查是否请求帮助
- if [[ "$1" == "--help" || "$1" == "-h" ]]; then
- show_help
- exit 0
- fi
- echo ""
- echo " ========================================"
- echo " Claude AI Installer - macOS 构建"
- echo " 使用 Tauri 2.0"
- echo " ========================================"
- echo ""
- # 检查 Rust 是否安装
- if ! command -v rustc &> /dev/null; then
- echo -e " ${RED}✖${NC} 未找到 Rust,请先安装 Rust"
- echo -e " ${BLUE}ℹ${NC} 访问: https://rustup.rs/"
- exit 1
- fi
- # 显示 Rust 版本
- RUST_VERSION=$(rustc --version)
- echo -e " ${GREEN}✔${NC} Rust: $RUST_VERSION"
- # 检查 Node.js
- if ! command -v node &> /dev/null; then
- echo -e " ${RED}✖${NC} 未找到 Node.js,请先安装 Node.js"
- exit 1
- fi
- # 显示 Node.js 版本
- NODE_VERSION=$(node --version)
- echo -e " ${GREEN}✔${NC} Node.js: $NODE_VERSION"
- # 检查 Xcode Command Line Tools
- if ! xcode-select -p &> /dev/null; then
- echo -e " ${YELLOW}!${NC} 未找到 Xcode Command Line Tools"
- echo -e " ${BLUE}ℹ${NC} 安装: xcode-select --install"
- else
- echo -e " ${GREEN}✔${NC} Xcode Command Line Tools 已安装"
- fi
- # 显示当前架构
- ARCH=$(uname -m)
- echo -e " ${BLUE}ℹ${NC} 当前架构: $ARCH"
- # 设置 Tauri 签名密钥环境变量
- if [ -f ".keys/tauri-signing.key" ]; then
- echo -e " ${GREEN}✔${NC} 找到签名密钥"
- export TAURI_SIGNING_PRIVATE_KEY=$(cat .keys/tauri-signing.key)
- export TAURI_SIGNING_PRIVATE_KEY_PASSWORD=""
- else
- echo -e " ${YELLOW}!${NC} 未找到签名密钥 (.keys/tauri-signing.key)"
- echo -e " ${BLUE}ℹ${NC} 更新功能将不可用,构建将继续..."
- fi
- # 检查 node_modules
- if [ ! -d "node_modules" ]; then
- echo ""
- echo -e " ${YELLOW}!${NC} 未找到 node_modules,正在安装依赖..."
- npm install
- if [ $? -ne 0 ]; then
- echo -e " ${RED}✖${NC} 安装依赖失败"
- exit 1
- fi
- fi
- # 解析参数
- NODE_ARGS=""
- TARGET=""
- UNIVERSAL=false
- while [[ $# -gt 0 ]]; do
- case $1 in
- --debug|-d)
- NODE_ARGS="$NODE_ARGS --debug"
- shift
- ;;
- --skip-frontend|-s)
- NODE_ARGS="$NODE_ARGS --skip-frontend"
- shift
- ;;
- --target|-t)
- TARGET="$2"
- shift 2
- ;;
- --universal|-u)
- UNIVERSAL=true
- shift
- ;;
- *)
- shift
- ;;
- esac
- done
- # 处理目标架构
- if [ "$UNIVERSAL" = true ]; then
- NODE_ARGS="$NODE_ARGS --target universal-apple-darwin"
- echo -e " ${BLUE}ℹ${NC} 构建目标: 通用二进制 (ARM + Intel)"
- elif [ -n "$TARGET" ]; then
- case $TARGET in
- aarch64|arm64|arm)
- NODE_ARGS="$NODE_ARGS --target aarch64-apple-darwin"
- echo -e " ${BLUE}ℹ${NC} 构建目标: Apple Silicon (aarch64)"
- ;;
- x86_64|x64|intel)
- NODE_ARGS="$NODE_ARGS --target x86_64-apple-darwin"
- echo -e " ${BLUE}ℹ${NC} 构建目标: Intel (x86_64)"
- ;;
- *)
- echo -e " ${RED}✖${NC} 未知目标架构: $TARGET"
- echo -e " ${BLUE}ℹ${NC} 支持的架构: aarch64, x86_64"
- exit 1
- ;;
- esac
- fi
- echo ""
- echo -e " ${CYAN}▶ 调用 Node.js 构建脚本...${NC}"
- echo -e " ${BLUE}ℹ${NC} 执行: node scripts/build.js $NODE_ARGS"
- echo ""
- node scripts/build.js $NODE_ARGS
- BUILD_RESULT=$?
- if [ $BUILD_RESULT -ne 0 ]; then
- echo ""
- echo -e " ${RED}✖${NC} 构建失败!"
- echo ""
- exit 1
- fi
- echo ""
|