Files
website/scripts/package-deploy.sh
T

105 lines
3.4 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT_DIR"
if [[ -z "${NEXT_PUBLIC_SITE_URL:-}" ]]; then
echo "ERROR: Set NEXT_PUBLIC_SITE_URL to the public production origin before packaging." >&2
echo "Example: NEXT_PUBLIC_SITE_URL=https://www.eversolo.com ./scripts/package-deploy.sh" >&2
exit 1
fi
case "$NEXT_PUBLIC_SITE_URL" in
http://localhost*|https://localhost*|http://127.0.0.1*|https://127.0.0.1*|http://0.0.0.0*|https://0.0.0.0*)
echo "ERROR: NEXT_PUBLIC_SITE_URL must not be a local URL for a deployment package." >&2
exit 1
;;
esac
STAMP="$(date +%Y%m%d-%H%M%S)"
OUT_DIR="${OUT_DIR:-deploy-packages/${STAMP}-deploy-nopublic-noenv}"
ARCHIVE_NAME="${ARCHIVE_NAME:-eversoloweb-deploy-nopublic-noenv-${STAMP}.tar.gz}"
ARCHIVE_PATH="${OUT_DIR}/${ARCHIVE_NAME}"
MANIFEST_PATH="${OUT_DIR}/manifest.txt"
if [[ "${SKIP_BUILD:-0}" != "1" ]]; then
NODE_ENV=production NEXT_PUBLIC_SITE_URL="$NEXT_PUBLIC_SITE_URL" npm run build
fi
mkdir -p "$OUT_DIR"
COPYFILE_DISABLE=1 tar --no-xattrs -czf "$ARCHIVE_PATH" \
--exclude='./.git' \
--exclude='./.git/*' \
--exclude='./.next/cache' \
--exclude='./.next/cache/*' \
--exclude='./.next-dev' \
--exclude='./.next-dev/*' \
--exclude='./.env' \
--exclude='./.env.*' \
--exclude='./.env.example' \
--exclude='./.DS_Store' \
--exclude='./**/.DS_Store' \
--exclude='./._*' \
--exclude='./**/._*' \
--exclude='./__MACOSX' \
--exclude='./__MACOSX/*' \
--exclude='./node_modules' \
--exclude='./node_modules/*' \
--exclude='./public' \
--exclude='./public/*' \
--exclude='./media' \
--exclude='./media/*' \
--exclude='./files' \
--exclude='./files/*' \
--exclude='./videos' \
--exclude='./videos/*' \
--exclude='./deploy-packages' \
--exclude='./deploy-packages/*' \
--exclude='./.claude' \
--exclude='./.claude/*' \
--exclude='./.playwright-cli' \
--exclude='./.playwright-cli/*' \
--exclude='./.tmp' \
--exclude='./.tmp/*' \
--exclude='./.wrangler' \
--exclude='./.wrangler/*' \
--exclude='./output' \
--exclude='./output/*' \
--exclude='./tsconfig.tsbuildinfo' \
--exclude='./tmp-*' \
2026-06-02 16:54:55 +08:00
--exclude='./eversolo-seo-keyword-audit-*.md' \
--exclude='./*.log' \
--exclude='./npm-debug.log*' \
--exclude='./yarn-debug.log*' \
--exclude='./yarn-error.log*' \
--exclude='./.vercel' \
--exclude='./.vercel/*' \
--exclude='./.turbo' \
--exclude='./.turbo/*' \
.
tar -tzf "$ARCHIVE_PATH" > "$MANIFEST_PATH"
if grep -E '(^|/)(public|node_modules|\.git|__MACOSX)(/|$)|(^|/)\.env($|\.)|(^|/)\.env\.example$|(^|/)\._|(^|/)\.DS_Store$|(^|/)\.next/cache(/|$)' "$MANIFEST_PATH"; then
echo "ERROR: The deployment archive contains excluded files. See ${MANIFEST_PATH}." >&2
exit 1
fi
if grep -E '(^|/)(media|files|videos|deploy-packages|\.claude|\.playwright-cli|\.tmp|\.wrangler|output)(/|$)|(^|/)tsconfig\.tsbuildinfo$|(^|/)tmp-' "$MANIFEST_PATH"; then
echo "ERROR: The deployment archive contains local upload, cache, or temporary files. See ${MANIFEST_PATH}." >&2
exit 1
fi
if command -v xattr >/dev/null 2>&1; then
xattr -c "$ARCHIVE_PATH" 2>/dev/null || true
if [[ -n "$(xattr -l "$ARCHIVE_PATH" 2>/dev/null || true)" ]]; then
echo "WARNING: The archive content is clean, but macOS still reports extended attributes on the outer archive file." >&2
xattr -l "$ARCHIVE_PATH" >&2 || true
fi
fi
echo "Archive: ${ARCHIVE_PATH}"
echo "Manifest: ${MANIFEST_PATH}"