@@ -33,13 +33,18 @@ module ts {
3333 type : "boolean" ,
3434 description : Diagnostics . Print_this_message ,
3535 } ,
36+ {
37+ name : "listFiles" ,
38+ type : "boolean" ,
39+ } ,
3640 {
3741 name : "locale" ,
3842 type : "string" ,
3943 } ,
4044 {
4145 name : "mapRoot" ,
4246 type : "string" ,
47+ isFilePath : true ,
4348 description : Diagnostics . Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations ,
4449 paramType : Diagnostics . LOCATION ,
4550 } ,
@@ -90,6 +95,7 @@ module ts {
9095 {
9196 name : "outDir" ,
9297 type : "string" ,
98+ isFilePath : true ,
9399 description : Diagnostics . Redirect_output_structure_to_the_directory ,
94100 paramType : Diagnostics . DIRECTORY ,
95101 } ,
@@ -98,6 +104,14 @@ module ts {
98104 type : "boolean" ,
99105 description : Diagnostics . Do_not_erase_const_enum_declarations_in_generated_code
100106 } ,
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+ } ,
101115 {
102116 name : "removeComments" ,
103117 type : "boolean" ,
@@ -111,6 +125,7 @@ module ts {
111125 {
112126 name : "sourceRoot" ,
113127 type : "string" ,
128+ isFilePath : true ,
114129 description : Diagnostics . Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations ,
115130 paramType : Diagnostics . LOCATION ,
116131 } ,
@@ -141,17 +156,6 @@ module ts {
141156 }
142157 ] ;
143158
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-
155159 export function parseCommandLine ( commandLine : string [ ] ) : ParsedCommandLine {
156160 // Set default compiler option values
157161 var options : CompilerOptions = {
@@ -160,7 +164,15 @@ module ts {
160164 } ;
161165 var filenames : string [ ] = [ ] ;
162166 var errors : Diagnostic [ ] = [ ] ;
167+ var shortOptionNames : Map < string > = { } ;
168+ var optionNameMap : Map < CommandLineOption > = { } ;
163169
170+ forEach ( optionDeclarations , option => {
171+ optionNameMap [ option . name . toLowerCase ( ) ] = option ;
172+ if ( option . shortName ) {
173+ shortOptionNames [ option . shortName ] = option . name ;
174+ }
175+ } ) ;
164176 parseStrings ( commandLine ) ;
165177 return {
166178 options,
@@ -256,4 +268,78 @@ module ts {
256268 parseStrings ( args ) ;
257269 }
258270 }
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+ }
259345}
0 commit comments