Skip to content

Commit

Permalink
stop grouping files
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVeksler committed Nov 24, 2024
1 parent e3052f3 commit 3292baf
Showing 1 changed file with 13 additions and 116 deletions.
129 changes: 13 additions & 116 deletions MyAppsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,132 +22,29 @@ public static string GetProjectStructure(string path, int indent = 0)
.ToList();

var sb = new StringBuilder();

// Group files by their type/purpose
var files = entries.Where(e => !Directory.Exists(e))
.Select(f => new FileInfo(f))
.ToList();

var projectFiles = files.Where(f => f.Extension == ".csproj" || f.Extension == ".sln");
var configFiles = files.Where(f =>
f.Name.StartsWith("appsettings") ||
f.Name.EndsWith(".json") ||
f.Name.EndsWith(".yml") ||
f.Name.EndsWith(".config"));
var sourceFiles = files.Where(f =>
f.Extension == ".cs" ||
f.Extension == ".ts" ||
f.Extension == ".js" ||
f.Extension == ".py");
var otherFiles = files.Except(projectFiles)
.Except(configFiles)
.Except(sourceFiles);

// Add project overview if it's the root
if (indent == 0)
{
var projFiles = projectFiles.ToList();
if (projFiles.Any())
{
sb.AppendLine("📦 Project Files:");
foreach (var proj in projFiles)
{
WriteProgress(files.IndexOf(proj) + 1, files.Count);
sb.AppendLine($"{new string(' ', (indent + 1) * 2)}[{proj.Extension}] {proj.Name}");
}
}

var configs = configFiles.ToList();
if (configs.Any())
{
sb.AppendLine("\n⚙️ Configuration Files:");
foreach (var config in configs)
{
WriteProgress(files.IndexOf(config) + 1, files.Count);
// Extract environment for appsettings files
var env = config.Name.Contains("appsettings.")
? $"({config.Name.Split('.')[1]}) "
: "";
sb.AppendLine($"{new string(' ', (indent + 1) * 2)}[{config.Extension}] {config.Name} {env}");
}
}
}

// Add source files
var srcFiles = sourceFiles.ToList();
if (srcFiles.Any())
{
if (indent == 0) sb.AppendLine("\n💻 Source Files:");
foreach (var src in srcFiles)
{
WriteProgress(files.IndexOf(src) + 1, files.Count);
var filePurpose = GetFilePurpose(src.Name);
sb.AppendLine($"{new string(' ', (indent + 1) * 2)}[{src.Extension}] {src.Name} {filePurpose}");
}
}

// Add remaining files
var remaining = otherFiles.ToList();
if (remaining.Any())

// Process all entries
for (int i = 0; i < entries.Count; i++)
{
if (indent == 0) sb.AppendLine("\n📄 Other Files:");
foreach (var file in remaining)
WriteProgress(i + 1, entries.Count);
var entry = entries[i];

if (Directory.Exists(entry))
{
WriteProgress(files.IndexOf(file) + 1, files.Count);
sb.AppendLine($"{new string(' ', (indent + 1) * 2)}{file.Name}");
var dir = new DirectoryInfo(entry);
sb.AppendLine($"{new string(' ', indent * 2)}[{dir.Name}/]")
.Append(GetProjectStructure(entry, indent + 1));
}
}

// Process subdirectories
var directories = entries.Where(e => Directory.Exists(e))
.Select(d => new DirectoryInfo(d))
.ToList();

if (directories.Any())
{
if (indent == 0) sb.AppendLine("\n📂 Directories:");
foreach (var dir in directories)
else
{
var dirPurpose = GetDirectoryPurpose(dir.Name);
sb.AppendLine($"{new string(' ', (indent + 1) * 2)}[{dir.Name}/] {dirPurpose}")
.Append(GetProjectStructure(dir.FullName, indent + 1));
var file = new FileInfo(entry);
sb.AppendLine($"{new string(' ', indent * 2)}[{file.Extension}] {file.Name}");
}
}

return sb.ToString();
}

private static string GetFilePurpose(string fileName) => fileName.ToLower() switch
{
var n when n.EndsWith("controller.cs") => "(API Endpoint)",
var n when n.EndsWith("service.cs") => "(Business Logic)",
var n when n.EndsWith("repository.cs") => "(Data Access)",
var n when n.EndsWith("model.cs") => "(Data Model)",
var n when n.EndsWith("request.cs") => "(API Request)",
var n when n.EndsWith("response.cs") => "(API Response)",
var n when n.EndsWith("dto.cs") => "(Data Transfer)",
var n when n.EndsWith("mapper.cs") => "(Object Mapping)",
var n when n == "program.cs" => "(Application Entry)",
var n when n == "startup.cs" => "(App Configuration)",
_ => ""
};

private static string GetDirectoryPurpose(string dirName) => dirName.ToLower() switch
{
"controllers" => "(API Endpoints)",
"services" => "(Business Logic)",
"models" => "(Data Models)",
"views" => "(UI Templates)",
"repositories" => "(Data Access)",
"tests" => "(Test Cases)",
"migrations" => "(DB Migrations)",
"scripts" => "(Utility Scripts)",
"docs" => "(Documentation)",
"config" => "(Configuration)",
"wwwroot" => "(Static Files)",
_ => ""
};

public static string GetFileContents(string path)
{
if (GitRepoRoot == null) GitRepoRoot = FindGitRepoRoot(path);
Expand Down

0 comments on commit 3292baf

Please sign in to comment.