@@ -2,22 +2,37 @@ import * as fs from "fs";
22import * as path from "path" ;
33import * as child_process from "child_process" ;
44
5+
56interface Map < T > {
67 [ key : string ] : T ;
78}
89
9- declare const __dirname : string ;
10- declare const process : {
10+ declare var process : {
1111 argv : string [ ] ;
12- env : Map < string >
12+ env : Map < string > ;
13+ exit ( exitCode ?: number ) : void ;
1314}
1415
15- const tscRoot = path . join ( __dirname , "..\\" ) ;
16- const tscPath = path . join ( tscRoot , "built" , "instrumented" , "tsc.js" ) ;
17- const rwcTestPath = path . join ( tscRoot , "tests" , "cases" , "rwc" , "dt" ) ;
18- const definitelyTypedRoot = process . argv [ 2 ] ;
16+ main ( ) ;
17+ function main ( ) {
18+ const [ , progName , tscRoot , definitelyTypedRoot ] = process . argv ;
19+ if ( process . argv . length !== 4 ) {
20+ if ( process . argv . length < 2 ) {
21+ throw "Expected at least 2 argv elements."
22+ }
23+ console . log ( "Usage:" )
24+ console . log ( ` node ${ path . relative ( __dirname , progName ) } [TypeScript Repo Root] [DefinitelyTyped Repo Root]` ) ;
25+ return ;
26+ }
1927
20- importDefinitelyTypedTests ( definitelyTypedRoot ) ;
28+ const tscPath = path . resolve ( tscRoot , "built" , "local" , "tsc.js" ) ;
29+ const rwcTestPath = path . resolve ( tscRoot , "tests" , "cases" , "rwc" , "dt" ) ;
30+ const resolvedDefinitelyTypedRoot = path . resolve ( definitelyTypedRoot ) ;
31+
32+ console . log ( `Resolved TypeScript Repo Root: '${ tscRoot } '.` ) ;
33+ console . log ( `Resolved DefinitelyTyped Repo Root: '${ definitelyTypedRoot } '.` ) ;
34+ importDefinitelyTypedTests ( tscPath , rwcTestPath , resolvedDefinitelyTypedRoot ) ;
35+ }
2136
2237function filePathEndsWith ( path : string , endingString : string ) : boolean {
2338 const pathLen = path . length ;
@@ -27,10 +42,10 @@ function filePathEndsWith(path: string, endingString: string): boolean {
2742
2843function copyFileSync ( source : string , destination : string ) {
2944 let text = fs . readFileSync ( source ) ;
30- fs . writeFileSync ( destination , text ) ;
45+ fs . writeFileSync ( destination , text , { } ) ;
3146}
3247
33- function importDefinitelyTypedTest ( testCaseName : string , testFiles : string [ ] , responseFile : string ) {
48+ function importDefinitelyTypedTest ( tscPath : string , rwcTestPath : string , testCaseName : string , testFiles : string [ ] , responseFile : string ) {
3449 let cmd = "node " + tscPath + " --module commonjs " + testFiles . join ( " " ) ;
3550 if ( responseFile ) {
3651 cmd += " @" + responseFile ;
@@ -85,7 +100,7 @@ function importDefinitelyTypedTest(testCaseName: string, testFiles: string[], re
85100 } ) ;
86101}
87102
88- function importDefinitelyTypedTests ( definitelyTypedRoot : string ) : void {
103+ function importDefinitelyTypedTests ( tscPath : string , rwcTestPath : string , definitelyTypedRoot : string ) : void {
89104 fs . readdir ( definitelyTypedRoot , ( err , subDirectories ) => {
90105 if ( err ) {
91106 throw err ;
@@ -124,16 +139,16 @@ function importDefinitelyTypedTests(definitelyTypedRoot: string): void {
124139 let regexp = new RegExp ( d + "(([-][0-9])|([\.]d[\.]ts))" ) ;
125140 if ( tsFiles . length > 1 && tsFiles . every ( t => filePathEndsWith ( t , ".d.ts" ) && regexp . test ( t ) ) ) {
126141 for ( const fileName of tsFiles ) {
127- importDefinitelyTypedTest ( path . basename ( fileName , ".d.ts" ) , [ fileName ] , paramFile ) ;
142+ importDefinitelyTypedTest ( tscPath , rwcTestPath , path . basename ( fileName , ".d.ts" ) , [ fileName ] , paramFile ) ;
128143 }
129144 }
130145 else {
131- importDefinitelyTypedTest ( d , tsFiles , paramFile ) ;
146+ importDefinitelyTypedTest ( tscPath , rwcTestPath , d , tsFiles , paramFile ) ;
132147 }
133148 }
134149 else {
135150 for ( const fileName of tsFiles ) {
136- importDefinitelyTypedTest ( path . basename ( fileName , "-tests.ts" ) , [ fileName ] , paramFile ) ;
151+ importDefinitelyTypedTest ( tscPath , rwcTestPath , path . basename ( fileName , "-tests.ts" ) , [ fileName ] , paramFile ) ;
137152 }
138153 }
139154 } ) ;
0 commit comments