Skip to content

Commit 3e79d2c

Browse files
Merge pull request #5 from A9G-Data-Droid/AddFiltering
Add filtering
2 parents b3ded83 + b3796c7 commit 3e79d2c

18 files changed

+383
-179
lines changed

.github/workflows/publish.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
22

33
name: publish
4+
permissions:
5+
contents: read
6+
pull-requests: write
7+
48
on:
59
workflow_dispatch: # Allow running the workflow manually from the GitHub UI
610
push:

Directory.Build.props

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<PackageReference Include="Nerdbank.GitVersioning" Condition="!Exists('packages.config')">
5+
<PrivateAssets>all</PrivateAssets>
6+
<Version>3.7.115</Version>
7+
</PackageReference>
8+
</ItemGroup>
9+
</Project>

MermaidGraph.NET.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ classDiagram
1616
}
1717
class Microsoft.Build{
1818
type NuGet
19-
version 17.12.6
19+
version 17.13.9
2020
}
2121
mermaid-graph ..> Microsoft.Build
2222
class Microsoft.Build.Locator{
2323
type NuGet
24-
version 1.7.8
24+
version 1.9.1
2525
}
2626
mermaid-graph ..> Microsoft.Build.Locator
2727
class Microsoft.Build.Utilities.Core{
2828
type NuGet
29-
version 17.12.6
29+
version 17.13.9
3030
}
3131
mermaid-graph ..> Microsoft.Build.Utilities.Core
3232
class System.CommandLine.DragonFruit{
@@ -50,19 +50,29 @@ classDiagram
5050
version 6.0.4
5151
}
5252
MermaidGraphTests ..> coverlet.msbuild
53+
class Microsoft.ClearScript.V8{
54+
type NuGet
55+
version 7.5.0
56+
}
57+
MermaidGraphTests ..> Microsoft.ClearScript.V8
58+
class Microsoft.ClearScript.V8.Native.win-x64{
59+
type NuGet
60+
version 7.5.0
61+
}
62+
MermaidGraphTests ..> Microsoft.ClearScript.V8.Native.win-x64
5363
class Microsoft.NET.Test.Sdk{
5464
type NuGet
5565
version 17.13.0
5666
}
5767
MermaidGraphTests ..> Microsoft.NET.Test.Sdk
5868
class MSTest.TestAdapter{
5969
type NuGet
60-
version 3.7.3
70+
version 3.8.3
6171
}
6272
MermaidGraphTests ..> MSTest.TestAdapter
6373
class MSTest.TestFramework{
6474
type NuGet
65-
version 3.7.3
75+
version 3.8.3
6676
}
6777
MermaidGraphTests ..> MSTest.TestFramework
6878
class NUnit{
@@ -72,12 +82,13 @@ classDiagram
7282
MermaidGraphTests ..> NUnit
7383
class NUnit.Analyzers{
7484
type NuGet
75-
version 4.6.0
85+
version 4.7.0
7686
}
7787
MermaidGraphTests ..> NUnit.Analyzers
7888
class NUnit3TestAdapter{
7989
type NuGet
80-
version 4.3.2
90+
version 5.0.0
8191
}
8292
MermaidGraphTests ..> NUnit3TestAdapter
8393
```
94+

MermaidGraph.NET.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C33AF3DC-C3F9-45B6-828C-57CB2B60EC96}"
99
ProjectSection(SolutionItems) = preProject
1010
MermaidGraph.NET.md = MermaidGraph.NET.md
11+
.github\workflows\publish.yml = .github\workflows\publish.yml
1112
README.md = README.md
13+
version.json = version.json
1214
EndProjectSection
1315
EndProject
1416
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MermaidGraphTests", "mermaid-graphTests\MermaidGraphTests.csproj", "{FADD9D23-431E-4C1B-B2D4-D4FDF0674FCA}"

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Create a mermaid graph of the dependency diagram for a project, or whole solution.
66

7-
## Dotnet tool [![NuGet version (mermaid-graph)](https://img.shields.io/nuget/v/mermaid-graph.svg?style=flat-square)](https://www.nuget.org/packages/mermaid-graph/)
7+
## Dotnet tool [![NuGet version (mermaid-graph)](https://img.shields.io/nuget/v/mermaid-graph.svg?style=flat-round)](https://www.nuget.org/packages/mermaid-graph/)
88

99
You can install as a dotnet tool so you can easily map all of your software projects:
1010

@@ -21,6 +21,8 @@ Usage:
2121
Options:
2222
--path <path> Full path to the solution (*.sln) or project (*.csproj) file that will be mapped.
2323
--type <Class|Graph> The type of diagram to generate (e.g., Graph or Class). [default: Graph]
24+
--filter <filter> Exclude projects whose name matches the filter. (e.g., Test). []
25+
--no-nuget Do not include NuGet packages in the graph. [default: False]
2426
--version Show version information
2527
-?, -h, --help Show help and usage information
2628
```
@@ -53,17 +55,17 @@ classDiagram
5355
}
5456
class Microsoft.Build{
5557
type NuGet
56-
version 17.12.6
58+
version 17.13.9
5759
}
5860
mermaid-graph ..> Microsoft.Build
5961
class Microsoft.Build.Locator{
6062
type NuGet
61-
version 1.7.8
63+
version 1.9.1
6264
}
6365
mermaid-graph ..> Microsoft.Build.Locator
6466
class Microsoft.Build.Utilities.Core{
6567
type NuGet
66-
version 17.12.6
68+
version 17.13.9
6769
}
6870
mermaid-graph ..> Microsoft.Build.Utilities.Core
6971
class System.CommandLine.DragonFruit{
@@ -89,12 +91,12 @@ classDiagram
8991
MermaidGraphTests ..> coverlet.msbuild
9092
class Microsoft.ClearScript.V8{
9193
type NuGet
92-
version 7.4.5
94+
version 7.5.0
9395
}
9496
MermaidGraphTests ..> Microsoft.ClearScript.V8
9597
class Microsoft.ClearScript.V8.Native.win-x64{
9698
type NuGet
97-
version 7.4.5
99+
version 7.5.0
98100
}
99101
MermaidGraphTests ..> Microsoft.ClearScript.V8.Native.win-x64
100102
class Microsoft.NET.Test.Sdk{
@@ -104,12 +106,12 @@ classDiagram
104106
MermaidGraphTests ..> Microsoft.NET.Test.Sdk
105107
class MSTest.TestAdapter{
106108
type NuGet
107-
version 3.7.3
109+
version 3.8.3
108110
}
109111
MermaidGraphTests ..> MSTest.TestAdapter
110112
class MSTest.TestFramework{
111113
type NuGet
112-
version 3.7.3
114+
version 3.8.3
113115
}
114116
MermaidGraphTests ..> MSTest.TestFramework
115117
class NUnit{
@@ -119,12 +121,12 @@ classDiagram
119121
MermaidGraphTests ..> NUnit
120122
class NUnit.Analyzers{
121123
type NuGet
122-
version 4.6.0
124+
version 4.7.0
123125
}
124126
MermaidGraphTests ..> NUnit.Analyzers
125127
class NUnit3TestAdapter{
126128
type NuGet
127-
version 4.3.2
129+
version 5.0.0
128130
}
129131
MermaidGraphTests ..> NUnit3TestAdapter
130132
```

mermaid-graph/Commands.cs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using MermaidGraph.Diagrams;
1+
using MermaidGraph.Diagrams.Base;
22

33
namespace MermaidGraph;
44

@@ -10,31 +10,20 @@ public class Commands
1010
/// <summary>
1111
/// Generate the dependency graph of a Visual Studio Project.
1212
/// </summary>
13-
/// <param name="file">`.csproj` file.</param>
14-
/// <param name="diagramType"></param>
15-
public static string Project(FileInfo file, DiagramType diagramType = DiagramType.Graph)
13+
public static string Project(FileInfo file, DiagramType diagramType = DiagramType.Graph, string? filter = null, bool excludeNuget = false)
1614
{
17-
var graph = GetGraphType(diagramType);
15+
var graph = MermaidDiagram.GetDiagramType(diagramType);
1816

19-
return graph.Project(file);
17+
return graph.Project(file, filter, excludeNuget);
2018
}
2119

2220
/// <summary>
2321
/// Generate the dependency graph of a Visual Studio Solution.
2422
/// </summary>
25-
/// <param name="file">`.sln` file.</param>
26-
/// <param name="diagramType"></param>
27-
public static string Solution(FileInfo file, DiagramType diagramType = DiagramType.Graph)
23+
public static string Solution(FileInfo file, DiagramType diagramType = DiagramType.Graph, string? filter = null, bool excludeNuget = false)
2824
{
29-
var graph = GetGraphType(diagramType);
25+
var graph = MermaidDiagram.GetDiagramType(diagramType);
3026

31-
return graph.Solution(file);
27+
return graph.Solution(file, filter, excludeNuget);
3228
}
33-
34-
private static IMermaidDiagram GetGraphType(DiagramType diagramType) => diagramType switch
35-
{
36-
DiagramType.Class => new ClassDiagram(),
37-
DiagramType.Graph => new GraphDiagram(),
38-
_ => throw new NotImplementedException($"Option not supported: {diagramType}"),
39-
};
4029
}

mermaid-graph/Diagrams/DiagramType.cs renamed to mermaid-graph/Diagrams/Base/DiagramType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace MermaidGraph.Diagrams;
1+
namespace MermaidGraph.Diagrams.Base;
22

33
/// <summary>
44
/// Specifies the type of mermaid diagram to generate.

mermaid-graph/Diagrams/IMermaidDiagram.cs renamed to mermaid-graph/Diagrams/Base/IMermaidDiagram.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace MermaidGraph.Diagrams;
1+
namespace MermaidGraph.Diagrams.Base;
22

33
/// <summary>
44
/// This file defines the IMermaidDiagram interface and the MermaidDiagram abstract class.
@@ -11,13 +11,17 @@ public interface IMermaidDiagram
1111
/// Generate the diagram from a visual studio project file (*.csproj)
1212
/// </summary>
1313
/// <param name="file">The project file</param>
14+
/// <param name="filter">Exclude projects whose name matches the filter. (e.g., Test)</param>
15+
/// <param name="excludeNuget">Do not include NuGet packages in the graph</param>
1416
/// <returns>Mermaid Markdown</returns>
15-
public string Project(FileInfo file);
17+
public string Project(FileInfo file, string? filter = null, bool excludeNuget = false);
1618

1719
/// <summary>
1820
/// Generate the diagram from a visual studio solution file (*.sln)
1921
/// </summary>
2022
/// <param name="file">The solution file.</param>
23+
/// <param name="filter">Exclude projects whose name matches the filter. (e.g., Test)</param>
24+
/// <param name="excludeNuget">Do not include NuGet packages in the graph</param>
2125
/// <returns>Mermaid Markdown</returns>
22-
public string Solution(FileInfo file);
26+
public string Solution(FileInfo file, string? filter = null, bool excludeNuget = false);
2327
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using System.Text;
2+
using Microsoft.Build.Evaluation;
3+
using Microsoft.Build.Locator;
4+
5+
namespace MermaidGraph.Diagrams.Base;
6+
7+
/// <summary>
8+
/// The MermaidDiagram abstract class implements shared functionality for Mermaid diagram generation,
9+
/// including initializing the graph output and managing the graph buffer.
10+
/// </summary>
11+
public abstract class MermaidDiagram : IMermaidDiagram
12+
{
13+
/// <summary>
14+
/// Code block fence.
15+
/// </summary>
16+
public const string Fence = "```";
17+
18+
/// <summary>
19+
/// Mermaid code block.
20+
/// </summary>
21+
public const string MermaidBegin = Fence + "mermaid";
22+
23+
internal StringBuilder Graph { get; } = new(256);
24+
25+
/// <summary>
26+
/// Initialize the MermaidDiagram class and ensure MSBuild is registered.
27+
/// </summary>
28+
protected MermaidDiagram()
29+
{
30+
if (!MSBuildLocator.IsRegistered)
31+
{
32+
MSBuildLocator.RegisterDefaults();
33+
}
34+
}
35+
36+
/// <summary>
37+
/// Factory method to get the appropriate graph type based on the provided DiagramType enum value.
38+
/// </summary>
39+
/// <param name="diagramType">The type of graph to generate.</param>
40+
/// <returns>The appropriate methods for generating a diagram of that type.</returns>
41+
/// <exception cref="NotImplementedException">If an enum type is added without corresponding diagram class.</exception>
42+
public static IMermaidDiagram GetDiagramType(DiagramType diagramType) => diagramType switch
43+
{
44+
DiagramType.Class => new ClassDiagram(),
45+
DiagramType.Graph => new GraphDiagram(),
46+
_ => throw new NotImplementedException($"Option not supported: {diagramType}"),
47+
};
48+
49+
/// <summary>
50+
/// Initialize the graph output.
51+
/// </summary>
52+
public virtual void Header(string title)
53+
{
54+
Graph.Clear();
55+
Graph.AppendLine($"""
56+
{MermaidBegin}
57+
---
58+
title: {title}
59+
config:
60+
class:
61+
hideEmptyMembersBox: true
62+
---
63+
""");
64+
}
65+
66+
/// <summary>
67+
/// Get the mermaid diagram Markdown text.
68+
/// </summary>
69+
/// <returns>The contents of the graph buffer.</returns>
70+
public override string ToString() => Graph.ToString();
71+
72+
/// <inheritdoc />
73+
public virtual string Project(FileInfo file, string? filter = null, bool excludeNuget = false)
74+
{
75+
Header(file.Name);
76+
using var projectCollection = new ProjectCollection();
77+
var project = projectCollection.LoadProject(file.FullName);
78+
GraphProject(project, filter, excludeNuget);
79+
Graph.AppendLine(Fence);
80+
81+
projectCollection.UnloadAllProjects();
82+
83+
return Graph.ToString();
84+
}
85+
86+
/// <inheritdoc />
87+
public abstract string Solution(FileInfo file, string? filter = null, bool excludeNuget = false);
88+
89+
/// <summary>
90+
/// This method must be implemented in all derived classes to generate the graph for a project.
91+
/// </summary>
92+
/// <param name="project">A project to graph.</param>
93+
/// <param name="filter">Exclude projects whose name matches the filter. (e.g., Test)</param>
94+
/// <param name="excludeNuget">Do not include NuGet packages in the graph</param>
95+
internal abstract void GraphProject(Project project, string? filter = null, bool excludeNuget = false);
96+
}

0 commit comments

Comments
 (0)