@@ -71,44 +71,58 @@ public CSTOJS(CSTOJSOptions options)
7171 }
7272
7373 /// <summary>
74- /// Method for generating js file.
74+ /// Method for generating js file/files .
7575 /// </summary>
76- /// <param name="path">Full path to cs file.</param>
77- /// <param name="filename">Filename of a js file. </param>
76+ /// <param name="path">Full path to cs file or to the folder with cs files .</param>
77+ /// <param name="filename">Optional! Filename of a js file if you generating one file! </param>
7878 /// <returns></returns>
7979 public async Task GenerateOneAsync ( string path , string ? filename = null )
8080 {
8181 Assembly assembly = Assembly . GetEntryAssembly ( ) ;
82+ List < FileInfo > files = new ( ) ;
8283
83- FileInfo file = new ( path ) ;
84-
85- SyntaxTree ? _tree = null ;
86-
87- using ( var stream = File . OpenRead ( path ) )
84+ if ( File . Exists ( path ) )
8885 {
89- _tree = CSharpSyntaxTree . ParseText ( SourceText . From ( stream ) , path : path ) ;
86+ files . Add ( new FileInfo ( path ) ) ;
9087 }
88+ else
89+ {
90+ DirectoryInfo folder = new ( path ) ;
9191
92- await GenerateAsync ( _tree , assembly ) ;
92+ files = folder . GetFiles ( "*.cs" ) . ToList ( ) ;
9393
94- if ( ! Directory . Exists ( Options . OutPutPath ) )
95- {
96- Directory . CreateDirectory ( Options . OutPutPath ) ;
94+ filename = null ;
9795 }
9896
99- string pathCombined = string . Empty ;
97+ foreach ( FileInfo file in files )
98+ {
99+ SyntaxTree ? _tree = null ;
100100
101- if ( filename != null )
102- pathCombined = Path . Combine ( Options . OutPutPath , filename ) ;
103- else
104- pathCombined = Path . Combine ( Options . OutPutPath , file . Name . Replace ( ".cs" , ".js" ) ) ;
101+ using ( var stream = File . OpenRead ( file . FullName ) )
102+ {
103+ _tree = CSharpSyntaxTree . ParseText ( SourceText . From ( stream ) , path : file . FullName ) ;
104+ }
105105
106+ await GenerateAsync ( _tree , assembly ) ;
106107
107- await File . WriteAllTextAsync ( pathCombined , _Walker . JSSB . ToString ( ) ) ;
108+ if ( ! Directory . Exists ( Options . OutPutPath ) )
109+ {
110+ Directory . CreateDirectory ( Options . OutPutPath ) ;
111+ }
108112
109- Log ( $ "--- Done!") ;
110- Log ( $ "--- Path: { pathCombined } ") ;
111- Log ( $ "--- --- ---") ;
113+ string pathCombined = string . Empty ;
114+
115+ if ( filename != null )
116+ pathCombined = Path . Combine ( Options . OutPutPath , filename ) ;
117+ else
118+ pathCombined = Path . Combine ( Options . OutPutPath , file . Name . Replace ( ".cs" , ".js" ) ) ;
119+
120+ await File . WriteAllTextAsync ( pathCombined , _Walker . JSSB . ToString ( ) ) ;
121+
122+ Log ( $ "--- Done!") ;
123+ Log ( $ "--- Path: { pathCombined } ") ;
124+ Log ( $ "--- --- ---") ;
125+ }
112126 }
113127 /// <summary>
114128 /// Method for generating from string.
@@ -136,44 +150,6 @@ public async Task<StringBuilder> GenerateOneFromStringAsync(string csstring, Lis
136150
137151 return _Walker . JSSB ;
138152 }
139- /// <summary>
140- /// Method for generating multiply js files.
141- /// </summary>
142- /// <param name="path">Full path to the folder/directory.</param>
143- /// <returns></returns>
144- public async Task GenerateManyAsync ( string path )
145- {
146- Assembly assembly = Assembly . GetEntryAssembly ( ) ;
147-
148- DirectoryInfo folder = new ( path ) ;
149-
150- FileInfo [ ] Files = folder . GetFiles ( "*.cs" ) ;
151-
152- foreach ( FileInfo file in Files )
153- {
154- SyntaxTree ? _tree = null ;
155-
156- using ( var stream = File . OpenRead ( file . FullName ) )
157- {
158- _tree = CSharpSyntaxTree . ParseText ( SourceText . From ( stream ) , path : file . FullName ) ;
159- }
160-
161- await GenerateAsync ( _tree , assembly ) ;
162-
163- if ( ! Directory . Exists ( Options . OutPutPath ) )
164- {
165- Directory . CreateDirectory ( Options . OutPutPath ) ;
166- }
167-
168- string pathCombined = Path . Combine ( Options . OutPutPath , file . Name . Replace ( ".cs" , ".js" ) ) ;
169-
170- await File . WriteAllTextAsync ( pathCombined , _Walker . JSSB . ToString ( ) ) ;
171-
172- Log ( $ "--- Done!") ;
173- Log ( $ "--- Path: { pathCombined } ") ;
174- Log ( $ "--- --- ---") ;
175- }
176- }
177153
178154 private async Task GenerateAsync ( SyntaxTree ? tree , Assembly assembly , List < MetadataReference > ? refs = null )
179155 {
0 commit comments