2014-07-13 03:04:16 +04:00
// This file contains the build logic for the public repo
var fs = require ( "fs" ) ;
2014-12-02 02:32:52 +03:00
var os = require ( "os" ) ;
2014-07-13 03:04:16 +04:00
var path = require ( "path" ) ;
2015-03-04 09:12:06 +03:00
var child_process = require ( "child_process" ) ;
2014-07-13 03:04:16 +04:00
// Variables
var compilerDirectory = "src/compiler/" ;
var servicesDirectory = "src/services/" ;
2015-02-12 06:43:10 +03:00
var serverDirectory = "src/server/" ;
2014-07-13 03:04:16 +04:00
var harnessDirectory = "src/harness/" ;
var libraryDirectory = "src/lib/" ;
2014-07-24 15:53:42 +04:00
var scriptsDirectory = "scripts/" ;
2014-10-17 05:13:26 +04:00
var unittestsDirectory = "tests/cases/unittests/" ;
2014-09-27 01:36:18 +04:00
var docDirectory = "doc/" ;
2014-07-13 03:04:16 +04:00
var builtDirectory = "built/" ;
var builtLocalDirectory = "built/local/" ;
var LKGDirectory = "bin/" ;
var copyright = "CopyrightNotice.txt" ;
var thirdParty = "ThirdPartyNoticeText.txt" ;
2014-07-22 09:08:27 +04:00
// add node_modules to path so we don't need global modules, prefer the modules by adding them first
2014-07-24 06:30:13 +04:00
var nodeModulesPathPrefix = path . resolve ( "./node_modules/.bin/" ) + path . delimiter ;
if ( process . env . path !== undefined ) {
process . env . path = nodeModulesPathPrefix + process . env . path ;
2015-03-04 09:12:06 +03:00
} else if ( process . env . PATH !== undefined ) {
2014-07-24 06:30:13 +04:00
process . env . PATH = nodeModulesPathPrefix + process . env . PATH ;
}
2014-07-22 09:08:27 +04:00
2014-07-13 03:04:16 +04:00
var compilerSources = [
"core.ts" ,
"sys.ts" ,
"types.ts" ,
"scanner.ts" ,
"parser.ts" ,
2014-12-11 03:42:41 +03:00
"utilities.ts" ,
2014-07-13 03:04:16 +04:00
"binder.ts" ,
"checker.ts" ,
2015-03-19 02:37:52 +03:00
"declarationEmitter.ts" ,
2014-07-13 03:04:16 +04:00
"emitter.ts" ,
2014-12-17 00:28:38 +03:00
"program.ts" ,
2014-07-13 03:04:16 +04:00
"commandLineParser.ts" ,
2014-08-07 10:21:53 +04:00
"tsc.ts" ,
2014-07-13 03:04:16 +04:00
"diagnosticInformationMap.generated.ts"
] . map ( function ( f ) {
return path . join ( compilerDirectory , f ) ;
} ) ;
var servicesSources = [
"core.ts" ,
2014-12-11 03:42:41 +03:00
"sys.ts" ,
2014-07-13 03:04:16 +04:00
"types.ts" ,
"scanner.ts" ,
"parser.ts" ,
2014-12-11 03:42:41 +03:00
"utilities.ts" ,
2014-07-13 03:04:16 +04:00
"binder.ts" ,
"checker.ts" ,
2015-03-19 02:37:52 +03:00
"declarationEmitter.ts" ,
2014-12-11 03:42:41 +03:00
"emitter.ts" ,
2014-12-17 00:28:38 +03:00
"program.ts" ,
2015-01-12 03:20:19 +03:00
"commandLineParser.ts" ,
2014-12-11 03:42:41 +03:00
"diagnosticInformationMap.generated.ts"
2014-07-13 03:04:16 +04:00
] . map ( function ( f ) {
return path . join ( compilerDirectory , f ) ;
} ) . concat ( [
2014-10-18 02:39:31 +04:00
"breakpoints.ts" ,
2015-03-19 02:37:52 +03:00
"navigateTo.ts" ,
2014-12-11 03:42:41 +03:00
"navigationBar.ts" ,
"outliningElementsCollector.ts" ,
2015-02-20 11:22:41 +03:00
"patternMatcher.ts" ,
2014-07-13 03:04:16 +04:00
"services.ts" ,
"shims.ts" ,
2014-09-24 06:00:45 +04:00
"signatureHelp.ts" ,
2014-10-01 01:20:58 +04:00
"utilities.ts" ,
2014-12-11 03:42:41 +03:00
"formatting/formatting.ts" ,
"formatting/formattingContext.ts" ,
"formatting/formattingRequestKind.ts" ,
"formatting/formattingScanner.ts" ,
"formatting/references.ts" ,
"formatting/rule.ts" ,
"formatting/ruleAction.ts" ,
"formatting/ruleDescriptor.ts" ,
"formatting/ruleFlag.ts" ,
"formatting/ruleOperation.ts" ,
"formatting/ruleOperationContext.ts" ,
"formatting/rules.ts" ,
"formatting/rulesMap.ts" ,
"formatting/rulesProvider.ts" ,
"formatting/smartIndenter.ts" ,
"formatting/tokenRange.ts"
2014-07-13 03:04:16 +04:00
] . map ( function ( f ) {
return path . join ( servicesDirectory , f ) ;
} ) ) ;
2015-02-12 06:43:10 +03:00
var serverSources = [
"node.d.ts" ,
"editorServices.ts" ,
2015-02-16 05:49:22 +03:00
"protocol.d.ts" ,
"session.ts" ,
2015-02-12 06:43:10 +03:00
"server.ts"
] . map ( function ( f ) {
return path . join ( serverDirectory , f ) ;
2015-06-24 19:28:54 +03:00
} ) . concat ( servicesSources ) ;
2015-02-12 06:43:10 +03:00
2015-06-10 03:00:35 +03:00
var languageServiceLibrarySources = [
"editorServices.ts" ,
"protocol.d.ts" ,
"session.ts"
] . map ( function ( f ) {
return path . join ( serverDirectory , f ) ;
2015-06-17 22:39:02 +03:00
} ) . concat ( servicesSources ) ;
2015-06-10 03:00:35 +03:00
2014-07-13 03:04:16 +04:00
var harnessSources = [
"harness.ts" ,
"sourceMapRecorder.ts" ,
2014-07-29 21:37:01 +04:00
"harnessLanguageService.ts" ,
"fourslash.ts" ,
2014-07-13 03:04:16 +04:00
"runnerbase.ts" ,
"compilerRunner.ts" ,
"typeWriter.ts" ,
2014-07-29 21:37:01 +04:00
"fourslashRunner.ts" ,
2014-07-13 03:04:16 +04:00
"projectsRunner.ts" ,
2014-08-21 02:26:33 +04:00
"loggedIO.ts" ,
2014-07-13 03:04:16 +04:00
"rwcRunner.ts" ,
2014-11-17 22:01:05 +03:00
"test262Runner.ts" ,
2014-07-29 21:37:01 +04:00
"runner.ts"
2014-07-13 03:04:16 +04:00
] . map ( function ( f ) {
return path . join ( harnessDirectory , f ) ;
2014-10-17 05:13:26 +04:00
} ) . concat ( [
2014-12-10 03:39:52 +03:00
"incrementalParser.ts" ,
2015-05-28 20:14:18 +03:00
"jsDocParsing.ts" ,
2014-10-30 03:36:39 +03:00
"services/colorization.ts" ,
2014-10-25 03:03:59 +04:00
"services/documentRegistry.ts" ,
2015-02-20 11:22:41 +03:00
"services/preProcessFile.ts" ,
2015-04-01 03:30:57 +03:00
"services/patternMatcher.ts" ,
2015-04-08 08:54:06 +03:00
"versionCache.ts" ,
2015-05-27 06:18:13 +03:00
"convertToBase64.ts" ,
"transpile.ts"
2014-10-17 05:13:26 +04:00
] . map ( function ( f ) {
return path . join ( unittestsDirectory , f ) ;
2015-02-12 06:43:10 +03:00
} ) ) . concat ( [
2015-02-16 05:49:22 +03:00
"protocol.d.ts" ,
"session.ts" ,
2015-02-12 06:43:10 +03:00
"client.ts" ,
"editorServices.ts" ,
] . map ( function ( f ) {
return path . join ( serverDirectory , f ) ;
2014-10-17 05:13:26 +04:00
} ) ) ;
2014-07-13 03:04:16 +04:00
var librarySourceMap = [
{ target : "lib.core.d.ts" , sources : [ "core.d.ts" ] } ,
2014-11-17 22:35:43 +03:00
{ target : "lib.dom.d.ts" , sources : [ "importcore.d.ts" , "extensions.d.ts" , "intl.d.ts" , "dom.generated.d.ts" ] , } ,
{ target : "lib.webworker.d.ts" , sources : [ "importcore.d.ts" , "extensions.d.ts" , "intl.d.ts" , "webworker.generated.d.ts" ] , } ,
2014-07-13 03:04:16 +04:00
{ target : "lib.scriptHost.d.ts" , sources : [ "importcore.d.ts" , "scriptHost.d.ts" ] , } ,
2014-11-17 22:35:43 +03:00
{ target : "lib.d.ts" , sources : [ "core.d.ts" , "extensions.d.ts" , "intl.d.ts" , "dom.generated.d.ts" , "webworker.importscripts.d.ts" , "scriptHost.d.ts" ] , } ,
2014-11-17 23:47:45 +03:00
{ target : "lib.core.es6.d.ts" , sources : [ "core.d.ts" , "es6.d.ts" ] } ,
2015-06-05 14:54:22 +03:00
{ target : "lib.es6.d.ts" , sources : [ "core.d.ts" , "es6.d.ts" , "intl.d.ts" , "dom.generated.d.ts" , "dom.es6.d.ts" , "webworker.importscripts.d.ts" , "scriptHost.d.ts" ] } ,
2014-07-13 03:04:16 +04:00
] ;
var libraryTargets = librarySourceMap . map ( function ( f ) {
return path . join ( builtLocalDirectory , f . target ) ;
} ) ;
// Prepends the contents of prefixFile to destinationFile
function prependFile ( prefixFile , destinationFile ) {
if ( ! fs . existsSync ( prefixFile ) ) {
fail ( prefixFile + " does not exist!" ) ;
}
if ( ! fs . existsSync ( destinationFile ) ) {
fail ( destinationFile + " failed to be created!" ) ;
}
var temp = "temptemp" ;
jake . cpR ( prefixFile , temp , { silent : true } ) ;
fs . appendFileSync ( temp , fs . readFileSync ( destinationFile ) ) ;
fs . renameSync ( temp , destinationFile ) ;
}
// concatenate a list of sourceFiles to a destinationFile
function concatenateFiles ( destinationFile , sourceFiles ) {
var temp = "temptemp" ;
// Copy the first file to temp
if ( ! fs . existsSync ( sourceFiles [ 0 ] ) ) {
fail ( sourceFiles [ 0 ] + " does not exist!" ) ;
}
jake . cpR ( sourceFiles [ 0 ] , temp , { silent : true } ) ;
// append all files in sequence
for ( var i = 1 ; i < sourceFiles . length ; i ++ ) {
if ( ! fs . existsSync ( sourceFiles [ i ] ) ) {
fail ( sourceFiles [ i ] + " does not exist!" ) ;
}
fs . appendFileSync ( temp , fs . readFileSync ( sourceFiles [ i ] ) ) ;
}
// Move the file to the final destination
fs . renameSync ( temp , destinationFile ) ;
}
2014-11-04 23:18:32 +03:00
var useDebugMode = true ;
2014-09-02 23:19:58 +04:00
var host = ( process . env . host || process . env . TYPESCRIPT_HOST || "node" ) ;
var compilerFilename = "tsc.js" ;
2015-03-04 09:12:06 +03:00
/ * C o m p i l e s a f i l e f r o m a l i s t o f s o u r c e s
2014-07-13 03:04:16 +04:00
* @param outFile : the target file name
* @param sources : an array of the names of the source files
* @param prereqs : prerequisite tasks to compiling the file
* @param prefixes : a list of files to prepend to the target file
* @param useBuiltCompiler : true to use the built compiler , false to use the LKG
* @param noOutFile : true to compile without using -- out
2014-12-11 03:42:41 +03:00
* @param generateDeclarations : true to compile using -- declaration
* @param outDir : true to compile using -- outDir
* @param keepComments : false to compile using -- removeComments
* @param callback : a function to execute after the compilation process ends
2014-07-13 03:04:16 +04:00
* /
2015-03-04 09:12:06 +03:00
function compileFile ( outFile , sources , prereqs , prefixes , useBuiltCompiler , noOutFile , generateDeclarations , outDir , preserveConstEnums , keepComments , noResolve , stripInternal , callback ) {
2014-07-13 03:04:16 +04:00
file ( outFile , prereqs , function ( ) {
var dir = useBuiltCompiler ? builtLocalDirectory : LKGDirectory ;
2014-12-11 03:42:41 +03:00
var options = "--module commonjs -noImplicitAny" ;
2015-04-01 04:00:02 +03:00
// Keep comments when specifically requested
// or when in debug mode.
if ( ! ( keepComments || useDebugMode ) ) {
options += " --removeComments" ;
2014-12-11 03:42:41 +03:00
}
2014-10-08 07:51:23 +04:00
if ( generateDeclarations ) {
2014-12-11 03:42:41 +03:00
options += " --declaration" ;
2014-10-08 07:51:23 +04:00
}
2014-11-04 22:27:34 +03:00
2015-04-01 04:00:02 +03:00
if ( preserveConstEnums || useDebugMode ) {
2014-12-11 03:42:41 +03:00
options += " --preserveConstEnums" ;
}
if ( outDir ) {
options += " --outDir " + outDir ;
}
if ( ! noOutFile ) {
options += " --out " + outFile ;
}
if ( noResolve ) {
options += " --noResolve" ;
2014-07-13 03:04:16 +04:00
}
2014-08-04 23:06:50 +04:00
2014-07-13 03:04:16 +04:00
if ( useDebugMode ) {
2014-12-11 03:42:41 +03:00
options += " -sourcemap -mapRoot file:///" + path . resolve ( path . dirname ( outFile ) ) ;
2014-07-13 03:04:16 +04:00
}
2014-12-11 03:42:41 +03:00
2015-02-04 00:47:46 +03:00
if ( stripInternal ) {
options += " --stripInternal"
}
2014-12-11 03:42:41 +03:00
var cmd = host + " " + dir + compilerFilename + " " + options + " " ;
cmd = cmd + sources . join ( " " ) ;
2015-03-04 09:12:06 +03:00
console . log ( cmd + "\n" ) ;
2014-12-11 03:42:41 +03:00
2015-03-04 09:12:06 +03:00
var ex = jake . createExec ( [ cmd ] ) ;
// Add listeners for output and error
ex . addListener ( "stdout" , function ( output ) {
process . stdout . write ( output ) ;
} ) ;
ex . addListener ( "stderr" , function ( error ) {
process . stderr . write ( error ) ;
} ) ;
ex . addListener ( "cmdEnd" , function ( ) {
2014-07-13 03:04:16 +04:00
if ( ! useDebugMode && prefixes && fs . existsSync ( outFile ) ) {
for ( var i in prefixes ) {
prependFile ( prefixes [ i ] , outFile ) ;
}
}
2014-12-02 02:32:52 +03:00
if ( callback ) {
callback ( ) ;
}
2015-03-04 09:12:06 +03:00
complete ( ) ;
} ) ;
ex . addListener ( "error" , function ( ) {
2014-07-13 03:04:16 +04:00
fs . unlinkSync ( outFile ) ;
2014-12-12 19:49:21 +03:00
fail ( "Compilation of " + outFile + " unsuccessful" ) ;
2014-07-13 03:04:16 +04:00
} ) ;
2015-03-04 09:12:06 +03:00
ex . run ( ) ;
2014-07-13 03:04:16 +04:00
} , { async : true } ) ;
}
// Prerequisite task for built directory and library typings
directory ( builtLocalDirectory ) ;
for ( var i in libraryTargets ) {
( function ( i ) {
var entry = librarySourceMap [ i ] ;
var target = libraryTargets [ i ] ;
var sources = [ copyright ] . concat ( entry . sources . map ( function ( s ) {
return path . join ( libraryDirectory , s ) ;
} ) ) ;
file ( target , [ builtLocalDirectory ] . concat ( sources ) , function ( ) {
concatenateFiles ( target , sources ) ;
} ) ;
} ) ( i ) ;
}
// Lib target to build the library files
desc ( "Builds the library targets" ) ;
task ( "lib" , libraryTargets ) ;
// Generate diagnostics
var processDiagnosticMessagesJs = path . join ( scriptsDirectory , "processDiagnosticMessages.js" ) ;
var processDiagnosticMessagesTs = path . join ( scriptsDirectory , "processDiagnosticMessages.ts" ) ;
var diagnosticMessagesJson = path . join ( compilerDirectory , "diagnosticMessages.json" ) ;
var diagnosticInfoMapTs = path . join ( compilerDirectory , "diagnosticInformationMap.generated.ts" ) ;
2014-08-01 04:20:57 +04:00
file ( processDiagnosticMessagesTs )
2014-07-13 03:04:16 +04:00
// processDiagnosticMessages script
compileFile ( processDiagnosticMessagesJs ,
[ processDiagnosticMessagesTs ] ,
[ processDiagnosticMessagesTs ] ,
[ ] ,
2014-12-02 02:32:52 +03:00
/*useBuiltCompiler*/ false ) ;
2014-07-13 03:04:16 +04:00
// The generated diagnostics map; built for the compiler and for the 'generate-diagnostics' task
file ( diagnosticInfoMapTs , [ processDiagnosticMessagesJs , diagnosticMessagesJson ] , function ( ) {
var cmd = "node " + processDiagnosticMessagesJs + " " + diagnosticMessagesJson ;
2015-03-04 09:12:06 +03:00
console . log ( cmd ) ;
var ex = jake . createExec ( [ cmd ] ) ;
// Add listeners for output and error
ex . addListener ( "stdout" , function ( output ) {
process . stdout . write ( output ) ;
} ) ;
ex . addListener ( "stderr" , function ( error ) {
process . stderr . write ( error ) ;
} ) ;
ex . addListener ( "cmdEnd" , function ( ) {
complete ( ) ;
} ) ;
ex . run ( ) ;
2014-07-13 03:04:16 +04:00
} , { async : true } )
desc ( "Generates a diagnostic file in TypeScript based on an input JSON file" ) ;
task ( "generate-diagnostics" , [ diagnosticInfoMapTs ] )
// Local target to build the compiler and services
2014-09-02 23:19:58 +04:00
var tscFile = path . join ( builtLocalDirectory , compilerFilename ) ;
2014-08-07 10:21:53 +04:00
compileFile ( tscFile , compilerSources , [ builtLocalDirectory , copyright ] . concat ( compilerSources ) , [ copyright ] , /*useBuiltCompiler:*/ false ) ;
2014-07-13 03:04:16 +04:00
2014-08-07 10:21:53 +04:00
var servicesFile = path . join ( builtLocalDirectory , "typescriptServices.js" ) ;
2015-04-10 00:15:07 +03:00
var standaloneDefinitionsFile = path . join ( builtLocalDirectory , "typescriptServices.d.ts" ) ;
2015-02-01 08:14:28 +03:00
var nodePackageFile = path . join ( builtLocalDirectory , "typescript.js" ) ;
2015-04-10 00:15:07 +03:00
var nodeDefinitionsFile = path . join ( builtLocalDirectory , "typescript.d.ts" ) ;
2014-12-13 03:17:30 +03:00
compileFile ( servicesFile , servicesSources , [ builtLocalDirectory , copyright ] . concat ( servicesSources ) ,
/*prefixes*/ [ copyright ] ,
/*useBuiltCompiler*/ true ,
/*noOutFile*/ false ,
2015-04-10 00:15:07 +03:00
/*generateDeclarations*/ true ,
2014-12-13 03:17:30 +03:00
/*outDir*/ undefined ,
/*preserveConstEnums*/ true ,
2015-04-10 00:15:07 +03:00
/*keepComments*/ true ,
2015-02-04 00:47:46 +03:00
/*noResolve*/ false ,
2015-04-10 00:15:07 +03:00
/*stripInternal*/ true ,
2015-02-01 08:14:28 +03:00
/*callback*/ function ( ) {
jake . cpR ( servicesFile , nodePackageFile , { silent : true } ) ;
2014-12-02 02:32:52 +03:00
2015-04-10 00:15:07 +03:00
prependFile ( copyright , standaloneDefinitionsFile ) ;
2014-12-11 03:42:41 +03:00
2015-04-10 00:15:07 +03:00
// Create the node definition file by replacing 'ts' module with '"typescript"' as a module.
jake . cpR ( standaloneDefinitionsFile , nodeDefinitionsFile , { silent : true } ) ;
var definitionFileContents = fs . readFileSync ( nodeDefinitionsFile ) . toString ( ) ;
2015-06-18 09:44:12 +03:00
definitionFileContents = definitionFileContents . replace ( /declare (namespace|module) ts/g , 'declare module "typescript"' ) ;
2015-04-10 00:15:07 +03:00
fs . writeFileSync ( nodeDefinitionsFile , definitionFileContents ) ;
} ) ;
2014-12-11 03:42:41 +03:00
2014-07-13 03:04:16 +04:00
2015-02-16 05:52:17 +03:00
var serverFile = path . join ( builtLocalDirectory , "tsserver.js" ) ;
2015-02-12 06:43:10 +03:00
compileFile ( serverFile , serverSources , [ builtLocalDirectory , copyright ] . concat ( serverSources ) , /*prefixes*/ [ copyright ] , /*useBuiltCompiler*/ true ) ;
2015-06-10 03:00:35 +03:00
var lsslFile = path . join ( builtLocalDirectory , "tslssl.js" ) ;
compileFile (
lsslFile ,
languageServiceLibrarySources ,
2015-06-17 22:39:02 +03:00
[ builtLocalDirectory , copyright ] . concat ( languageServiceLibrarySources ) ,
2015-06-10 03:00:35 +03:00
/*prefixes*/ [ copyright ] ,
/*useBuiltCompiler*/ true ,
/*noOutFile*/ false ,
/*generateDeclarations*/ true ) ;
// Local target to build the language service server library
desc ( "Builds language service server library" ) ;
task ( "lssl" , [ lsslFile ] ) ;
2014-07-13 03:04:16 +04:00
// Local target to build the compiler and services
desc ( "Builds the full compiler and services" ) ;
2015-02-12 06:43:10 +03:00
task ( "local" , [ "generate-diagnostics" , "lib" , tscFile , servicesFile , nodeDefinitionsFile , serverFile ] ) ;
2014-07-13 03:04:16 +04:00
2015-02-04 16:52:45 +03:00
// Local target to build only tsc.js
desc ( "Builds only the compiler" ) ;
task ( "tsc" , [ "generate-diagnostics" , "lib" , tscFile ] ) ;
2014-07-13 03:04:16 +04:00
// Local target to build the compiler and services
2014-11-04 23:18:32 +03:00
desc ( "Sets release mode flag" ) ;
task ( "release" , function ( ) {
useDebugMode = false ;
2014-07-13 03:04:16 +04:00
} ) ;
// Set the default task to "local"
task ( "default" , [ "local" ] ) ;
// Cleans the built directory
desc ( "Cleans the compiler output, declare files, and tests" ) ;
task ( "clean" , function ( ) {
jake . rmRf ( builtDirectory ) ;
} ) ;
2014-09-27 01:36:18 +04:00
// Generate Markdown spec
var word2mdJs = path . join ( scriptsDirectory , "word2md.js" ) ;
var word2mdTs = path . join ( scriptsDirectory , "word2md.ts" ) ;
var specWord = path . join ( docDirectory , "TypeScript Language Specification.docx" ) ;
var specMd = path . join ( docDirectory , "spec.md" ) ;
file ( word2mdTs ) ;
// word2md script
compileFile ( word2mdJs ,
[ word2mdTs ] ,
[ word2mdTs ] ,
[ ] ,
2014-12-02 02:32:52 +03:00
/*useBuiltCompiler*/ false ) ;
2014-09-27 01:36:18 +04:00
// The generated spec.md; built for the 'generate-spec' task
file ( specMd , [ word2mdJs , specWord ] , function ( ) {
2014-10-08 07:51:23 +04:00
var specWordFullPath = path . resolve ( specWord ) ;
2014-10-17 00:27:48 +04:00
var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" ' + specMd ;
2015-03-04 09:12:06 +03:00
console . log ( cmd ) ;
child_process . exec ( cmd , function ( ) {
complete ( ) ;
} ) ;
2014-09-27 01:36:18 +04:00
} , { async : true } )
desc ( "Generates a Markdown version of the Language Specification" ) ;
task ( "generate-spec" , [ specMd ] )
2014-07-13 03:04:16 +04:00
// Makes a new LKG. This target does not build anything, but errors if not all the outputs are present in the built/local directory
desc ( "Makes a new LKG out of the built js files" ) ;
2014-11-04 23:18:32 +03:00
task ( "LKG" , [ "clean" , "release" , "local" ] . concat ( libraryTargets ) , function ( ) {
2015-04-10 00:20:34 +03:00
var expectedFiles = [ tscFile , servicesFile , serverFile , nodePackageFile , nodeDefinitionsFile , standaloneDefinitionsFile ] . concat ( libraryTargets ) ;
2014-07-13 03:04:16 +04:00
var missingFiles = expectedFiles . filter ( function ( f ) {
return ! fs . existsSync ( f ) ;
} ) ;
if ( missingFiles . length > 0 ) {
fail ( "Cannot replace the LKG unless all built targets are present in directory " + builtLocalDirectory +
". The following files are missing:\n" + missingFiles . join ( "\n" ) ) ;
}
// Copy all the targets into the LKG directory
jake . mkdirP ( LKGDirectory ) ;
for ( i in expectedFiles ) {
jake . cpR ( expectedFiles [ i ] , LKGDirectory ) ;
}
//var resourceDirectories = fs.readdirSync(builtLocalResourcesDirectory).map(function(p) { return path.join(builtLocalResourcesDirectory, p); });
//resourceDirectories.map(function(d) {
// jake.cpR(d, LKGResourcesDirectory);
//});
} ) ;
// Test directory
directory ( builtLocalDirectory ) ;
// Task to build the tests infrastructure using the built compiler
var run = path . join ( builtLocalDirectory , "run.js" ) ;
2014-08-07 10:21:53 +04:00
compileFile ( run , harnessSources , [ builtLocalDirectory , tscFile ] . concat ( libraryTargets ) . concat ( harnessSources ) , [ ] , /*useBuiltCompiler:*/ true ) ;
2014-07-13 03:04:16 +04:00
2015-01-30 21:32:07 +03:00
var internalTests = "internal/"
2014-07-13 03:04:16 +04:00
var localBaseline = "tests/baselines/local/" ;
var refBaseline = "tests/baselines/reference/" ;
2015-02-02 23:52:26 +03:00
var localRwcBaseline = path . join ( internalTests , "baselines/rwc/local" ) ;
var refRwcBaseline = path . join ( internalTests , "baselines/rwc/reference" ) ;
2014-07-13 03:04:16 +04:00
2015-02-02 23:52:26 +03:00
var localTest262Baseline = path . join ( internalTests , "baselines/test262/local" ) ;
var refTest262Baseline = path . join ( internalTests , "baselines/test262/reference" ) ;
2014-11-17 22:01:05 +03:00
2014-07-13 03:04:16 +04:00
desc ( "Builds the test infrastructure using the built compiler" ) ;
task ( "tests" , [ "local" , run ] . concat ( libraryTargets ) ) ;
2015-03-04 09:12:06 +03:00
function exec ( cmd , completeHandler ) {
var ex = jake . createExec ( [ cmd ] , { windowsVerbatimArguments : true } ) ;
// Add listeners for output and error
ex . addListener ( "stdout" , function ( output ) {
process . stdout . write ( output ) ;
} ) ;
ex . addListener ( "stderr" , function ( error ) {
process . stderr . write ( error ) ;
} ) ;
2014-07-13 03:04:16 +04:00
ex . addListener ( "cmdEnd" , function ( ) {
2014-07-17 23:32:51 +04:00
if ( completeHandler ) {
completeHandler ( ) ;
}
2015-03-04 09:12:06 +03:00
complete ( ) ;
2014-07-13 03:04:16 +04:00
} ) ;
2015-03-04 09:12:06 +03:00
ex . addListener ( "error" , function ( e , status ) {
2014-12-17 02:28:36 +03:00
fail ( "Process exited with code " + status ) ;
2014-07-24 04:27:30 +04:00
} )
2014-12-17 02:28:36 +03:00
ex . run ( ) ;
2014-07-13 03:04:16 +04:00
}
function cleanTestDirs() {
// Clean the local baselines directory
if ( fs . existsSync ( localBaseline ) ) {
jake . rmRf ( localBaseline ) ;
}
2015-01-30 21:32:07 +03:00
// Clean the local Rwc baselines directory
2014-07-13 03:04:16 +04:00
if ( fs . existsSync ( localRwcBaseline ) ) {
jake . rmRf ( localRwcBaseline ) ;
}
2015-01-30 21:32:07 +03:00
jake . mkdirP ( localRwcBaseline ) ;
2015-03-19 02:37:52 +03:00
jake . mkdirP ( localTest262Baseline ) ;
2014-07-13 03:04:16 +04:00
jake . mkdirP ( localBaseline ) ;
}
// used to pass data from jake command line directly to run.js
2015-04-29 22:13:35 +03:00
function writeTestConfigFile ( tests , light , testConfigFile ) {
2014-07-13 03:04:16 +04:00
console . log ( 'Running test(s): ' + tests ) ;
2015-04-29 22:13:35 +03:00
var testConfigContents = JSON . stringify ( { test : [ tests ] , light : light } ) ;
2014-09-18 22:49:40 +04:00
fs . writeFileSync ( 'test.config' , testConfigContents ) ;
2014-07-13 03:04:16 +04:00
}
2014-07-17 23:32:51 +04:00
function deleteTemporaryProjectOutput() {
2015-02-02 23:52:26 +03:00
if ( fs . existsSync ( path . join ( localBaseline , "projectOutput/" ) ) ) {
jake . rmRf ( path . join ( localBaseline , "projectOutput/" ) ) ;
2014-07-17 23:32:51 +04:00
}
}
2014-12-15 11:24:03 +03:00
var testTimeout = 20000 ;
2014-07-13 03:04:16 +04:00
desc ( "Runs the tests using the built run.js file. Syntax is jake runtests. Optional parameters 'host=', 'tests=[regex], reporter=[list|spec|json|<more>]'." ) ;
task ( "runtests" , [ "tests" , builtLocalDirectory ] , function ( ) {
cleanTestDirs ( ) ;
host = "mocha"
2014-07-18 02:26:50 +04:00
tests = process . env . test || process . env . tests || process . env . t ;
2015-04-29 22:13:35 +03:00
var light = process . env . light || false ;
2014-07-13 03:04:16 +04:00
var testConfigFile = 'test.config' ;
if ( fs . existsSync ( testConfigFile ) ) {
fs . unlinkSync ( testConfigFile ) ;
}
2014-09-03 21:37:32 +04:00
2015-04-29 22:13:35 +03:00
if ( tests || light ) {
writeTestConfigFile ( tests , light , testConfigFile ) ;
2014-07-13 03:04:16 +04:00
}
2014-09-03 21:37:32 +04:00
if ( tests && tests . toLocaleLowerCase ( ) === "rwc" ) {
2015-02-20 00:52:50 +03:00
testTimeout = 100000 ;
2014-09-03 21:37:32 +04:00
}
2014-07-13 03:04:16 +04:00
colors = process . env . colors || process . env . color
2015-02-24 03:16:26 +03:00
colors = colors ? ' --no-colors ' : ' --colors ' ;
2014-07-13 03:04:16 +04:00
tests = tests ? ' -g ' + tests : '' ;
reporter = process . env . reporter || process . env . r || 'dot' ;
2014-07-26 04:01:01 +04:00
// timeout normally isn't necessary but Travis-CI has been timing out on compiler baselines occasionally
// default timeout is 2sec which really should be enough, but maybe we just need a small amount longer
2014-08-02 02:06:43 +04:00
var cmd = host + " -R " + reporter + tests + colors + ' -t ' + testTimeout + ' ' + run ;
2015-03-04 09:12:06 +03:00
console . log ( cmd ) ;
2014-07-17 23:32:51 +04:00
exec ( cmd , deleteTemporaryProjectOutput ) ;
2014-07-13 03:04:16 +04:00
} , { async : true } ) ;
2014-07-25 03:03:13 +04:00
desc ( "Generates code coverage data via instanbul" )
task ( "generate-code-coverage" , [ "tests" , builtLocalDirectory ] , function ( ) {
2014-09-03 01:22:14 +04:00
var cmd = 'istanbul cover node_modules/mocha/bin/_mocha -- -R min -t ' + testTimeout + ' ' + run ;
2015-03-04 09:12:06 +03:00
console . log ( cmd ) ;
2014-09-18 22:49:40 +04:00
exec ( cmd ) ;
2014-07-25 03:03:13 +04:00
} , { async : true } ) ;
2014-07-13 03:04:16 +04:00
// Browser tests
var nodeServerOutFile = 'tests/webTestServer.js'
var nodeServerInFile = 'tests/webTestServer.ts'
2014-12-02 02:32:52 +03:00
compileFile ( nodeServerOutFile , [ nodeServerInFile ] , [ builtLocalDirectory , tscFile ] , [ ] , /*useBuiltCompiler:*/ true , /*noOutFile*/ true ) ;
2014-07-13 03:04:16 +04:00
desc ( "Runs browserify on run.js to produce a file suitable for running tests in the browser" ) ;
task ( "browserify" , [ "tests" , builtLocalDirectory , nodeServerOutFile ] , function ( ) {
var cmd = 'browserify built/local/run.js -o built/local/bundle.js' ;
exec ( cmd ) ;
} , { async : true } ) ;
desc ( "Runs the tests using the built run.js file like 'jake runtests'. Syntax is jake runtests-browser. Additional optional parameters tests=[regex], port=, browser=[chrome|IE]" ) ;
task ( "runtests-browser" , [ "tests" , "browserify" , builtLocalDirectory ] , function ( ) {
cleanTestDirs ( ) ;
host = "node"
2014-07-18 02:26:50 +04:00
port = process . env . port || process . env . p || '8888' ;
browser = process . env . browser || process . env . b || "IE" ;
tests = process . env . test || process . env . tests || process . env . t ;
2015-04-29 22:13:35 +03:00
var light = process . env . light || false ;
2014-07-13 03:04:16 +04:00
var testConfigFile = 'test.config' ;
if ( fs . existsSync ( testConfigFile ) ) {
fs . unlinkSync ( testConfigFile ) ;
}
2015-04-29 22:13:35 +03:00
if ( tests || light ) {
writeTestConfigFile ( tests , light , testConfigFile ) ;
2014-07-13 03:04:16 +04:00
}
tests = tests ? tests : '' ;
var cmd = host + " tests/webTestServer.js " + port + " " + browser + " " + tests
2015-03-04 09:12:06 +03:00
console . log ( cmd ) ;
2014-07-13 03:04:16 +04:00
exec ( cmd ) ;
} , { async : true } ) ;
2014-12-04 17:27:24 +03:00
function getDiffTool() {
2014-12-04 22:15:00 +03:00
var program = process . env [ 'DIFF' ]
if ( ! program ) {
fail ( "Add the 'DIFF' environment variable to the path of the program you want to use." )
}
2014-12-04 17:27:24 +03:00
return program ;
}
2014-07-13 03:04:16 +04:00
// Baseline Diff
2014-12-04 22:15:00 +03:00
desc ( "Diffs the compiler baselines using the diff tool specified by the 'DIFF' environment variable" ) ;
2014-07-13 03:04:16 +04:00
task ( 'diff' , function ( ) {
2014-12-04 17:27:24 +03:00
var cmd = '"' + getDiffTool ( ) + '" ' + refBaseline + ' ' + localBaseline ;
2015-03-04 09:12:06 +03:00
console . log ( cmd )
2014-07-13 03:04:16 +04:00
exec ( cmd ) ;
} , { async : true } ) ;
2014-12-04 22:15:00 +03:00
desc ( "Diffs the RWC baselines using the diff tool specified by the 'DIFF' environment variable" ) ;
2014-07-13 03:04:16 +04:00
task ( 'diff-rwc' , function ( ) {
2014-12-04 17:27:24 +03:00
var cmd = '"' + getDiffTool ( ) + '" ' + refRwcBaseline + ' ' + localRwcBaseline ;
2015-03-04 09:12:06 +03:00
console . log ( cmd )
2014-07-13 03:04:16 +04:00
exec ( cmd ) ;
} , { async : true } ) ;
desc ( "Builds the test sources and automation in debug mode" ) ;
task ( "tests-debug" , [ "setDebugMode" , "tests" ] ) ;
// Makes the test results the new baseline
desc ( "Makes the most recent test results the new baseline, overwriting the old baseline" ) ;
task ( "baseline-accept" , function ( hardOrSoft ) {
if ( ! hardOrSoft || hardOrSoft == "hard" ) {
jake . rmRf ( refBaseline ) ;
fs . renameSync ( localBaseline , refBaseline ) ;
}
else if ( hardOrSoft == "soft" ) {
var files = jake . readdirR ( localBaseline ) ;
for ( var i in files ) {
jake . cpR ( files [ i ] , refBaseline ) ;
}
jake . rmRf ( path . join ( refBaseline , "local" ) ) ;
}
} ) ;
desc ( "Makes the most recent rwc test results the new baseline, overwriting the old baseline" ) ;
task ( "baseline-accept-rwc" , function ( ) {
jake . rmRf ( refRwcBaseline ) ;
fs . renameSync ( localRwcBaseline , refRwcBaseline ) ;
} ) ;
2014-11-17 22:01:05 +03:00
desc ( "Makes the most recent test262 test results the new baseline, overwriting the old baseline" ) ;
task ( "baseline-accept-test262" , function ( ) {
jake . rmRf ( refTest262Baseline ) ;
fs . renameSync ( localTest262Baseline , refTest262Baseline ) ;
} ) ;
2014-07-13 03:04:16 +04:00
// Webhost
var webhostPath = "tests/webhost/webtsc.ts" ;
var webhostJsPath = "tests/webhost/webtsc.js" ;
2014-12-02 02:32:52 +03:00
compileFile ( webhostJsPath , [ webhostPath ] , [ tscFile , webhostPath ] . concat ( libraryTargets ) , [ ] , /*useBuiltCompiler*/ true ) ;
2014-07-13 03:04:16 +04:00
desc ( "Builds the tsc web host" ) ;
task ( "webhost" , [ webhostJsPath ] , function ( ) {
2014-09-03 01:22:14 +04:00
jake . cpR ( path . join ( builtLocalDirectory , "lib.d.ts" ) , "tests/webhost/" , { silent : true } ) ;
2014-07-13 03:04:16 +04:00
} ) ;
2015-03-04 09:12:06 +03:00
// Perf compiler
var perftscPath = "tests/perftsc.ts" ;
var perftscJsPath = "built/local/perftsc.js" ;
compileFile ( perftscJsPath , [ perftscPath ] , [ tscFile , perftscPath , "tests/perfsys.ts" ] . concat ( libraryTargets ) , [ ] , /*useBuiltCompiler*/ true ) ;
desc ( "Builds augmented version of the compiler for perf tests" ) ;
task ( "perftsc" , [ perftscJsPath ] ) ;
2014-09-02 23:19:58 +04:00
// Instrumented compiler
var loggedIOpath = harnessDirectory + 'loggedIO.ts' ;
var loggedIOJsPath = builtLocalDirectory + 'loggedIO.js' ;
2014-09-03 01:22:14 +04:00
file ( loggedIOJsPath , [ builtLocalDirectory , loggedIOpath ] , function ( ) {
var temp = builtLocalDirectory + 'temp' ;
2014-09-02 23:19:58 +04:00
jake . mkdirP ( temp ) ;
var options = "--outdir " + temp + ' ' + loggedIOpath ;
var cmd = host + " " + LKGDirectory + compilerFilename + " " + options + " " ;
2015-03-04 09:12:06 +03:00
console . log ( cmd + "\n" ) ;
var ex = jake . createExec ( [ cmd ] ) ;
ex . addListener ( "cmdEnd" , function ( ) {
2014-09-03 01:22:14 +04:00
fs . renameSync ( temp + '/harness/loggedIO.js' , loggedIOJsPath ) ;
jake . rmRf ( temp ) ;
complete ( ) ;
2014-09-02 23:19:58 +04:00
} ) ;
2015-03-04 09:12:06 +03:00
ex . run ( ) ;
2014-09-02 23:19:58 +04:00
} , { async : true } ) ;
var instrumenterPath = harnessDirectory + 'instrumenter.ts' ;
var instrumenterJsPath = builtLocalDirectory + 'instrumenter.js' ;
2015-03-19 03:23:40 +03:00
compileFile ( instrumenterJsPath , [ instrumenterPath ] , [ tscFile , instrumenterPath ] . concat ( libraryTargets ) , [ ] , /*useBuiltCompiler*/ true ) ;
2014-09-02 23:19:58 +04:00
desc ( "Builds an instrumented tsc.js" ) ;
task ( 'tsc-instrumented' , [ loggedIOJsPath , instrumenterJsPath , tscFile ] , function ( ) {
2014-09-03 01:22:14 +04:00
var cmd = host + ' ' + instrumenterJsPath + ' record iocapture ' + builtLocalDirectory + compilerFilename ;
2015-03-04 09:12:06 +03:00
console . log ( cmd ) ;
var ex = jake . createExec ( [ cmd ] ) ;
ex . addListener ( "cmdEnd" , function ( ) {
complete ( ) ;
} ) ;
ex . run ( ) ;
2014-09-03 01:22:14 +04:00
} , { async : true } ) ;
2015-06-23 19:05:49 +03:00
desc ( "Updates the sublime plugin's tsserver" ) ;
task ( "update-sublime" , [ serverFile ] , function ( ) {
jake . cpR ( serverFile , "../TypeScript-Sublime-Plugin/tsserver/" ) ;
jake . cpR ( serverFile + ".map" , "../TypeScript-Sublime-Plugin/tsserver/" ) ;
} ) ;