diff --git a/.gitignore b/.gitignore index d00cdb788a..d6f521cb76 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ __pycache__ *.tix coverage .hpc +imports.png diff --git a/nix/devtools.nix b/nix/devtools.nix index f272bfb24d..b3a0bc6cb3 100644 --- a/nix/devtools.nix +++ b/nix/devtools.nix @@ -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 < imports.png + digraph { + $imports + $labels + } + EOF + ''; in buildEnv { name = "postgrest-devtools"; @@ -106,5 +142,6 @@ buildEnv { run.bin clean.bin check.bin + importsgraph.bin ]; }