#!/bin/sh

GDFORMAT=gdformat
GDLINT=gdlint
VENV=.venv
PYTHON=python3
PIP=$VENV/bin/pip

if ! which $GDFORMAT &> /dev/null; then
    if ! test -f $VENV/bin/$GDFORMAT; then
        if ! which $PYTHON &> /dev/null; then
            echo "Please install Python 3"
            exit 1
        fi

        echo "gdscript-toolkit will be installed locally under $VENV."
        echo "this only needs to be performed once."
        echo "creating venv..."
        $PYTHON -m venv $VENV
        echo "installing gdscript-toolkit..."
        $PIP install -r requirements.txt
    fi

    GDFORMAT=$VENV/bin/$GDFORMAT
    GDLINT=$VENV/bin/$GDLINT
fi

set -x

$GDFORMAT --check .
$GDLINT .
