#!/bin/bash

# --------- API ENV ---------
echo 'Generating all graphs.'

# Generate graphs directory, if it doesn't exist
mkdir -p graphs

# For each foled in src
for dirName in src/*/
do
    # Get only directory name from path
    moduleName=$(echo $dirName | sed 's/^....//' | sed 's/.$//')
    # Generate graph for the module
    echo "Generating $moduleName graph"
    npx depcruise src --include-only "^$dirName*" --output-type dot | dot -T svg > graphs/dependency-graph-$moduleName.svg
done

# Generate graph for the whole API
echo "Generating global graph"
npx depcruise src --include-only '^src/*' --exclude '^src/(utils|logger|error|config|types)' --output-type dot | dot -T svg > graphs/dependency-graph.svg

# Generate graph for the whole API, in a module level
echo "Generating global arquitechture graph"
npx depcruise src --include-only '^src/*' --exclude '^src/(utils|logger|error|config|types)' --output-type archi | dot -T svg > graphs/dependency-graph-module.svg