nix: Add a script to generate a graph of Haskell imports (#1751)
This commit is contained in:
@@ -21,3 +21,4 @@ __pycache__
|
||||
*.tix
|
||||
coverage
|
||||
.hpc
|
||||
imports.png
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
, checkedShellScript
|
||||
, devCabalOptions
|
||||
, entr
|
||||
, graphviz
|
||||
, silver-searcher
|
||||
, style
|
||||
, tests
|
||||
@@ -96,6 +97,41 @@ let
|
||||
${style}/bin/postgrest-lint
|
||||
${style}/bin/postgrest-style-check
|
||||
'';
|
||||
|
||||
importsgraph =
|
||||
checkedShellScript
|
||||
{
|
||||
name = "postgrest-importsgraph";
|
||||
docs =
|
||||
''
|
||||
Render the imports between PostgREST modules as a graph.
|
||||
|
||||
Output is written to 'imports.png' in the root directory of the project.
|
||||
'';
|
||||
inRootDir = true;
|
||||
}
|
||||
''
|
||||
imports=$(
|
||||
grep -rE 'import .*PostgREST\.' src main \
|
||||
| sed -E \
|
||||
-e 's|/|\.|g' \
|
||||
-e 's/(src|main)\.(.*)\.hs:import .*(PostgREST\.\S+)( .*)?/"\2" -> "\3"/'
|
||||
)
|
||||
|
||||
labels=$(
|
||||
grep -rE '^(--)?\s*Description\s*:' src main \
|
||||
| sed -E \
|
||||
-e 's|/|\.|g' \
|
||||
-e 's/^(src|main)\.(.*)\.hs:(--)?\s*Description\s*:\s*(.*)$/"\2" [label="\2\\n\4"]/'
|
||||
)
|
||||
|
||||
cat <<EOF | ${graphviz}/bin/dot -Tpng > imports.png
|
||||
digraph {
|
||||
$imports
|
||||
$labels
|
||||
}
|
||||
EOF
|
||||
'';
|
||||
in
|
||||
buildEnv {
|
||||
name = "postgrest-devtools";
|
||||
@@ -106,5 +142,6 @@ buildEnv {
|
||||
run.bin
|
||||
clean.bin
|
||||
check.bin
|
||||
importsgraph.bin
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user