#!/bin/sh
PACKNAME=$1
OUTDIR="../OUT"
mkdir -p "$OUTDIR/assets"
printf "{\"$PACKNAME\":{" > "$OUTDIR/$PACKNAME.json"
shopt -s nullglob
for i in "$PACKNAME"/*.png "$PACKNAME"/*.jpg "$PACKNAME"/*.gif "$PACKNAME"/*.svg;
do
	FILE="$(basename "${i%.*}")"
	OUTNAME="$(sha256sum "$i" | awk '{ print $1 }').${i##*.}"
	cp $i "$OUTDIR/assets/$OUTNAME"
	echo "Writing '$FILE' to pack json."
	printf "\"$FILE\":\"$OUTNAME\"," >> "$OUTDIR/$PACKNAME.json"
done
sed -i '$ s/.$//' "$OUTDIR/$PACKNAME.json"
printf "}}" >> "$OUTDIR/$PACKNAME.json"
