#!/usr/bin/env bash set -euo pipefail cd "$(dirname "$0")/.." if [ "$(uname -s)" != "Darwin" ]; then echo "此脚本需要在 macOS 上运行。" exit 1 fi for tool in node npm cargo; do if ! command -v "$tool" >/dev/null 2>&1; then echo "缺少 $tool,请先安装 Node.js 20+ 和 Rust (https://rustup.rs)。" exit 1 fi done if [ ! -d node_modules ]; then echo "==> 安装前端/CLI 依赖" npm ci fi echo "==> 准备 luatos-cli sidecar(universal)" CLI_SRC="../luatools-mac/resources/bin/luatos-cli" for triple in aarch64-apple-darwin x86_64-apple-darwin; do target="src-tauri/binaries/luatos-cli-$triple" if [ ! -f "$target" ]; then if [ -f "$CLI_SRC" ]; then cp "$CLI_SRC" "$target" chmod +x "$target" else echo "缺少 $target,请先把 luatos-cli 放到 src-tauri/binaries/。" exit 1 fi fi done if [ "${UNIVERSAL:-0}" = "1" ]; then echo "==> 补齐 Rust 双架构 target" rustup target add aarch64-apple-darwin x86_64-apple-darwin >/dev/null 2>&1 || true echo "==> 构建 universal .app / .dmg" npm run build:mac:universal OUT="src-tauri/target/universal-apple-darwin/release/bundle" else echo "==> 构建 arm64 .app / .dmg" npm run build:mac OUT="src-tauri/target/aarch64-apple-darwin/release/bundle" fi echo echo "完成。产物:" ls -lh "$OUT"/dmg/*.dmg "$OUT"/macos/*.app 2>/dev/null || true echo echo "未签名构建首次运行如被 Gatekeeper 拦截:" echo ' xattr -cr "/Applications/LuatOS Flasher.app"'