#!/bin/bash
# Helper script to set LD_LIBRARY_PATH for Sharp before running commands
# This ensures Sharp can find its bundled libvips library

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
SHARP_LIB_PATH="$PROJECT_DIR/node_modules/sharp/node_modules/@img/sharp-libvips-linux-x64/lib"

# Add node_modules/.bin to PATH if it exists
if [ -d "$PROJECT_DIR/node_modules/.bin" ]; then
  export PATH="$PROJECT_DIR/node_modules/.bin:$PATH"
fi

# Change to project directory to ensure relative paths work
cd "$PROJECT_DIR" || exit 1
if [ -d "$SHARP_LIB_PATH" ]; then
  export LD_LIBRARY_PATH="$SHARP_LIB_PATH:${LD_LIBRARY_PATH:-}"
  exec "$@"
else
  echo "Warning: Sharp libvips library not found at $SHARP_LIB_PATH"
  echo "Sharp image processing may not work correctly."
  exec "$@"
fi




