@@ -71,44 +71,58 @@ public CSTOJS(CSTOJSOptions options)
71
71
}
72
72
73
73
/// <summary>
74
- /// Method for generating js file.
74
+ /// Method for generating js file/files .
75
75
/// </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>
78
78
/// <returns></returns>
79
79
public async Task GenerateOneAsync ( string path , string ? filename = null )
80
80
{
81
81
Assembly assembly = Assembly . GetEntryAssembly ( ) ;
82
+ List < FileInfo > files = new ( ) ;
82
83
83
- FileInfo file = new ( path ) ;
84
-
85
- SyntaxTree ? _tree = null ;
86
-
87
- using ( var stream = File . OpenRead ( path ) )
84
+ if ( File . Exists ( path ) )
88
85
{
89
- _tree = CSharpSyntaxTree . ParseText ( SourceText . From ( stream ) , path : path ) ;
86
+ files . Add ( new FileInfo ( path ) ) ;
90
87
}
88
+ else
89
+ {
90
+ DirectoryInfo folder = new ( path ) ;
91
91
92
- await GenerateAsync ( _tree , assembly ) ;
92
+ files = folder . GetFiles ( "*.cs" ) . ToList ( ) ;
93
93
94
- if ( ! Directory . Exists ( Options . OutPutPath ) )
95
- {
96
- Directory . CreateDirectory ( Options . OutPutPath ) ;
94
+ filename = null ;
97
95
}
98
96
99
- string pathCombined = string . Empty ;
97
+ foreach ( FileInfo file in files )
98
+ {
99
+ SyntaxTree ? _tree = null ;
100
100
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
+ }
105
105
106
+ await GenerateAsync ( _tree , assembly ) ;
106
107
107
- await File . WriteAllTextAsync ( pathCombined , _Walker . JSSB . ToString ( ) ) ;
108
+ if ( ! Directory . Exists ( Options . OutPutPath ) )
109
+ {
110
+ Directory . CreateDirectory ( Options . OutPutPath ) ;
111
+ }
108
112
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
+ }
112
126
}
113
127
/// <summary>
114
128
/// Method for generating from string.
@@ -136,44 +150,6 @@ public async Task<StringBuilder> GenerateOneFromStringAsync(string csstring, Lis
136
150
137
151
return _Walker . JSSB ;
138
152
}
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
- }
177
153
178
154
private async Task GenerateAsync ( SyntaxTree ? tree , Assembly assembly , List < MetadataReference > ? refs = null )
179
155
{
0 commit comments