@@ -172,6 +172,128 @@ namespace ts {
172
172
}
173
173
}
174
174
175
+ const buildOpts : CommandLineOption [ ] = [
176
+ {
177
+ name : "verbose" ,
178
+ shortName : "v" ,
179
+ category : Diagnostics . Command_line_Options ,
180
+ description : Diagnostics . Enable_verbose_logging ,
181
+ type : "boolean"
182
+ } ,
183
+ {
184
+ name : "dry" ,
185
+ shortName : "d" ,
186
+ category : Diagnostics . Command_line_Options ,
187
+ description : Diagnostics . Show_what_would_be_built_or_deleted_if_specified_with_clean ,
188
+ type : "boolean"
189
+ } ,
190
+ {
191
+ name : "force" ,
192
+ shortName : "f" ,
193
+ category : Diagnostics . Command_line_Options ,
194
+ description : Diagnostics . Build_all_projects_including_those_that_appear_to_be_up_to_date ,
195
+ type : "boolean"
196
+ } ,
197
+ {
198
+ name : "clean" ,
199
+ category : Diagnostics . Command_line_Options ,
200
+ description : Diagnostics . Delete_the_outputs_of_all_projects ,
201
+ type : "boolean"
202
+ } ,
203
+ {
204
+ name : "watch" ,
205
+ category : Diagnostics . Command_line_Options ,
206
+ description : Diagnostics . Watch_input_files ,
207
+ type : "boolean"
208
+ }
209
+ ] ;
210
+
211
+ function performBuild ( args : string [ ] , compilerHost : CompilerHost , buildHost : BuildHost , system ?: System ) : number | undefined {
212
+ let verbose = false ;
213
+ let dry = false ;
214
+ let force = false ;
215
+ let clean = false ;
216
+ let watch = false ;
217
+
218
+ const projects : string [ ] = [ ] ;
219
+ for ( const arg of args ) {
220
+ switch ( arg . toLowerCase ( ) ) {
221
+ case "-v" :
222
+ case "--verbose" :
223
+ verbose = true ;
224
+ continue ;
225
+ case "-d" :
226
+ case "--dry" :
227
+ dry = true ;
228
+ continue ;
229
+ case "-f" :
230
+ case "--force" :
231
+ force = true ;
232
+ continue ;
233
+ case "--clean" :
234
+ clean = true ;
235
+ continue ;
236
+ case "--watch" :
237
+ case "-w" :
238
+ watch = true ;
239
+ continue ;
240
+
241
+ case "--?" :
242
+ case "-?" :
243
+ case "--help" :
244
+ printHelp ( buildOpts , "--build " ) ;
245
+ return ExitStatus . Success ;
246
+ }
247
+ // Not a flag, parse as filename
248
+ addProject ( arg ) ;
249
+ }
250
+
251
+ // Nonsensical combinations
252
+ if ( clean && force ) {
253
+ buildHost . error ( Diagnostics . Options_0_and_1_cannot_be_combined , "clean" , "force" ) ;
254
+ return ExitStatus . DiagnosticsPresent_OutputsSkipped ;
255
+ }
256
+ if ( clean && verbose ) {
257
+ buildHost . error ( Diagnostics . Options_0_and_1_cannot_be_combined , "clean" , "verbose" ) ;
258
+ return ExitStatus . DiagnosticsPresent_OutputsSkipped ;
259
+ }
260
+ if ( clean && watch ) {
261
+ buildHost . error ( Diagnostics . Options_0_and_1_cannot_be_combined , "clean" , "watch" ) ;
262
+ return ExitStatus . DiagnosticsPresent_OutputsSkipped ;
263
+ }
264
+ if ( watch && dry ) {
265
+ buildHost . error ( Diagnostics . Options_0_and_1_cannot_be_combined , "watch" , "dry" ) ;
266
+ return ExitStatus . DiagnosticsPresent_OutputsSkipped ;
267
+ }
268
+
269
+ if ( projects . length === 0 ) {
270
+ // tsc -b invoked with no extra arguments; act as if invoked with "tsc -b ."
271
+ addProject ( "." ) ;
272
+ }
273
+
274
+ const builder = createSolutionBuilder ( compilerHost , buildHost , projects , { dry, force, verbose } , system ) ;
275
+ if ( clean ) {
276
+ return builder . cleanAllProjects ( ) ;
277
+ }
278
+
279
+ if ( watch ) {
280
+ builder . buildAllProjects ( ) ;
281
+ builder . startWatching ( ) ;
282
+ return undefined ;
283
+ }
284
+
285
+ return builder . buildAllProjects ( ) ;
286
+
287
+ function addProject ( projectSpecification : string ) {
288
+ const fileName = resolvePath ( compilerHost . getCurrentDirectory ( ) , projectSpecification ) ;
289
+ const refPath = resolveProjectReferencePath ( compilerHost , { path : fileName } ) ;
290
+ if ( ! compilerHost . fileExists ( refPath ) ) {
291
+ return buildHost . error ( Diagnostics . File_0_does_not_exist , fileName ) ;
292
+ }
293
+ projects . push ( refPath ) ;
294
+ }
295
+ }
296
+
175
297
function performCompilation ( rootNames : string [ ] , projectReferences : ReadonlyArray < ProjectReference > | undefined , options : CompilerOptions , configFileParsingDiagnostics ?: ReadonlyArray < Diagnostic > ) {
176
298
const host = createCompilerHost ( options ) ;
177
299
enableStatistics ( options ) ;
0 commit comments