#!/bin/bash

# requires node 22 at least
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# default NODE_ENV to development if not set
if [ -z "$NODE_ENV" ]; then
    NODE_ENV=development
fi

# default ENVIRONMENT to development if not set
if [ -z "$ENVIRONMENT" ]; then
    ENVIRONMENT=development
fi

set -eo pipefail

export NODE_ENV
export ENVIRONMENT

echo "cleaning"
rm -rf $SCRIPT_DIR/build

echo "creating build dir - this is for correct image resolution; ideally this wouldn't be needed"

#mkdir -p $SCRIPT_DIR/build/assets/img
#cp -r $SCRIPT_DIR/../src/assets/img/* $SCRIPT_DIR/build/assets/img/

echo "creating client-hydrate.bundle.js for jamtrack landing pages"
# PUBLIC_URL=? for server builds
# NODE_ENV=production for server builds
npx webpack
#cp -r public/* output/


npm run build

echo "run generate.js for all jamtracks defined in the CSV"
NODE_ENV=$NODE_ENV ENVIRONMENT=$ENVIRONMENT npm run generate-song-landing-pages

