#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" OUTPUT_DIR="${OUTPUT_DIR:-"$ROOT_DIR/dist"}" ALLOW_DIRTY="${ALLOW_DIRTY:-0}" if [[ "$ALLOW_DIRTY" != "1" ]]; then if [[ -n "$(git -C "$ROOT_DIR" status --porcelain)" ]]; then echo "Working tree is dirty. Set ALLOW_DIRTY=1 to override." >&2 exit 1 fi fi VERSION="$(php -r 'echo json_decode(file_get_contents("composer.json"), true)["version"] ?? "0.0.0";')" if [[ -z "$VERSION" ]]; then echo "Could not determine version from composer.json" >&2 exit 1 fi BUILD_DIR="$(mktemp -d)" cleanup() { rm -rf "$BUILD_DIR" } trap cleanup EXIT exclude_args=( --exclude ".git" --exclude "node_modules" --exclude "vendor" --exclude "storage" --exclude "dist" --exclude "tests" --exclude ".env" --exclude ".env.test" --exclude "public/build" ) if command -v rsync >/dev/null 2>&1; then rsync -a "${exclude_args[@]}" "$ROOT_DIR/" "$BUILD_DIR/" else tar -C "$ROOT_DIR" -cf - \ --exclude=".git" \ --exclude="node_modules" \ --exclude="vendor" \ --exclude="storage" \ --exclude="dist" \ --exclude="tests" \ --exclude=".env" \ --exclude=".env.test" \ --exclude="public/build" \ . | tar -C "$BUILD_DIR" -xf - fi pushd "$BUILD_DIR" >/dev/null composer install --no-dev --optimize-autoloader npm install npm run build rm -rf node_modules popd >/dev/null mkdir -p "$OUTPUT_DIR" FULL_TAR="$OUTPUT_DIR/speedbb-full-v${VERSION}.tar.gz" SRC_TAR="$OUTPUT_DIR/speedbb-src-v${VERSION}.tar.gz" tar -C "$BUILD_DIR" -czf "$FULL_TAR" --exclude="tests" . tar -C "$BUILD_DIR" -czf "$SRC_TAR" --exclude="vendor" --exclude="public/build" --exclude="tests" . echo "Built:" echo " $FULL_TAR" echo " $SRC_TAR"