-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeps.sh
executable file
·50 lines (42 loc) · 1.46 KB
/
deps.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
47
48
49
50
#!/bin/bash
# To run this file directly: bash deps.sh
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 (or file or other folder you'd like to inspect): " 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
# Example outputs:
# https://raw.githubusercontent.com/hchiam/learning-dependency-cruiser/879baa9074b550d87bd3f23203022ca35a31850d/dependencygraph.svg
# https://raw.githubusercontent.com/hchiam/code-inspiration/d2301787478c917812d0a82a7d1803d515f6a35c/dependencygraph.svg