#!/usr/bin/env bash
# TODO rewrite this script in python for better maintainability

set -e

CAMITK_SOURCE_DIR="../../../.."
PYTHON_MODULE_PATH="$CAMITK_SOURCE_DIR/build/lib"
EXTENSIONGENERATOR_RESOURCES_DIR="$CAMITK_SOURCE_DIR/sdk/libraries/extensiongenerator/resources/Python"

# Generate subs and update extensiongenerator resources
echo "Generating stub files ..."
PYTHONPATH=$PYTHON_MODULE_PATH .venv/bin/pybind11-stubgen camitk --output-dir ${EXTENSIONGENERATOR_RESOURCES_DIR}

echo "Stub files generated in ${EXTENSIONGENERATOR_RESOURCES_DIR}"

echo "Updating camitk.pyi files in source tree..."
for i in $(find ${CAMITK_SOURCE_DIR} -name "camitk.pyi"); do
    echo "- Updating $i"
    cp ${EXTENSIONGENERATOR_RESOURCES_DIR}/camitk.pyi $i
done
