#!/bin/bash

# Ensure script is run from the root directory
if [ ! -f "app/planqtn_cli/package.json" ]; then
    echo "Error: This script must be run from the root directory of the repository"
    echo "Current directory: $(pwd)"
    echo "Expected to find: app/planqtn_cli/package.json"
    exit 1
fi


export PYTHONPATH=`pwd`

cd app/planqtn_cli

# Check formatting
npx prettier --check src --config ../.prettierrc
if [ $? -ne 0 ]; then
    echo "Formatting check failed"
    echo "Run 'cd app/planqtn_cli && npx prettier --write src && cd -' to fix"
    exit 1
fi

# Check linting
echo "ESLint..."
npx eslint src
if [ $? -ne 0 ]; then
    echo "Linting check failed"
    echo "Run 'cd app/planqtn_cli && npx eslint --fix src && cd -' to fix"
    exit 1
fi
echo "Passed."

echo "Check build"
npm run build
if [ $? -ne 0 ]; then
    echo "Build check failed"    
    exit 1
fi
echo "Passed."


echo "All checks passed"