#!/bin/bash

set -euo pipefail

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
PROJECT="bb64"

echo "Cleaning ${PROJECT}..."

# Remove output directory
if [ -d "${SCRIPT_DIR}/output" ]; then
    echo "Removing output directory..."
    rm -rf "${SCRIPT_DIR}/output"
fi

# Remove Docker images related to this project
echo "Removing Docker images..."
docker images --filter "reference=${PROJECT}-build*" -q | xargs -r docker rmi -f

# Remove Docker build cache
echo "Pruning Docker build cache..."
docker builder prune -f

echo "✓ ${PROJECT} cleaned successfully"