@@ -62,7 +62,7 @@ namespace ts {
62
62
message : report ,
63
63
errorDiagnostic : d => reportDiag ( d )
64
64
} ;
65
- const result = performBuild ( args . slice ( 1 ) , createCompilerHost ( { } ) , buildHost , sys ) ;
65
+ const result = performBuild ( args . slice ( 1 ) , createCompilerHost ( { } ) , buildHost ) ;
66
66
// undefined = in watch mode, do not exit
67
67
if ( result !== undefined ) {
68
68
return sys . exit ( result ) ;
@@ -172,96 +172,94 @@ 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 ;
175
+ function performBuild ( args : string [ ] , compilerHost : CompilerHost , buildHost : BuildHost ) : number | undefined {
176
+ const buildOpts : CommandLineOption [ ] = [
177
+ {
178
+ name : "help" ,
179
+ shortName : "h" ,
180
+ type : "boolean" ,
181
+ showInSimplifiedHelpView : true ,
182
+ category : Diagnostics . Command_line_Options ,
183
+ description : Diagnostics . Print_this_message ,
184
+ } ,
185
+ {
186
+ name : "help" ,
187
+ shortName : "?" ,
188
+ type : "boolean"
189
+ } ,
190
+ {
191
+ name : "verbose" ,
192
+ shortName : "v" ,
193
+ category : Diagnostics . Command_line_Options ,
194
+ description : Diagnostics . Enable_verbose_logging ,
195
+ type : "boolean"
196
+ } ,
197
+ {
198
+ name : "dry" ,
199
+ shortName : "d" ,
200
+ category : Diagnostics . Command_line_Options ,
201
+ description : Diagnostics . Show_what_would_be_built_or_deleted_if_specified_with_clean ,
202
+ type : "boolean"
203
+ } ,
204
+ {
205
+ name : "force" ,
206
+ shortName : "f" ,
207
+ category : Diagnostics . Command_line_Options ,
208
+ description : Diagnostics . Build_all_projects_including_those_that_appear_to_be_up_to_date ,
209
+ type : "boolean"
210
+ } ,
211
+ {
212
+ name : "clean" ,
213
+ category : Diagnostics . Command_line_Options ,
214
+ description : Diagnostics . Delete_the_outputs_of_all_projects ,
215
+ type : "boolean"
216
+ } ,
217
+ {
218
+ name : "watch" ,
219
+ category : Diagnostics . Command_line_Options ,
220
+ description : Diagnostics . Watch_input_files ,
221
+ type : "boolean"
222
+ }
223
+ ] ;
224
+ let buildOptionNameMap : OptionNameMap | undefined ;
225
+ const returnBuildOptionNameMap = ( ) => ( buildOptionNameMap || ( buildOptionNameMap = createOptionNameMap ( buildOpts ) ) ) ;
217
226
227
+ const buildOptions : BuildOptions = { } ;
218
228
const projects : string [ ] = [ ] ;
219
229
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 ;
230
+ if ( arg . charCodeAt ( 0 ) === CharacterCodes . minus ) {
231
+ const opt = getOptionDeclarationFromName ( returnBuildOptionNameMap , arg . slice ( arg . charCodeAt ( 1 ) === CharacterCodes . minus ? 2 : 1 ) , /*allowShort*/ true ) ;
232
+ if ( opt ) {
233
+ buildOptions [ opt . name as keyof BuildOptions ] = true ;
234
+ }
235
+ else {
236
+ reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . Unknown_build_option_0 , arg ) ) ;
237
+ }
246
238
}
247
- // Not a flag, parse as filename
248
- addProject ( arg ) ;
239
+ else {
240
+ // Not a flag, parse as filename
241
+ addProject ( arg ) ;
242
+ }
243
+ }
244
+
245
+ if ( buildOptions . help ) {
246
+ printHelp ( buildOpts , "--build " ) ; return ExitStatus . Success ;
249
247
}
250
248
251
249
// Nonsensical combinations
252
- if ( clean && force ) {
250
+ if ( buildOptions . clean && buildOptions . force ) {
253
251
buildHost . error ( Diagnostics . Options_0_and_1_cannot_be_combined , "clean" , "force" ) ;
254
252
return ExitStatus . DiagnosticsPresent_OutputsSkipped ;
255
253
}
256
- if ( clean && verbose ) {
254
+ if ( buildOptions . clean && buildOptions . verbose ) {
257
255
buildHost . error ( Diagnostics . Options_0_and_1_cannot_be_combined , "clean" , "verbose" ) ;
258
256
return ExitStatus . DiagnosticsPresent_OutputsSkipped ;
259
257
}
260
- if ( clean && watch ) {
258
+ if ( buildOptions . clean && buildOptions . watch ) {
261
259
buildHost . error ( Diagnostics . Options_0_and_1_cannot_be_combined , "clean" , "watch" ) ;
262
260
return ExitStatus . DiagnosticsPresent_OutputsSkipped ;
263
261
}
264
- if ( watch && dry ) {
262
+ if ( buildOptions . watch && buildOptions . dry ) {
265
263
buildHost . error ( Diagnostics . Options_0_and_1_cannot_be_combined , "watch" , "dry" ) ;
266
264
return ExitStatus . DiagnosticsPresent_OutputsSkipped ;
267
265
}
@@ -271,12 +269,12 @@ namespace ts {
271
269
addProject ( "." ) ;
272
270
}
273
271
274
- const builder = createSolutionBuilder ( compilerHost , buildHost , projects , { dry , force , verbose } , system ) ;
275
- if ( clean ) {
272
+ const builder = createSolutionBuilder ( compilerHost , buildHost , projects , buildOptions ) ;
273
+ if ( buildOptions . clean ) {
276
274
return builder . cleanAllProjects ( ) ;
277
275
}
278
276
279
- if ( watch ) {
277
+ if ( buildOptions . watch ) {
280
278
builder . buildAllProjects ( ) ;
281
279
builder . startWatching ( ) ;
282
280
return undefined ;
0 commit comments