Created
February 13, 2024 05:44
-
-
Save mahldcat/b1a7c6486ebb579007046e901a7bdff3 to your computer and use it in GitHub Desktop.
Powershell script to generate a mermaid dep tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| param($slnFile = ".\ProjectWithDeps\ProjectWithDeps.sln") | |
| function Get-ProjectFileWithoutExt{ | |
| param($path) | |
| $fileName = Split-Path -Path $path -Leaf | |
| return $fileName -replace '\.[^.]*$' | |
| } | |
| function Get-ProjectPackages{ | |
| param($path) | |
| $packages = dotnet list $path package | Select-Object -skip 3 | |
| $a = @() | |
| foreach($p in $packages){ | |
| if($p -eq ""){ | |
| continue | |
| } | |
| $pkg = $p -split '\s+' -ne '' | |
| $a+= "$($pkg[1]) $($pkg[3])" | |
| } | |
| return $a | |
| } | |
| $slnPath = Resolve-Path $slnFile | |
| $slnDir = Split-Path -Path $slnPath -Parent | |
| $projects = dotnet sln $slnPath list | Select-Object -skip 2 | |
| Write-Output "flowchart TD" | |
| foreach($project in $projects){ | |
| $projPath = resolve-path (join-Path $slnDir $project) | |
| $projectName =Get-ProjectFileWithoutExt -path $projPath | |
| $projDir = Split-Path -Path $projPath -Parent | |
| $packages=Get-ProjectPackages -path $projPath | |
| Write-Output "$projectName[" | |
| Write-Output " $projectName" | |
| foreach($p in $packages){ | |
| Write-Output " $p" | |
| } | |
| Write-Output "]" | |
| $deps = dotnet list $projPath reference | Select-object -skip 2 | |
| if($deps.Count -gt 0){ | |
| foreach($d in $deps){ | |
| $depPath = Resolve-Path (join-Path $projDir $d) | |
| $depProj = Get-ProjectFileWithoutExt -path $depPath | |
| Write-Output "$projectName --> $depProj" | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment