@@ -33,13 +33,18 @@ module ts {
33
33
type : "boolean" ,
34
34
description : Diagnostics . Print_this_message ,
35
35
} ,
36
+ {
37
+ name : "listFiles" ,
38
+ type : "boolean" ,
39
+ } ,
36
40
{
37
41
name : "locale" ,
38
42
type : "string" ,
39
43
} ,
40
44
{
41
45
name : "mapRoot" ,
42
46
type : "string" ,
47
+ isFilePath : true ,
43
48
description : Diagnostics . Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations ,
44
49
paramType : Diagnostics . LOCATION ,
45
50
} ,
@@ -90,6 +95,7 @@ module ts {
90
95
{
91
96
name : "outDir" ,
92
97
type : "string" ,
98
+ isFilePath : true ,
93
99
description : Diagnostics . Redirect_output_structure_to_the_directory ,
94
100
paramType : Diagnostics . DIRECTORY ,
95
101
} ,
@@ -98,6 +104,14 @@ module ts {
98
104
type : "boolean" ,
99
105
description : Diagnostics . Do_not_erase_const_enum_declarations_in_generated_code
100
106
} ,
107
+ {
108
+ name : "project" ,
109
+ shortName : "p" ,
110
+ type : "string" ,
111
+ isFilePath : true ,
112
+ description : Diagnostics . Compile_the_project_in_the_given_directory ,
113
+ paramType : Diagnostics . DIRECTORY
114
+ } ,
101
115
{
102
116
name : "removeComments" ,
103
117
type : "boolean" ,
@@ -111,6 +125,7 @@ module ts {
111
125
{
112
126
name : "sourceRoot" ,
113
127
type : "string" ,
128
+ isFilePath : true ,
114
129
description : Diagnostics . Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations ,
115
130
paramType : Diagnostics . LOCATION ,
116
131
} ,
@@ -141,17 +156,6 @@ module ts {
141
156
}
142
157
] ;
143
158
144
- var shortOptionNames : Map < string > = { } ;
145
- var optionNameMap : Map < CommandLineOption > = { } ;
146
-
147
- forEach ( optionDeclarations , option => {
148
- optionNameMap [ option . name . toLowerCase ( ) ] = option ;
149
-
150
- if ( option . shortName ) {
151
- shortOptionNames [ option . shortName ] = option . name ;
152
- }
153
- } ) ;
154
-
155
159
export function parseCommandLine ( commandLine : string [ ] ) : ParsedCommandLine {
156
160
// Set default compiler option values
157
161
var options : CompilerOptions = {
@@ -160,7 +164,15 @@ module ts {
160
164
} ;
161
165
var filenames : string [ ] = [ ] ;
162
166
var errors : Diagnostic [ ] = [ ] ;
167
+ var shortOptionNames : Map < string > = { } ;
168
+ var optionNameMap : Map < CommandLineOption > = { } ;
163
169
170
+ forEach ( optionDeclarations , option => {
171
+ optionNameMap [ option . name . toLowerCase ( ) ] = option ;
172
+ if ( option . shortName ) {
173
+ shortOptionNames [ option . shortName ] = option . name ;
174
+ }
175
+ } ) ;
164
176
parseStrings ( commandLine ) ;
165
177
return {
166
178
options,
@@ -256,4 +268,78 @@ module ts {
256
268
parseStrings ( args ) ;
257
269
}
258
270
}
271
+
272
+ export function readConfigFile ( filename : string ) : any {
273
+ try {
274
+ var text = sys . readFile ( filename ) ;
275
+ return / \S / . test ( text ) ? JSON . parse ( text ) : { } ;
276
+ }
277
+ catch ( e ) {
278
+ }
279
+ }
280
+
281
+ export function parseConfigFile ( json : any , basePath ?: string ) : ParsedCommandLine {
282
+ var errors : Diagnostic [ ] = [ ] ;
283
+
284
+ return {
285
+ options : getCompilerOptions ( ) ,
286
+ filenames : getFiles ( ) ,
287
+ errors
288
+ } ;
289
+
290
+ function getCompilerOptions ( ) : CompilerOptions {
291
+ var options : CompilerOptions = { } ;
292
+ var optionNameMap : Map < CommandLineOption > = { } ;
293
+ forEach ( optionDeclarations , option => {
294
+ optionNameMap [ option . name ] = option ;
295
+ } ) ;
296
+ var jsonOptions = json [ "compilerOptions" ] ;
297
+ if ( jsonOptions ) {
298
+ for ( var id in jsonOptions ) {
299
+ if ( hasProperty ( optionNameMap , id ) ) {
300
+ var opt = optionNameMap [ id ] ;
301
+ var optType = opt . type ;
302
+ var value = jsonOptions [ id ] ;
303
+ var expectedType = typeof optType === "string" ? optType : "string" ;
304
+ if ( typeof value === expectedType ) {
305
+ if ( typeof optType !== "string" ) {
306
+ var key = value . toLowerCase ( ) ;
307
+ if ( hasProperty ( optType , key ) ) {
308
+ value = optType [ key ] ;
309
+ }
310
+ else {
311
+ errors . push ( createCompilerDiagnostic ( opt . error ) ) ;
312
+ value = 0 ;
313
+ }
314
+ }
315
+ if ( opt . isFilePath ) {
316
+ value = normalizePath ( combinePaths ( basePath , value ) ) ;
317
+ }
318
+ options [ opt . name ] = value ;
319
+ }
320
+ else {
321
+ errors . push ( createCompilerDiagnostic ( Diagnostics . Compiler_option_0_requires_a_value_of_type_1 , id , expectedType ) ) ;
322
+ }
323
+ }
324
+ else {
325
+ errors . push ( createCompilerDiagnostic ( Diagnostics . Unknown_compiler_option_0 , id ) ) ;
326
+ }
327
+ }
328
+ }
329
+ return options ;
330
+ }
331
+
332
+ function getFiles ( ) : string [ ] {
333
+ var references : string [ ] = json [ "references" ] instanceof Array ? json [ "references" ] : [ ]
334
+ var files = map ( references , s => combinePaths ( basePath , s ) ) ;
335
+ var sysFiles = sys . readDirectory ( basePath , ".ts" ) ;
336
+ for ( var i = 0 ; i < sysFiles . length ; i ++ ) {
337
+ var name = sysFiles [ i ] ;
338
+ if ( ! fileExtensionIs ( name , ".d.ts" ) || ! contains ( sysFiles , name . substr ( 0 , name . length - 5 ) + ".ts" ) ) {
339
+ files . push ( name ) ;
340
+ }
341
+ }
342
+ return files ;
343
+ }
344
+ }
259
345
}
0 commit comments