-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow_dep_graph.sh
46 lines (40 loc) · 1.22 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
43
44
45
46
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
# This file was first created using the Yeoman generator
# generator-hchiam-learning:
# https://www.npmjs.com/package/generator-hchiam-learning