Files
jiu/scripts/local_test.sh
T
wangjia c49ee3b1df feat(client): 库存抽屉打印标签 + 修本地构建版本号不对
- 商品编辑抽屉头部「预览」旁加「打印标签」(同入库管理:QR+品牌型号版本+
  门店信息 → LabelPreviewDialog;移动端无打印不渲染)
- 修版本号 bug:appVersionProvider/更新检查改为优先 APP_VERSION dart-define
  (本地与 iOS 手工构建不改 pubspec,PackageInfo 恒为旧值 1.0.52,App 内
  显示错且误弹更新横幅);版本比较容忍 -dev/+build 后缀(每段取前导数字)
- local_test.sh:版本标记 -dev(如 v1.1.4-dev)明确区分本地包;新增 --ios
  模式(开发签名构建 + devicectl 装 USB iPhone),双端同一版本注入链路

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-04 23:57:37 +08:00

81 lines
3.2 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# local_test.sh — 本地编译一份「指向线上后端」的 app 用于发版前自测。
#
# 用法:
# sh scripts/local_test.sh # 编译 macOS + 启动
# sh scripts/local_test.sh --no-open # 只编译 macOS 不启动
# sh scripts/local_test.sh --ios # 编译 iOS 并装到 USB iPhone(开发签名)
#
# 后端固定指向生产 https://jiu.51yanmei.com(与 CI compile 脚本一致)。
# 版本号 = 最新 client-v* tag 的 patch+1 加 -dev 后缀(如 v1.1.4-dev),
# App 内显示走 APP_VERSION dart-defineupdate_provider.currentAppVersion),
# 与 CI 同一读取链路——本地构建不再显示 pubspec 旧版本(2026-07-04 修复)。
set -euo pipefail
export PATH="/opt/homebrew/bin:$PATH"
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$REPO_ROOT"
LATEST_TAG="$(git describe --tags --match 'client-v*' --abbrev=0 2>/dev/null || true)"
if [ -n "$LATEST_TAG" ]; then
BASE_VER="${LATEST_TAG#client-v}"
MAJOR_MINOR="${BASE_VER%.*}"
PATCH="${BASE_VER##*.}"
VER="${MAJOR_MINOR}.$((PATCH + 1))-dev"
else
VER="0.0.0-dev"
fi
DEFINES=(
"--dart-define=BASE_URL=https://jiu.51yanmei.com"
"--dart-define=PUBLIC_URL=https://jiu.51yanmei.com"
"--dart-define=APP_VERSION=v${VER}"
)
if [ "${1:-}" = "--ios" ]; then
# ── iOS:开发签名构建 + devicectl 装到 USB iPhone ──
# Release 配置是 CI 的 Manual+App Store 签名,本机没有分发证书,
# 故 xcodebuild 用 Automatic + Apple Development 覆盖(不改工程文件)。
echo "==> 编译 iOS(线上后端,版本 v${VER}"
cd client
flutter build ios --release --config-only "${DEFINES[@]}"
cd ios
CD_ID="$(xcrun devicectl list devices 2>/dev/null | grep 'available (paired)' | grep 'iPhone' | grep -oE '[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}' | head -1 || true)"
if [ -z "$CD_ID" ]; then
echo "!! 未检测到已配对 iPhone(插线并解锁后重试)" >&2
exit 1
fi
xcodebuild -workspace Runner.xcworkspace -scheme Runner -configuration Release \
-destination "generic/platform=iOS" \
CODE_SIGN_STYLE=Automatic DEVELOPMENT_TEAM=BYL4KQHMTN \
CODE_SIGN_IDENTITY="Apple Development" PROVISIONING_PROFILE_SPECIFIER= \
-allowProvisioningUpdates -allowProvisioningDeviceRegistration build \
| grep -E "BUILD (SUCCEEDED|FAILED)"
APP_PATH="$(find "$HOME/Library/Developer/Xcode/DerivedData" -path '*Release-iphoneos/Runner.app' -maxdepth 6 2>/dev/null | head -1)"
if [ -z "$APP_PATH" ]; then
echo "!! 找不到构建产物 Runner.app" >&2
exit 1
fi
echo "==> 安装到 iPhone$CD_ID"
xcrun devicectl device install app --device "$CD_ID" "$APP_PATH" | grep -m1 databaseSequenceNumber || true
echo "==> 完成:解锁手机打开 岩美酒库(版本 v${VER}"
exit 0
fi
APP="client/build/macos/Build/Products/Release/jiu_client.app"
echo "==> 编译 macOS app(线上后端,版本 v${VER}"
cd client
flutter build macos --release "${DEFINES[@]}"
cd "$REPO_ROOT"
echo "==> 产物:$APP"
if [ "${1:-}" = "--no-open" ]; then
echo "==> 跳过启动(--no-open"
else
echo "==> 前台启动 app(终端附着日志,退出 app 才返回;Ctrl-C 可终止)"
exec "$APP/Contents/MacOS/jiu_client"
fi