add emu*.sh to boot ios emulator by short names

This commit is contained in:
luk
2026-10-07 07:28:21 +08:00
parent 4645729e64
commit 093663f62d
7 changed files with 611 additions and 2 deletions
+35
View File
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
# 输出要跑 App 的那台模拟器 UDID,供 app-ios-run-* 使用。
#
# 不给参数(默认):纯 booted 语义——打「当前已启动的那台」。
# 有多台同时开着会直接报错,避免稀里糊涂打到另一台上。
# 给参数(覆盖) :解析成指定的那台,跳过 booted 检查。
# [email protected] npm run app-ios-run-local
# (flutter run 会自己把它启动起来,不用先 boot)
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
override="${1:-}"
if [[ -n "${override}" ]]; then
node "${SCRIPT_DIR}/emuResolveIos.js" "${override}"
exit 0
fi
booted="$(xcrun simctl list devices booted | grep -oE '[0-9A-Fa-f-]{36}' || true)"
if [[ -z "${booted}" ]]; then
echo "❌ 没有已启动的模拟器。先跑:npm run app-ios-emu-boot [-- [email protected]]" >&2
exit 1
fi
count="$(printf '%s\n' "${booted}" | wc -l | tr -d ' ')"
if (( count > 1 )); then
echo "❌ 有 ${count} 台模拟器同时开着,不知道该打哪台:" >&2
xcrun simctl list devices booted >&2
echo " 关掉多余的:xcrun simctl shutdown <UDID>" >&2
echo " 或者直接指定:[email protected] npm run app-ios-run-local" >&2
exit 1
fi
printf '%s' "${booted}"