Skip to content

Commit 3c98c5c

Browse files
Version 1.0.0
- Keep the graph in the buffer until next header or scope end - Update README - Refactor, cleanup
1 parent a4d25b1 commit 3c98c5c

9 files changed

Lines changed: 72 additions & 62 deletions

File tree

README.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,22 @@ Usage:
1919
mermaid-graph [options]
2020
2121
Options:
22-
--path <path> Full path to the solution (*.sln) or project (*.csproj) file that will be mapped.
23-
--version Show version information
24-
-?, -h, --help Show help and usage information
25-
```
22+
--path <path> Full path to the solution (*.sln) or project (*.csproj) file that will be mapped.
23+
--type <Class|Graph> The type of diagram to generate (e.g., Graph or Class). [default: Graph]
24+
--version Show version information
25+
-?, -h, --help Show help and usage information
26+
```
2627

2728
## Example output from this solution
2829

30+
You can run the following command to generate a class diagram for this solution:
31+
32+
```powershell
33+
.\mermaid-graph.exe --path "MermaidGraph.NET.sln" --type Class
34+
```
35+
36+
This will generate a mermaid graph in the console output, which can be piped to a file and used in a markdown document.
37+
2938
```mermaid
3039
---
3140
title: MermaidGraph.NET.sln
@@ -78,6 +87,16 @@ classDiagram
7887
version 6.0.4
7988
}
8089
MermaidGraphTests ..> coverlet.msbuild
90+
class Microsoft.ClearScript.V8{
91+
type NuGet
92+
version 7.4.5
93+
}
94+
MermaidGraphTests ..> Microsoft.ClearScript.V8
95+
class Microsoft.ClearScript.V8.Native.win-x64{
96+
type NuGet
97+
version 7.4.5
98+
}
99+
MermaidGraphTests ..> Microsoft.ClearScript.V8.Native.win-x64
81100
class Microsoft.NET.Test.Sdk{
82101
type NuGet
83102
version 17.13.0

mermaid-graph/Commands.cs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
1-
using System.Diagnostics;
2-
using MermaidGraph.Diagrams;
1+
using MermaidGraph.Diagrams;
32

43
namespace MermaidGraph;
54

65
/// <summary>
7-
/// Specifies the type of mermaid diagram to generate.
8-
/// </summary>
9-
public enum DiagramType
10-
{
11-
/// <summary>
12-
/// Represents a general dependency graph.
13-
/// </summary>
14-
Graph,
15-
16-
/// <summary>
17-
/// Represents a class diagram.
18-
/// </summary>
19-
Class
20-
}
21-
22-
/// <summary>
23-
/// The commands that can be run by `mermaid-graph`
6+
/// The commands that can be run by `mermaid-graph`.
247
/// </summary>
258
public class Commands
269
{
@@ -48,7 +31,7 @@ public static string Solution(FileInfo file, DiagramType diagramType = DiagramTy
4831
return graph.Solution(file);
4932
}
5033

51-
private static Diagram GetGraphType(DiagramType diagramType) => diagramType switch
34+
private static IMermaidDiagram GetGraphType(DiagramType diagramType) => diagramType switch
5235
{
5336
DiagramType.Class => new ClassDiagram(),
5437
DiagramType.Graph => new GraphDiagram(),

mermaid-graph/Diagrams/ClassDiagram.cs

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

44
namespace MermaidGraph.Diagrams;
55

6-
internal class ClassDiagram : Diagram
6+
internal class ClassDiagram : MermaidDiagram
77
{
88
/// <inheritdoc />
99
public override void Header(string title)
@@ -23,13 +23,10 @@ public override string Project(FileInfo file)
2323
var project = projectCollection.LoadProject(file.FullName);
2424
GraphProject(project);
2525
Graph.AppendLine(Fence);
26-
var graph = Graph.ToString();
2726

28-
// Cleanup
29-
Graph.Clear();
3027
projectCollection.UnloadAllProjects();
3128

32-
return graph;
29+
return Graph.ToString();
3330
}
3431

3532
/// <summary>
@@ -66,13 +63,10 @@ type solution
6663
}
6764

6865
Graph.AppendLine(Fence);
69-
var graph = Graph.ToString();
70-
71-
// Cleanup
72-
Graph.Clear();
66+
7367
projectCollection.UnloadAllProjects();
7468

75-
return graph;
69+
return Graph.ToString();
7670
}
7771

7872
private void GraphProject(Project project)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace MermaidGraph.Diagrams;
2+
3+
/// <summary>
4+
/// Specifies the type of mermaid diagram to generate.
5+
/// </summary>
6+
public enum DiagramType
7+
{
8+
/// <summary>
9+
/// Represents a general dependency graph.
10+
/// </summary>
11+
Graph,
12+
13+
/// <summary>
14+
/// Represents a class diagram.
15+
/// </summary>
16+
Class
17+
}

mermaid-graph/Diagrams/GraphDiagram.cs

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

44
namespace MermaidGraph.Diagrams;
55

6-
internal class GraphDiagram : Diagram
6+
internal class GraphDiagram : MermaidDiagram
77
{
88
/// <inheritdoc />
99
public override void Header(string title)
@@ -23,13 +23,10 @@ public override string Project(FileInfo file)
2323
var project = projectCollection.LoadProject(file.FullName);
2424
GraphProject(project);
2525
Graph.AppendLine(Fence);
26-
var graph = Graph.ToString();
2726

28-
// Cleanup
29-
Graph.Clear();
3027
projectCollection.UnloadAllProjects();
3128

32-
return graph;
29+
return Graph.ToString();
3330
}
3431

3532
/// <summary>
@@ -66,13 +63,10 @@ type solution
6663
}
6764

6865
Graph.AppendLine(Fence);
69-
var graph = Graph.ToString();
70-
71-
// Cleanup
72-
Graph.Clear();
66+
7367
projectCollection.UnloadAllProjects();
7468

75-
return graph;
69+
return Graph.ToString();
7670
}
7771

7872
private void GraphProject(Project project)

mermaid-graph/Diagrams/IMermaidDiagram.cs

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

33
/// <summary>
4-
/// This file defines the IMermaidDiagram interface and the Diagram abstract class.
4+
/// This file defines the IMermaidDiagram interface and the MermaidDiagram abstract class.
55
/// The IMermaidDiagram interface provides methods for generating Mermaid diagrams
66
/// from Visual Studio project (*.csproj) and solution (*.sln) files.
77
/// </summary>
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@
44
namespace MermaidGraph.Diagrams;
55

66
/// <summary>
7-
/// The Diagram abstract class implements shared functionality for Mermaid diagram generation,
7+
/// The MermaidDiagram abstract class implements shared functionality for Mermaid diagram generation,
88
/// including initializing the graph output and managing the graph buffer.
99
/// </summary>
10-
public abstract class Diagram : IMermaidDiagram
10+
public abstract class MermaidDiagram : IMermaidDiagram
1111
{
1212
/// <summary>
13-
/// Code block fence
13+
/// Code block fence.
1414
/// </summary>
1515
public const string Fence = "```";
1616

1717
/// <summary>
18-
/// Mermaid code block
18+
/// Mermaid code block.
1919
/// </summary>
2020
public const string MermaidBegin = Fence + "mermaid";
2121

2222
internal readonly StringBuilder Graph = new();
2323

2424
/// <summary>
25-
/// Initialize the Diagram class and ensure MSBuild is registered.
25+
/// Initialize the MermaidDiagram class and ensure MSBuild is registered.
2626
/// </summary>
27-
protected Diagram()
27+
protected MermaidDiagram()
2828
{
2929
if (!MSBuildLocator.IsRegistered)
3030
{
@@ -33,10 +33,11 @@ protected Diagram()
3333
}
3434

3535
/// <summary>
36-
/// Initialize the graph output
36+
/// Initialize the graph output.
3737
/// </summary>
3838
public virtual void Header(string title)
3939
{
40+
Graph.Clear();
4041
Graph.AppendLine(MermaidBegin);
4142
Graph.AppendLine($"""
4243
---

mermaid-graph/Program.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace MermaidGraph;
1+
using MermaidGraph.Diagrams;
2+
3+
namespace MermaidGraph;
24

35
/// <summary>
46
/// mermaid-graph.exe
@@ -9,9 +11,9 @@ public sealed class Program
911
/// Outputs a mermaid graph of the dependency diagram for a project, or whole solution.
1012
/// </summary>
1113
/// <param name="path">Full path to the solution (*.sln) or project (*.csproj) file that will be mapped.</param>
12-
/// <param name="diagramType">The type of diagram to generate (e.g., Graph or Class).</param>
14+
/// <param name="type">The type of diagram to generate (e.g., Graph or Class).</param>
1315
/// <returns>HResult</returns>
14-
public static int Main(string? path, DiagramType diagramType = DiagramType.Graph)
16+
public static int Main(string? path, DiagramType type = DiagramType.Graph)
1517
{
1618
if (path is null)
1719
{
@@ -32,13 +34,13 @@ public static int Main(string? path, DiagramType diagramType = DiagramType.Graph
3234
{
3335
if (path.EndsWith(".csproj"))
3436
{
35-
Console.WriteLine(Commands.Project(file, diagramType));
37+
Console.WriteLine(Commands.Project(file, type));
3638
return 0;
3739
}
3840

3941
if (path.EndsWith(".sln"))
4042
{
41-
Console.WriteLine(Commands.Solution(file, diagramType));
43+
Console.WriteLine(Commands.Solution(file, type));
4244
return 0;
4345
}
4446
}

mermaid-graphTests/CommandsTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void DogFoodSolutionTest(DiagramType type, string typeName)
5555

5656
[Test]
5757
[TestCaseSource(nameof(DiagramTypeTestCases))]
58-
public void DogFoodProjectTestAsync(DiagramType type, string typeName)
58+
public void DogFoodProjectTest(DiagramType type, string typeName)
5959
{
6060
var filePath = FindFileDownTree("*.csproj");
6161
Assert.That(filePath, Is.Not.Null);
@@ -100,11 +100,11 @@ public void CommandLineFailTests(string? file, int hResult)
100100

101101
private static string ExtractMermaid(string? markup)
102102
{
103-
Assert.That(markup, Does.StartWith(Diagram.MermaidBegin));
104-
markup = markup.Substring(Diagram.MermaidBegin.Length + Environment.NewLine.Length);
103+
Assert.That(markup, Does.StartWith(MermaidDiagram.MermaidBegin));
104+
markup = markup.Substring(MermaidDiagram.MermaidBegin.Length + Environment.NewLine.Length);
105105

106-
Assert.That(markup, Does.EndWith(Diagram.Fence + Environment.NewLine));
107-
return markup.Substring(0, markup.Length - Diagram.MermaidBegin.Length + Environment.NewLine.Length);
106+
Assert.That(markup, Does.EndWith(MermaidDiagram.Fence + Environment.NewLine));
107+
return markup.Substring(0, markup.Length - MermaidDiagram.MermaidBegin.Length + Environment.NewLine.Length);
108108
}
109109

110110
private string? DetectType(string markup)

0 commit comments

Comments
 (0)