#!/bin/bash
set -e

ASSETS_DIR=node_modules/photoswipe/dist
TARGET_DIR=static/modules/hall-of-mirrors

# Print error to stdout and exit 1 if asset directories cannot be found
if ! [ -d "$ASSETS_DIR" ] || [ -d "$ASSETS_DIR"/default-skins ] ; then
   echo "Error: Photoswipe assets not found in $PWD/$ASSETS_DIR." >&2; exit 1
fi

# Create target directory if not exists
mkdir -p "$TARGET_DIR"

# Define required assets
# See https://stackoverflow.com/a/51683629/712334 for recursive globbing
files=(
   "$ASSETS_DIR"/*.min.js
   "$ASSETS_DIR"/*.css
   "$ASSETS_DIR"/**/*
)
# printf '%s\n' "${files[@]}" # e.g. path/to/source/filename.tar.gz
# printf '%s\n' "${files[@]##*/}" # e.g. filename.tgz

# Copy required assets to target directory
for file in "${files[@]}" ; do
   cp "$file" "$TARGET_DIR"
done
