Last active
August 20, 2024 22:32
-
-
Save wakinchan/75bc1b75c812e432561a639566af518b to your computer and use it in GitHub Desktop.
Generate Target Dependencies for Package.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# usage: sh ./generate-target-dependencies.sh | dot -Tsvg -o target-graph.svg | |
packages=`swift package describe --type json` | |
targets=`echo $packages | jq '.targets'` | |
target_names=`echo $targets | jq -r '.[] | .name'` | |
body="" | |
template=`cat <<EOF | |
digraph DependenciesGraph { | |
node [shape = box] | |
%BODY% | |
} | |
` | |
for target_name in `echo $target_names`; do | |
label='"'$target_name'" [label="'$target_name'"]' | |
body+="$label\n" | |
target_dependencies=`echo $targets | jq -r '.[] | select(.name == "'$target_name'") | select(.target_dependencies != null) | .target_dependencies | .[]'` | |
for target_dependency in `echo $target_dependencies`; do | |
target='"'$target_name'" -> "'$target_dependency'"' | |
body+="$target\n" | |
done | |
done | |
echo "$template" | sed -e 's/%BODY%/'"$body"'/' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is possible to output such svg. Low resolution for convenience.