11// This file contains the build logic for the public repo
2+ // @ts -check
23
34var fs = require ( "fs" ) ;
45var os = require ( "os" ) ;
56var path = require ( "path" ) ;
67var child_process = require ( "child_process" ) ;
78var fold = require ( "travis-fold" ) ;
8- var runTestsInParallel = require ( "./scripts/mocha-parallel" ) . runTestsInParallel ;
99var ts = require ( "./lib/typescript" ) ;
1010
1111
@@ -38,7 +38,7 @@ else if (process.env.PATH !== undefined) {
3838
3939function filesFromConfig ( configPath ) {
4040 var configText = fs . readFileSync ( configPath ) . toString ( ) ;
41- var config = ts . parseConfigFileTextToJson ( configPath , configText , /*stripComments*/ true ) ;
41+ var config = ts . parseConfigFileTextToJson ( configPath , configText ) ;
4242 if ( config . error ) {
4343 throw new Error ( diagnosticsToString ( [ config . error ] ) ) ;
4444 }
@@ -105,6 +105,9 @@ var harnessCoreSources = [
105105 "loggedIO.ts" ,
106106 "rwcRunner.ts" ,
107107 "test262Runner.ts" ,
108+ "./parallel/shared.ts" ,
109+ "./parallel/host.ts" ,
110+ "./parallel/worker.ts" ,
108111 "runner.ts"
109112] . map ( function ( f ) {
110113 return path . join ( harnessDirectory , f ) ;
@@ -596,7 +599,7 @@ file(typesMapOutputPath, function() {
596599 var content = fs . readFileSync ( path . join ( serverDirectory , 'typesMap.json' ) ) ;
597600 // Validate that it's valid JSON
598601 try {
599- JSON . parse ( content ) ;
602+ JSON . parse ( content . toString ( ) ) ;
600603 } catch ( e ) {
601604 console . log ( "Parse error in typesMap.json: " + e ) ;
602605 }
@@ -740,7 +743,7 @@ desc("Builds the test infrastructure using the built compiler");
740743task ( "tests" , [ "local" , run ] . concat ( libraryTargets ) ) ;
741744
742745function exec ( cmd , completeHandler , errorHandler ) {
743- var ex = jake . createExec ( [ cmd ] , { windowsVerbatimArguments : true } ) ;
746+ var ex = jake . createExec ( [ cmd ] , { windowsVerbatimArguments : true , interactive : true } ) ;
744747 // Add listeners for output and error
745748 ex . addListener ( "stdout" , function ( output ) {
746749 process . stdout . write ( output ) ;
@@ -766,15 +769,16 @@ function exec(cmd, completeHandler, errorHandler) {
766769 ex . run ( ) ;
767770}
768771
772+ const del = require ( "del" ) ;
769773function cleanTestDirs ( ) {
770774 // Clean the local baselines directory
771775 if ( fs . existsSync ( localBaseline ) ) {
772- jake . rmRf ( localBaseline ) ;
776+ del . sync ( localBaseline ) ;
773777 }
774778
775779 // Clean the local Rwc baselines directory
776780 if ( fs . existsSync ( localRwcBaseline ) ) {
777- jake . rmRf ( localRwcBaseline ) ;
781+ del . sync ( localRwcBaseline ) ;
778782 }
779783
780784 jake . mkdirP ( localRwcBaseline ) ;
@@ -783,13 +787,14 @@ function cleanTestDirs() {
783787}
784788
785789// used to pass data from jake command line directly to run.js
786- function writeTestConfigFile ( tests , light , taskConfigsFolder , workerCount , stackTraceLimit ) {
790+ function writeTestConfigFile ( tests , light , taskConfigsFolder , workerCount , stackTraceLimit , colors ) {
787791 var testConfigContents = JSON . stringify ( {
788792 test : tests ? [ tests ] : undefined ,
789793 light : light ,
790794 workerCount : workerCount ,
791795 taskConfigsFolder : taskConfigsFolder ,
792- stackTraceLimit : stackTraceLimit
796+ stackTraceLimit : stackTraceLimit ,
797+ noColor : ! colors
793798 } ) ;
794799 fs . writeFileSync ( 'test.config' , testConfigContents ) ;
795800}
@@ -831,7 +836,7 @@ function runConsoleTests(defaultReporter, runInParallel) {
831836 }
832837
833838 if ( tests || light || taskConfigsFolder ) {
834- writeTestConfigFile ( tests , light , taskConfigsFolder , workerCount , stackTraceLimit ) ;
839+ writeTestConfigFile ( tests , light , taskConfigsFolder , workerCount , stackTraceLimit , colors ) ;
835840 }
836841
837842 if ( tests && tests . toLocaleLowerCase ( ) === "rwc" ) {
@@ -894,19 +899,15 @@ function runConsoleTests(defaultReporter, runInParallel) {
894899 var savedNodeEnv = process . env . NODE_ENV ;
895900 process . env . NODE_ENV = "development" ;
896901 var startTime = mark ( ) ;
897- runTestsInParallel ( taskConfigsFolder , run , { testTimeout : testTimeout , noColors : ! colors } , function ( err ) {
902+ exec ( host + " " + run , function ( ) {
898903 process . env . NODE_ENV = savedNodeEnv ;
899904 measure ( startTime ) ;
900- // last worker clean everything and runs linter in case if there were no errors
901- deleteTemporaryProjectOutput ( ) ;
902- jake . rmRf ( taskConfigsFolder ) ;
903- if ( err ) {
904- fail ( err ) ;
905- }
906- else {
907- runLinter ( ) ;
908- complete ( ) ;
909- }
905+ runLinter ( ) ;
906+ finish ( ) ;
907+ } , function ( e , status ) {
908+ process . env . NODE_ENV = savedNodeEnv ;
909+ measure ( startTime ) ;
910+ finish ( status ) ;
910911 } ) ;
911912 }
912913
@@ -969,8 +970,8 @@ desc("Runs the tests using the built run.js file like 'jake runtests'. Syntax is
969970task ( "runtests-browser" , [ "browserify" , nodeServerOutFile ] , function ( ) {
970971 cleanTestDirs ( ) ;
971972 host = "node" ;
972- browser = process . env . browser || process . env . b || ( os . platform ( ) === "linux" ? "chrome" : "IE" ) ;
973- tests = process . env . test || process . env . tests || process . env . t ;
973+ var browser = process . env . browser || process . env . b || ( os . platform ( ) === "linux" ? "chrome" : "IE" ) ;
974+ var tests = process . env . test || process . env . tests || process . env . t ;
974975 var light = process . env . light || false ;
975976 var testConfigFile = 'test.config' ;
976977 if ( fs . existsSync ( testConfigFile ) ) {
@@ -1042,6 +1043,7 @@ function acceptBaseline(sourceFolder, targetFolder) {
10421043 if ( fs . existsSync ( target ) ) {
10431044 fs . unlinkSync ( target ) ;
10441045 }
1046+ jake . mkdirP ( path . dirname ( target ) ) ;
10451047 fs . renameSync ( path . join ( sourceFolder , filename ) , target ) ;
10461048 }
10471049 }
@@ -1119,7 +1121,7 @@ task("update-sublime", ["local", serverFile], function () {
11191121 jake . cpR ( serverFile + ".map" , "../TypeScript-Sublime-Plugin/tsserver/" ) ;
11201122} ) ;
11211123
1122- var tslintRuleDir = "scripts/tslint" ;
1124+ var tslintRuleDir = "scripts/tslint/rules " ;
11231125var tslintRules = [
11241126 "booleanTriviaRule" ,
11251127 "debugAssertRule" ,
@@ -1135,13 +1137,27 @@ var tslintRulesFiles = tslintRules.map(function (p) {
11351137 return path . join ( tslintRuleDir , p + ".ts" ) ;
11361138} ) ;
11371139var tslintRulesOutFiles = tslintRules . map ( function ( p ) {
1138- return path . join ( builtLocalDirectory , "tslint" , p + ".js" ) ;
1140+ return path . join ( builtLocalDirectory , "tslint/rules" , p + ".js" ) ;
1141+ } ) ;
1142+ var tslintFormattersDir = "scripts/tslint/formatters" ;
1143+ var tslintFormatters = [
1144+ "autolinkableStylishFormatter" ,
1145+ ] ;
1146+ var tslintFormatterFiles = tslintFormatters . map ( function ( p ) {
1147+ return path . join ( tslintFormattersDir , p + ".ts" ) ;
1148+ } ) ;
1149+ var tslintFormattersOutFiles = tslintFormatters . map ( function ( p ) {
1150+ return path . join ( builtLocalDirectory , "tslint/formatters" , p + ".js" ) ;
11391151} ) ;
11401152desc ( "Compiles tslint rules to js" ) ;
1141- task ( "build-rules" , [ "build-rules-start" ] . concat ( tslintRulesOutFiles ) . concat ( [ "build-rules-end" ] ) ) ;
1153+ task ( "build-rules" , [ "build-rules-start" ] . concat ( tslintRulesOutFiles ) . concat ( tslintFormattersOutFiles ) . concat ( [ "build-rules-end" ] ) ) ;
11421154tslintRulesFiles . forEach ( function ( ruleFile , i ) {
11431155 compileFile ( tslintRulesOutFiles [ i ] , [ ruleFile ] , [ ruleFile ] , [ ] , /*useBuiltCompiler*/ false ,
1144- { noOutFile : true , generateDeclarations : false , outDir : path . join ( builtLocalDirectory , "tslint" ) , lib : "es6" } ) ;
1156+ { noOutFile : true , generateDeclarations : false , outDir : path . join ( builtLocalDirectory , "tslint/rules" ) , lib : "es6" } ) ;
1157+ } ) ;
1158+ tslintFormatterFiles . forEach ( function ( ruleFile , i ) {
1159+ compileFile ( tslintFormattersOutFiles [ i ] , [ ruleFile ] , [ ruleFile ] , [ ] , /*useBuiltCompiler*/ false ,
1160+ { noOutFile : true , generateDeclarations : false , outDir : path . join ( builtLocalDirectory , "tslint/formatters" ) , lib : "es6" } ) ;
11451161} ) ;
11461162
11471163desc ( "Emit the start of the build-rules fold" ) ;
@@ -1209,8 +1225,8 @@ task("lint", ["build-rules"], () => {
12091225 const fileMatcher = process . env . f || process . env . file || process . env . files ;
12101226 const files = fileMatcher
12111227 ? `src/**/${ fileMatcher } `
1212- : "Gulpfile.ts 'scripts/tslint/*.ts' 'src/**/*.ts' --exclude src/lib/es5.d.ts --exclude 'src/lib/*.generated.d.ts'" ;
1213- const cmd = `node node_modules/tslint/bin/tslint ${ files } --format stylish ` ;
1228+ : "Gulpfile.ts 'scripts/tslint/**/* .ts' 'src/**/*.ts' --exclude src/lib/es5.d.ts --exclude 'src/lib/*.generated.d.ts'" ;
1229+ const cmd = `node node_modules/tslint/bin/tslint ${ files } --formatters-dir ./built/local/tslint/formatters -- format autolinkableStylish ` ;
12141230 console . log ( "Linting: " + cmd ) ;
12151231 jake . exec ( [ cmd ] , { interactive : true } , ( ) => {
12161232 if ( fold . isTravis ( ) ) console . log ( fold . end ( "lint" ) ) ;
0 commit comments