#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

SRC_PATTERN="\.json$"
if git diff --cached --name-only | grep --quiet -E "$SRC_PATTERN"
then
  echo "JSON assets changed. Running build scripts."
  echo "Re-building JS and PY assets using JS script."
  npm run transpile-and-build-assets
fi
pwd

if test -f .venv/bin/activate
then
  echo "Python virtual environment found. Running build scripts"
  echo "Re-building JS and PY assets using JS script."
  source .venv/bin/activate
  # Note: resolved (no include statements) schemas have to exist by this time
  pre-commit run --all-files
  #git add dist/py
else
  echo "ERROR: Python virtual environment found. Create one in '.venv' and install '.[all]'"
  exit 1
fi
npx lint-staged --allow-empty

# Skip linting after build to preserve generated files
# npm run lint:fix
npm run transpile
git add dist

