#!/bin/bash

# Run the rest of the file in the parent directory (src/packages/ui-icons)
cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1
cd ../

# Get the hash of all files in this directory
files_hash_current=$(./scripts/get_current_hash.sh)

# Get the saved hash at time of build (if it exists)
files_hash_at_build=$([ -f ./dist/files_hash_at_build.txt ] && cat ./dist/files_hash_at_build.txt || echo "")

# Compare the hashes and rebuild the package if they differ
if [ "$files_hash_current" != "$files_hash_at_build" ]; then
    echo "ui-icons package is out of date. Rebuilding..."
    pnpm run build
fi
