Skip to content

Commit d6d25f5

Browse files
author
LoneWandererProductions
committed
add a new command.
1 parent eb95c41 commit d6d25f5

3 files changed

Lines changed: 116 additions & 3 deletions

File tree

Core.Apps/CommandFactory.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static IReadOnlyList<ICommand> GetCommands(Weave? weave = null)
4242
new UnusedLocalVariableAnalyzer(), new UnusedParameterAnalyzer(), new UnusedPrivateFieldAnalyzer(),
4343
new DocCommentCoverageCommand(), new DeadReferenceAnalyzer(), new ApiExplorerCommand(),
4444
new FileLockScanner(weave.Runtime.Variables), new SmartPingPro(),
45-
new WhoAmI(weave.Runtime.Variables), new Tree()
45+
new WhoAmI(weave.Runtime.Variables), new Tree(), new DependencyExplorer(weave.Runtime.Variables)
4646
};
4747

4848
return modules;
@@ -67,7 +67,8 @@ public static IReadOnlyList<ICommand> GetCommands(string userSpace, Weave? weave
6767
new UnusedLocalVariableAnalyzer(), new UnusedParameterAnalyzer(), new UnusedPrivateFieldAnalyzer(),
6868
new DocCommentCoverageCommand(), new DeadReferenceAnalyzer(), new ApiExplorerCommand(),
6969
new FileLockScanner(weave.Runtime.Variables), new SmartPingPro(),
70-
new WhoAmI(weave.Runtime.Variables), new Tree()
70+
new WhoAmI(weave.Runtime.Variables), new Tree(),
71+
new DependencyExplorer(weave.Runtime.Variables),
7172
};
7273

7374
// Filter by Namespace

Core.Apps/Development/ApiExplorerCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public sealed class ApiExplorerCommand : ICommand
4242
/// <inheritdoc />
4343
public CommandSignature Signature => new(Namespace, Name, ParameterCount);
4444

45-
4645
/// <inheritdoc />
4746
/// <summary>
4847
/// folder + optional outputMode
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* COPYRIGHT: See COPYING in the top level directory
3+
* PROJECT: Core.Apps.Development
4+
* FILE: DependencyExplorer.cs
5+
* PURPOSE: Maps project-to-project and project-to-library dependencies.
6+
* PROGRAMMER: Peter Geinitz (Wayfarer)
7+
*/
8+
9+
using System.Collections.Generic;
10+
using System.IO;
11+
using System.Linq;
12+
using System.Text;
13+
using System.Xml.Linq;
14+
using Weaver;
15+
using Weaver.Interfaces;
16+
using Weaver.Messages;
17+
using Weaver.Registry;
18+
19+
namespace Core.Apps.Development
20+
{
21+
public sealed class DependencyExplorer : ICommand, IRegistryProducer
22+
{
23+
/// <summary>
24+
/// The variables
25+
/// </summary>
26+
private readonly IVariableRegistry _variables;
27+
28+
/// <inheritdoc />
29+
public string CurrentRegistryKey => "project_map";
30+
31+
/// <inheritdoc />
32+
public EnumTypes DataType => EnumTypes.Wobject;
33+
34+
/// <inheritdoc />
35+
public IVariableRegistry Variables => _variables;
36+
37+
/// <summary>
38+
/// Initializes a new instance of the <see cref="DependencyExplorer"/> class.
39+
/// </summary>
40+
/// <param name="variables">The variables.</param>
41+
public DependencyExplorer(IVariableRegistry variables)
42+
{
43+
_variables = variables;
44+
}
45+
46+
/// <inheritdoc />
47+
public string Name => "depexplore";
48+
49+
/// <inheritdoc />
50+
public string Namespace => "Development";
51+
52+
/// <inheritdoc />
53+
public int ParameterCount => 1;
54+
55+
/// <inheritdoc />
56+
public string Description => "Explores project dependencies and maps them.";
57+
58+
/// <inheritdoc />
59+
public CommandSignature Signature => new(Namespace, Name, ParameterCount);
60+
61+
/// <inheritdoc />
62+
public CommandResult Execute(params string[] args)
63+
{
64+
if (args.Length < 1) return CommandResult.Fail("Usage: depexplore <root_folder>");
65+
66+
var rootPath = args[0];
67+
if (!Directory.Exists(rootPath)) return CommandResult.Fail("Folder not found.");
68+
69+
var projectMap = new Dictionary<string, VmValue>();
70+
var sb = new StringBuilder();
71+
72+
// 1. Find all .csproj files
73+
var projects = Directory.EnumerateFiles(rootPath, "*.csproj", SearchOption.AllDirectories);
74+
75+
foreach (var projFile in projects)
76+
{
77+
var projName = Path.GetFileNameWithoutExtension(projFile);
78+
var doc = XDocument.Load(projFile);
79+
80+
// 2. Extract NuGet Packages
81+
var packages = doc.Descendants("PackageReference")
82+
.Select(x => x.Attribute("Include")?.Value)
83+
.Where(v => v != null)
84+
.ToList();
85+
86+
// 3. Extract Project References
87+
var refs = doc.Descendants("ProjectReference")
88+
.Select(x => Path.GetFileNameWithoutExtension(x.Attribute("Include")?.Value ?? ""))
89+
.Where(v => !string.IsNullOrEmpty(v))
90+
.ToList();
91+
92+
// 4. Create a Sub-Object for this project
93+
var details = new Dictionary<string, VmValue>
94+
{
95+
{ "packages", VmValue.FromString(string.Join(", ", packages)) },
96+
{ "references", VmValue.FromString(string.Join(", ", refs)) }
97+
};
98+
99+
projectMap[projName] = VmValue.FromObject(); // In your registry, this links to the dict
100+
101+
sb.AppendLine($"Project: {projName}");
102+
sb.AppendLine($" - Libraries: {string.Join(", ", packages)}");
103+
sb.AppendLine($" - Projects: {string.Join(", ", refs)}");
104+
sb.AppendLine();
105+
}
106+
107+
// 5. Store in the Registry for WPF or Scripts to use
108+
_variables.SetObject(CurrentRegistryKey, projectMap);
109+
110+
return CommandResult.Ok(sb.ToString(), CurrentRegistryKey, EnumTypes.Wobject);
111+
}
112+
}
113+
}

0 commit comments

Comments
 (0)