Skip to content

Commit 35a4909

Browse files
NuGet package alpha
- Round solution edges - Refactor - Organize - Get ready for testing
1 parent 03d8d77 commit 35a4909

File tree

8 files changed

+114
-50
lines changed

8 files changed

+114
-50
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,4 @@ FodyWeavers.xsd
396396

397397
# JetBrains Rider
398398
*.sln.iml
399+
*.xcf

MermaidGraph.NET.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
4-
VisualStudioVersion = 17.12.35707.178 d17.12
4+
VisualStudioVersion = 17.12.35707.178
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mermaid-graph", "mermaid-graph\mermaid-graph.csproj", "{BDC56E20-7574-4734-B3F2-DD75C08B2FBC}"
77
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C33AF3DC-C3F9-45B6-828C-57CB2B60EC96}"
9+
ProjectSection(SolutionItems) = preProject
10+
MermaidGraph.NET.md = MermaidGraph.NET.md
11+
README.md = README.md
12+
EndProjectSection
13+
EndProject
814
Global
915
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1016
Debug|Any CPU = Debug|Any CPU

mermaid-graph.ico

10.1 KB
Binary file not shown.

mermaid-graph.png

8.99 KB
Loading

mermaid-graph/Commands.cs

Lines changed: 64 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,72 +7,92 @@ namespace MermaidGraph;
77
/// <summary>
88
/// The commands that can be run by `mermaid-graph`
99
/// </summary>
10-
public static class Commands
10+
public class Commands
1111
{
12-
private static readonly StringBuilder Graph = new();
12+
private readonly StringBuilder _graph;
1313

1414
private const string Fence = "```";
1515

16-
static Commands()
16+
/// <summary>
17+
/// Initialize the graph output
18+
/// </summary>
19+
public Commands()
1720
{
18-
Graph.AppendLine(Fence + "mermaid");
19-
Graph.AppendLine("graph TD");
21+
_graph = new StringBuilder();
2022
}
2123

2224
/// <summary>
2325
/// Generate the dependency graph of a Visual Studio Project.
2426
/// </summary>
25-
/// <param name="path">Full path to `.csproj` file.</param>
26-
public static void Project(string path)
27+
/// <param name="file">`.csproj` file.</param>
28+
public string Project(FileInfo file)
2729
{
28-
GraphProject(path);
29-
Graph.AppendLine(Fence);
30-
Console.WriteLine(Graph.ToString());
31-
}
32-
33-
private static void GraphProject(string path)
34-
{
35-
// Load project
36-
var project = new Project(path);
37-
var projectName = Path.GetFileNameWithoutExtension(path);
38-
39-
foreach (var item in project.GetItems("ProjectReference"))
40-
{
41-
string refPath = item.EvaluatedInclude;
42-
string refName = Path.GetFileNameWithoutExtension(refPath);
43-
Graph.AppendLine($" {projectName} --> {refName}");
44-
}
45-
46-
foreach (var item in project.GetItems("PackageReference"))
47-
{
48-
string packageName = item.EvaluatedInclude;
49-
Graph.AppendLine($" {projectName} -->|NuGet| {packageName}");
50-
}
30+
Header(file.Name);
31+
GraphProject(file);
32+
_graph.AppendLine(Fence);
33+
var graph = _graph.ToString();
34+
_graph.Clear();
35+
return graph;
5136
}
5237

5338
/// <summary>
5439
/// Generate the dependency graph of a Visual Studio Solution.
5540
/// </summary>
56-
/// <param name="path">Full path to `.sln` file.</param>
57-
public static void Solution(string path)
41+
/// <param name="file">`.sln` file.</param>
42+
public string Solution(FileInfo file)
5843
{
59-
var solutionFile = SolutionFile.Parse(path);
60-
var solutionName = Path.GetFileNameWithoutExtension(path);
44+
Header(file.Name);
45+
var solutionFile = SolutionFile.Parse(file.FullName);
46+
var solutionName = Path.GetFileNameWithoutExtension(file.Name);
47+
var solutionId = $"s{solutionFile.GetHashCode()}({solutionName})";
6148
foreach (var project in solutionFile.ProjectsInOrder)
6249
{
63-
if (project.ProjectType == SolutionProjectType.KnownToBeMSBuildFormat)
50+
if (project.ProjectType != SolutionProjectType.KnownToBeMSBuildFormat) continue;
51+
52+
var projectPath = project.AbsolutePath;
53+
var projectName = Path.GetFileNameWithoutExtension(projectPath);
54+
_graph.AppendLine($" {solutionId} --> {projectName}");
55+
var projectFile = new FileInfo(projectPath);
56+
if (projectFile.Exists)
6457
{
65-
var projectPath = project.AbsolutePath;
66-
var projectName = Path.GetFileNameWithoutExtension(projectPath);
67-
Graph.AppendLine($" {solutionName} --> {projectName}");
68-
if (File.Exists(projectPath))
69-
{
70-
GraphProject(projectPath);
71-
}
58+
GraphProject(projectFile);
7259
}
7360
}
7461

75-
Graph.AppendLine(Fence);
76-
Console.WriteLine(Graph.ToString());
62+
_graph.AppendLine(Fence);
63+
var graph = _graph.ToString();
64+
_graph.Clear();
65+
return graph;
66+
}
67+
68+
private void Header(string title)
69+
{
70+
_graph.AppendLine(Fence + "mermaid");
71+
_graph.AppendLine($"""
72+
---
73+
title: {title}
74+
---
75+
""");
76+
77+
_graph.AppendLine("graph TD");
78+
}
79+
80+
private void GraphProject(FileInfo path)
81+
{
82+
var project = new Project(path.FullName);
83+
var projectName = Path.GetFileNameWithoutExtension(path.Name);
84+
85+
foreach (var item in project.GetItems("ProjectReference"))
86+
{
87+
var refPath = item.EvaluatedInclude;
88+
var refName = Path.GetFileNameWithoutExtension(refPath);
89+
_graph.AppendLine($" {projectName} --> {refName}");
90+
}
91+
92+
foreach (var item in project.GetItems("PackageReference"))
93+
{
94+
var packageName = item.EvaluatedInclude;
95+
_graph.AppendLine($" {projectName} -->|NuGet| {packageName}");
96+
}
7797
}
7898
}

mermaid-graph/Program.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ internal sealed class Program
1414
/// </summary>
1515
/// <param name="path">Full path to the solution (*.sln) or project (*.csproj) file that will be mapped.</param>
1616
/// <returns>HResult</returns>
17-
internal static int Main(string path)
17+
internal static int Main(string? path)
1818
{
19+
if (path is null)
20+
{
21+
System.CommandLine.DragonFruit.CommandLine.ExecuteAssembly(typeof(AutoGeneratedProgram).Assembly, ["--help"], "");
22+
return 1;
23+
}
24+
1925
var file = new FileInfo(path);
2026
if (!file.Exists)
2127
{
2228
Console.WriteLine($"Error: File not found - {path}");
23-
return 1;
29+
return 2;
2430
}
2531

2632
try
@@ -33,13 +39,13 @@ internal static int Main(string path)
3339

3440
if (path.EndsWith(".csproj"))
3541
{
36-
Commands.Project(file.FullName);
42+
Console.WriteLine(new Commands().Project(file));
3743
return 0;
3844
}
3945

4046
if (path.EndsWith(".sln"))
4147
{
42-
Commands.Solution(file.FullName);
48+
Console.WriteLine(new Commands().Solution(file));
4349
return 0;
4450
}
4551
}
@@ -50,6 +56,6 @@ internal static int Main(string path)
5056
}
5157

5258
Console.WriteLine($"Error: Unsupported file type - {path}");
53-
return 2;
59+
return 3;
5460
}
5561
}

mermaid-graph/mermaid-graph.csproj

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@
1111
<AnalysisLevel>latest-recommended</AnalysisLevel>
1212
<PackAsTool>True</PackAsTool>
1313
<StartupObject>MermaidGraph.Program</StartupObject>
14+
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
15+
<PublishTrimmed>False</PublishTrimmed>
16+
<Title>MermaidGraph.NET</Title>
17+
<Authors>A9G-Data-Droid</Authors>
18+
<Description>Create a mermaid graph of the dependency diagram for a project, or whole solution.</Description>
19+
<Copyright>Copyright $([System.DateTime]::Now.Year) $(Company)</Copyright>
20+
<PackageProjectUrl>https://github.com/A9G-Data-Droid/MermaidGraph.NET</PackageProjectUrl>
21+
<PackageReadmeFile>README.md</PackageReadmeFile>
22+
<RepositoryUrl>https://github.com/A9G-Data-Droid/MermaidGraph.NET.git</RepositoryUrl>
23+
<PackageTags>mermaid.js</PackageTags>
24+
<NeutralLanguage>en</NeutralLanguage>
25+
<FileVersion>$(AssemblyVersion)</FileVersion>
26+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
27+
<PackageIcon>mermaid-graph.png</PackageIcon>
28+
<ApplicationIcon>mermaid-graph.ico</ApplicationIcon>
29+
<Version>1.0.0-alpha</Version>
1430
</PropertyGroup>
1531

1632
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -23,6 +39,21 @@
2339
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
2440
</PropertyGroup>
2541

42+
<ItemGroup>
43+
<Content Include="mermaid-graph.ico" />
44+
</ItemGroup>
45+
46+
<ItemGroup>
47+
<None Include="..\mermaid-graph.png">
48+
<Pack>True</Pack>
49+
<PackagePath>\</PackagePath>
50+
</None>
51+
<None Include="..\README.md">
52+
<Pack>True</Pack>
53+
<PackagePath>\</PackagePath>
54+
</None>
55+
</ItemGroup>
56+
2657
<ItemGroup>
2758
<PackageReference Include="Microsoft.Build" Version="17.12.6" ExcludeAssets="runtime" />
2859
<PackageReference Include="Microsoft.Build.Locator" Version="1.7.8" />

mermaid-graph/mermaid-graph.ico

10.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)