@@ -22,132 +22,29 @@ public static string GetProjectStructure(string path, int indent = 0)
2222 . ToList ( ) ;
2323
2424 var sb = new StringBuilder ( ) ;
25-
26- // Group files by their type/purpose
27- var files = entries . Where ( e => ! Directory . Exists ( e ) )
28- . Select ( f => new FileInfo ( f ) )
29- . ToList ( ) ;
30-
31- var projectFiles = files . Where ( f => f . Extension == ".csproj" || f . Extension == ".sln" ) ;
32- var configFiles = files . Where ( f =>
33- f . Name . StartsWith ( "appsettings" ) ||
34- f . Name . EndsWith ( ".json" ) ||
35- f . Name . EndsWith ( ".yml" ) ||
36- f . Name . EndsWith ( ".config" ) ) ;
37- var sourceFiles = files . Where ( f =>
38- f . Extension == ".cs" ||
39- f . Extension == ".ts" ||
40- f . Extension == ".js" ||
41- f . Extension == ".py" ) ;
42- var otherFiles = files . Except ( projectFiles )
43- . Except ( configFiles )
44- . Except ( sourceFiles ) ;
45-
46- // Add project overview if it's the root
47- if ( indent == 0 )
48- {
49- var projFiles = projectFiles . ToList ( ) ;
50- if ( projFiles . Any ( ) )
51- {
52- sb . AppendLine ( "📦 Project Files:" ) ;
53- foreach ( var proj in projFiles )
54- {
55- WriteProgress ( files . IndexOf ( proj ) + 1 , files . Count ) ;
56- sb . AppendLine ( $ "{ new string ( ' ' , ( indent + 1 ) * 2 ) } [{ proj . Extension } ] { proj . Name } ") ;
57- }
58- }
59-
60- var configs = configFiles . ToList ( ) ;
61- if ( configs . Any ( ) )
62- {
63- sb . AppendLine ( "\n ⚙️ Configuration Files:" ) ;
64- foreach ( var config in configs )
65- {
66- WriteProgress ( files . IndexOf ( config ) + 1 , files . Count ) ;
67- // Extract environment for appsettings files
68- var env = config . Name . Contains ( "appsettings." )
69- ? $ "({ config . Name . Split ( '.' ) [ 1 ] } ) "
70- : "" ;
71- sb . AppendLine ( $ "{ new string ( ' ' , ( indent + 1 ) * 2 ) } [{ config . Extension } ] { config . Name } { env } ") ;
72- }
73- }
74- }
75-
76- // Add source files
77- var srcFiles = sourceFiles . ToList ( ) ;
78- if ( srcFiles . Any ( ) )
79- {
80- if ( indent == 0 ) sb . AppendLine ( "\n 💻 Source Files:" ) ;
81- foreach ( var src in srcFiles )
82- {
83- WriteProgress ( files . IndexOf ( src ) + 1 , files . Count ) ;
84- var filePurpose = GetFilePurpose ( src . Name ) ;
85- sb . AppendLine ( $ "{ new string ( ' ' , ( indent + 1 ) * 2 ) } [{ src . Extension } ] { src . Name } { filePurpose } ") ;
86- }
87- }
88-
89- // Add remaining files
90- var remaining = otherFiles . ToList ( ) ;
91- if ( remaining . Any ( ) )
25+
26+ // Process all entries
27+ for ( int i = 0 ; i < entries . Count ; i ++ )
9228 {
93- if ( indent == 0 ) sb . AppendLine ( "\n 📄 Other Files:" ) ;
94- foreach ( var file in remaining )
29+ WriteProgress ( i + 1 , entries . Count ) ;
30+ var entry = entries [ i ] ;
31+
32+ if ( Directory . Exists ( entry ) )
9533 {
96- WriteProgress ( files . IndexOf ( file ) + 1 , files . Count ) ;
97- sb . AppendLine ( $ "{ new string ( ' ' , ( indent + 1 ) * 2 ) } { file . Name } ") ;
34+ var dir = new DirectoryInfo ( entry ) ;
35+ sb . AppendLine ( $ "{ new string ( ' ' , indent * 2 ) } [{ dir . Name } /]")
36+ . Append ( GetProjectStructure ( entry , indent + 1 ) ) ;
9837 }
99- }
100-
101- // Process subdirectories
102- var directories = entries . Where ( e => Directory . Exists ( e ) )
103- . Select ( d => new DirectoryInfo ( d ) )
104- . ToList ( ) ;
105-
106- if ( directories . Any ( ) )
107- {
108- if ( indent == 0 ) sb . AppendLine ( "\n 📂 Directories:" ) ;
109- foreach ( var dir in directories )
38+ else
11039 {
111- var dirPurpose = GetDirectoryPurpose ( dir . Name ) ;
112- sb . AppendLine ( $ "{ new string ( ' ' , ( indent + 1 ) * 2 ) } [{ dir . Name } /] { dirPurpose } ")
113- . Append ( GetProjectStructure ( dir . FullName , indent + 1 ) ) ;
40+ var file = new FileInfo ( entry ) ;
41+ sb . AppendLine ( $ "{ new string ( ' ' , indent * 2 ) } [{ file . Extension } ] { file . Name } ") ;
11442 }
11543 }
11644
11745 return sb . ToString ( ) ;
11846 }
11947
120- private static string GetFilePurpose ( string fileName ) => fileName . ToLower ( ) switch
121- {
122- var n when n . EndsWith ( "controller.cs" ) => "(API Endpoint)" ,
123- var n when n . EndsWith ( "service.cs" ) => "(Business Logic)" ,
124- var n when n . EndsWith ( "repository.cs" ) => "(Data Access)" ,
125- var n when n . EndsWith ( "model.cs" ) => "(Data Model)" ,
126- var n when n . EndsWith ( "request.cs" ) => "(API Request)" ,
127- var n when n . EndsWith ( "response.cs" ) => "(API Response)" ,
128- var n when n . EndsWith ( "dto.cs" ) => "(Data Transfer)" ,
129- var n when n . EndsWith ( "mapper.cs" ) => "(Object Mapping)" ,
130- var n when n == "program.cs" => "(Application Entry)" ,
131- var n when n == "startup.cs" => "(App Configuration)" ,
132- _ => ""
133- } ;
134-
135- private static string GetDirectoryPurpose ( string dirName ) => dirName . ToLower ( ) switch
136- {
137- "controllers" => "(API Endpoints)" ,
138- "services" => "(Business Logic)" ,
139- "models" => "(Data Models)" ,
140- "views" => "(UI Templates)" ,
141- "repositories" => "(Data Access)" ,
142- "tests" => "(Test Cases)" ,
143- "migrations" => "(DB Migrations)" ,
144- "scripts" => "(Utility Scripts)" ,
145- "docs" => "(Documentation)" ,
146- "config" => "(Configuration)" ,
147- "wwwroot" => "(Static Files)" ,
148- _ => ""
149- } ;
150-
15148 public static string GetFileContents ( string path )
15249 {
15350 if ( GitRepoRoot == null ) GitRepoRoot = FindGitRepoRoot ( path ) ;
0 commit comments