#!/bin/bash
#
# Do not edit this file.
#
# To adjust any values, copy the file settings-local.sh.dist
# to settings-local.sh and overwrite or expand the variables ​​there

source ./scripts/helper.sh

TARGET="$(determine_target "$1")"         # either "firefox" or "chromium"
ROOT="$PWD"                               # root directory of local project repository
SOURCE="$ROOT/src"                    
BUILD="$ROOT/build/$TARGET"

PORT="$(free_port)"                       # ascending in the range from 55555 to 55666
URL="https://127.0.0.1:$PORT/test.html"   # dummy page used as --start-url by web-ext

FIREFOX="firefox"                         # executable, add path if not in PATH
FIREFOX_PROFILE="kahuna-dev"
CHROMIUM="google-chrome"
CHROMIUM_PROFILE="kahuna-dev"

ESBUILD_PARAMS=(
    "--bundle"
#    "--alias:dexie=dexie/dist/modern/dexie.mjs"
    "--alias:buildinfo.js=$BUILD/buildinfo.js"
    "--target=es2024"
    "--log-level=warning"
    )
if [ "$2" = "release" ]; then
    ESBUILD_PARAMS+=("--minify")
else
    ESBUILD_PARAMS+=("--sourcemap=both")    
fi;

WEBEXT_OPTIONS=(
    "--source-dir" "$BUILD"
    "--profile-create-if-missing"
    "--keep-profile-changes"
    "--start-url" "$URL"   
)
if [ "$TARGET" = "firefox" ]; then
    WEBEXT_OPTIONS+=(
        "--watch-file" "$BUILD/background.js"
        "--arg=\"--devtools\""
        "--firefox" "$FIREFOX"
        "--firefox-profile" "$FIREFOX_PROFILE"
    )
elif [ "$TARGET" = "chromium" ]; then
    WEBEXT_OPTIONS+=(
    "--watch-file" "$BUILD/background_worker.js"
    "--target" "$TARGET"
    "--args=\"--auto-open-devtools-for-tabs\""
    "--chromium-binary" "$CHROMIUM"
    "--chromium-profile" "$CHROMIUM_PROFILE"
    )
fi;

HTTP_SERVER_OPTIONS=(
    "--port" "$PORT"
)

if [ -f ./scripts/settings-local.sh ]; then
    source ./scripts/settings-local.sh
fi

