#!/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 ==="
cargo clean -p dbui
cd "src"
cargo count --separator , --unsafe-statistics
cd ..

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

echo "=== Dependencies ==="
# cargo outdated --depth=1 -w
cargo outdated --depth=1
echo "=== Advisories ==="
cargo audit

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