Files
cocos_zhuzhan/tools/sync-unity-package-to-static.sh

63 lines
2.1 KiB
Bash
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
# 将运行时包同步到 scratch-gui/static/unity/
# 与 OSS unitycdndir 内容完全一致Build/ + StreamingAssets/ + levels-db-index.*
#
# bash tools/sync-unity-package-to-static.sh <packDir> <staticUnityDir>
set -euo pipefail
PACK_DIR="$(cd "${1:?packDir}" && pwd)"
UNITY_STATIC="$(cd "${2:?staticUnityDir}" && pwd)"
DRY_RUN="${DRY_RUN:-0}"
if [[ ! -f "$PACK_DIR/Build/mstest5.loader.js" ]]; then
echo "错误: 缺少 $PACK_DIR/Build/mstest5.loader.js" >&2
exit 1
fi
if [[ ! -f "$PACK_DIR/StreamingAssets/aa/catalog.json" && ! -f "$PACK_DIR/StreamingAssets/aa/catalog.json.br" ]]; then
echo "错误: 缺少 $PACK_DIR/StreamingAssets/aa/catalog.json(.br)" >&2
exit 1
fi
mkdir -p "$UNITY_STATIC/Build" "$UNITY_STATIC/StreamingAssets"
RSYNC_FLAGS=(-a --delete)
[[ "$DRY_RUN" -eq 1 ]] && RSYNC_FLAGS=(-a -n -v)
echo "==> 同步运行时包 → static/unity与 OSS unitycdndir 相同)"
echo " 源: $PACK_DIR"
echo " 目标: $UNITY_STATIC"
rsync "${RSYNC_FLAGS[@]}" "$PACK_DIR/Build/" "$UNITY_STATIC/Build/"
rsync "${RSYNC_FLAGS[@]}" "$PACK_DIR/StreamingAssets/" "$UNITY_STATIC/StreamingAssets/"
for db in levels-db-index.json levels-db-index.json.br levels-database.json levels-database.json.br; do
if [[ -f "$PACK_DIR/$db" ]]; then
if [[ "$DRY_RUN" -eq 1 ]]; then
echo " [dry-run] cp $PACK_DIR/$db$UNITY_STATIC/"
else
cp "$PACK_DIR/$db" "$UNITY_STATIC/$db"
echo " copied $db"
fi
fi
done
# 全量库已默认不打进包;清掉 static 里旧的大文件
if [[ "$DRY_RUN" -eq 0 ]]; then
for stale in levels-database.json levels-database.json.br; do
if [[ ! -f "$PACK_DIR/$stale" && -f "$UNITY_STATIC/$stale" ]]; then
rm -f "$UNITY_STATIC/$stale"
echo " removed stale $stale"
fi
done
fi
if [[ "$DRY_RUN" -eq 0 ]]; then
for legacy in index.js application.js cocos-bridge.js assets cocos-js src index.html TemplateData; do
if [[ -e "$UNITY_STATIC/$legacy" ]]; then
rm -rf "$UNITY_STATIC/$legacy"
echo " removed legacy: $legacy"
fi
done
fi
echo "==> 完成。usecdn:false → /unity/ usecdn:true → unitycdndir文件相同"