#! /usr/env/bin sh

####################
# Copies the structure defined in netlify.toml
####################

DIR_BUILD='public'
DIR_OUT='temp'

# Find DIR_BUILD
if [ ! -e "$DIR_BUILD" ]; then
    echo "No $DIR_BUILD found"
    exit 1
fi

# Delete DIR_OUT
if [ -e "$DIR_OUT" ]; then
    echo "Removing $DIR_OUT"
    rm -rf "$DIR_OUT"
fi

echo "Duplicate $DIR_BUILD $DIR_OUT"
cp -r "$DIR_BUILD" "$DIR_OUT"

echo "Change structure"
mv "$DIR_OUT/page-data" "$DIR_OUT/js-assets/page-data"
mv "$DIR_OUT/static" "$DIR_OUT/js-assets/static"

if [ -e "$DIR_BUILD" ]; then
    echo "Removing $DIR_BUILD"
    rm -rf "$DIR_BUILD"
fi

if [ -e "$DIR_OUT" ]; then
    echo "Moving $DIR_OUT to $DIR_BUILD"
    mv "$DIR_OUT" "$DIR_BUILD"
fi

clear

echo "
!!!!!!!!!!!!!!!!!!!
!!!             !!!
!!!   WARNING   !!!
!!!             !!!
!!!!!!!!!!!!!!!!!!!

If you need the default gatsby output,
ensure that you rebuild  with \"npm run build\"


"
