#!/bin/env bash

# We need to add this shim as the main umbreld entrypoint so we can sets up the environmnet we need
# like adding node_modules/.bin to the PATH so we have access to tsx.

# Find the project directory and follow symlinks if necessary
project_directory="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"

# Get the start script from package.json
entrypoint=$(npm --prefix "${project_directory}" pkg get scripts.start)

# Remove double quotes
entrypoint="${entrypoint#\"}"
entrypoint="${entrypoint%\"}"

# Setup PATH so we can resolve tsx and local node
export PATH="${project_directory}/node_modules/.bin:${PATH}"

# Execute the entrpoint and pass through any arguments
exec "${project_directory}/${entrypoint}" "$@"
