#!/bin/bash
set -e
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
project_dir=${dir}/..
cd $project_dir

f () {
  echo "=== $1 ==="
  cargo clean -p $1
  cd "$1"
  cargo count --separator , --unsafe-statistics src
  cd ..
}

bin/format

f "dbui-core"
f "dbui-client"
f "dbui-assets"
f "dbui-database"
f "dbui-controllers"
f "dbui-service"
f "dbui-templates"

echo "=== dbui (bin) ==="
cargo clean -p dbui
cd "src"
cargo count --separator , --unsafe-statistics
cd ..

echo "=== dbui (total) ==="
cargo count --separator , --unsafe-statistics -a --exclude=$(cat .gitignore) --exclude=target --exclude=dbui-assets/embed --exclude=dbui-client/pkg
cargo deps --include-versions --dev-deps | dot -Tpng > "target/dependencies.png"

echo "=== Dependencies ==="
cargo outdated
cargo audit

echo "=== Linting ==="
cargo clippy
cd dbui-client
cargo clippy
