-
Notifications
You must be signed in to change notification settings - Fork 0
/
show_dep_graph.sh
42 lines (37 loc) · 1.08 KB
/
show_dep_graph.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function askForMaxDepth() {
read -p "Enter max depth: " maxDepth
}
function installDotIfMissing() {
if ! [ -x "$(command -v dot)" ]; then
echo 'Error: dot graphviz is not set up or installed. Attempting install now.'
brew install graphviz
fi
}
function getSrcFolder() {
read -p "Enter src folder: " srcFolder
}
function createDependencyGraph() {
re='^[0-9]+$'
if ! [[ $maxDepth =~ $re ]] ; then
# don't use maxDepth if it's not a number
depcruise --exclude "^node_modules" --output-type dot $srcFolder | dot -T svg > dependencygraph.svg
else
depcruise --max-depth $maxDepth --exclude "^node_modules" --output-type dot $srcFolder | dot -T svg > dependencygraph.svg
fi
}
function showDependencyGraph() {
echo 'Trying to open dependencygraph.svg in a browser.'
# try to open in Firefox or Chrome
open -a "Firefox" dependencygraph.svg || \
open -a "Google Chrome" dependencygraph.svg || true
}
askForMaxDepth
installDotIfMissing
if [ ! -d src ]; then
echo "src folder missing"
getSrcFolder
else
srcFolder="src"
fi
createDependencyGraph
showDependencyGraph