@@ -32,6 +32,7 @@ import browserify = require("browserify");
3232import through2 = require( "through2" ) ;
3333import merge2 = require( "merge2" ) ;
3434import intoStream = require( "into-stream" ) ;
35+ import lazypipe = require( "lazypipe" ) ;
3536import * as os from "os" ;
3637import Linter = require( "tslint" ) ;
3738const gulp = helpMaker ( originalGulp ) ;
@@ -434,55 +435,50 @@ const nodePackageFile = path.join(builtLocalDirectory, "typescript.js");
434435const nodeDefinitionsFile = path . join ( builtLocalDirectory , "typescript.d.ts" ) ;
435436const nodeStandaloneDefinitionsFile = path . join ( builtLocalDirectory , "typescript_standalone.d.ts" ) ;
436437
438+ const prependCopyright = lazypipe ( )
439+ . pipe ( ( ) => insert . prepend ( fs . readFileSync ( copyright ) ) ) ;
440+
437441gulp . task ( builtLocalCompiler , false , [ servicesFile ] , ( ) => {
438442 const localCompilerProject = tsc . createProject ( "src/compiler/tsconfig.json" , getCompilerSettings ( { } , /*useBuiltCompiler*/ true ) ) ;
439443 return localCompilerProject . src ( )
440444 . pipe ( newer ( builtLocalCompiler ) )
441445 . pipe ( sourcemaps . init ( ) )
442446 . pipe ( tsc ( localCompilerProject ) )
443- . pipe ( gIf ( useDebugMode , insert . prepend ( fs . readFileSync ( copyright ) ) ) )
447+ . pipe ( gIf ( useDebugMode , prependCopyright ( ) ) )
444448 . pipe ( sourcemaps . write ( "." ) )
445449 . pipe ( gulp . dest ( builtLocalDirectory ) ) ;
446450} ) ;
447451
448- gulp . task ( servicesFile , false , [ "lib" , "generate-diagnostics" ] , ( done ) => {
452+ gulp . task ( servicesFile , false , [ "lib" , "generate-diagnostics" ] , ( ) => {
449453 const servicesProject = tsc . createProject ( "src/services/tsconfig.json" , getCompilerSettings ( { } , /*useBuiltCompiler*/ false ) ) ;
450454 const { js, dts} = servicesProject . src ( )
451455 . pipe ( newer ( servicesFile ) )
452456 . pipe ( sourcemaps . init ( ) )
453457 . pipe ( tsc ( servicesProject ) ) ;
454- js . pipe ( gIf ( useDebugMode , insert . prepend ( fs . readFileSync ( copyright ) ) ) )
455- . pipe ( sourcemaps . write ( "." ) )
456- . pipe ( gulp . dest ( builtLocalDirectory ) )
457- . on ( "end" , ( ) => {
458- gulp . src ( servicesFile ) . pipe ( insert . transform ( ( content , file ) => ( file . path = nodePackageFile , content ) ) ) . pipe ( gulp . dest ( builtLocalDirectory ) ) . on ( "end" , ( ) => {
459- // Stanalone/web definition file using global 'ts' namespace
460- const defs = dts . pipe ( insert . prepend ( fs . readFileSync ( copyright ) ) ) . pipe ( insert . transform ( ( contents , file ) => {
461- file . path = standaloneDefinitionsFile ;
462- return contents . replace ( / ^ ( \s * ) ( e x p o r t ) ? c o n s t e n u m ( \S + ) { ( \s * ) $ / gm, "$1$2enum $3 {$4" ) ;
463- } ) ) ;
464-
465- // Official node package definition file, pointed to by 'typings' in package.json
466- // Created by appending 'export = ts;' at the end of the standalone file to turn it into an external module
467- const nodeDefs = defs . pipe ( clone ( ) ) . pipe ( insert . transform ( ( content , file ) => {
468- file . path = nodeDefinitionsFile ;
469- return content + "\r\nexport = ts;" ;
470- } ) ) ;
471-
472- // Node package definition file to be distributed without the package. Created by replacing
473- // 'ts' namespace with '"typescript"' as a module.
474- const nodeStandaloneDefs = defs . pipe ( clone ( ) ) . pipe ( insert . transform ( ( content , file ) => {
475- file . path = nodeStandaloneDefinitionsFile ;
476- return content . replace ( / d e c l a r e ( n a m e s p a c e | m o d u l e ) t s / g, 'declare module "typescript"' ) ;
477- } ) ) ;
478-
479- merge2 ( [ defs , nodeDefs , nodeStandaloneDefs ] ) . pipe ( gulp . dest ( builtLocalDirectory ) )
480- . on ( "end" , ( ) => done ( ) )
481- . on ( "error" , ( err ) => console . error ( err ) ) ;
482- } )
483- . on ( "error" , ( err ) => console . error ( err ) ) ;
484- } )
485- . on ( "error" , ( err ) => console . error ( err ) ) ;
458+ const completedJs = js . pipe ( gIf ( useDebugMode , prependCopyright ( ) ) )
459+ . pipe ( sourcemaps . write ( "." ) ) ;
460+ const completedDts = dts . pipe ( prependCopyright ( ) )
461+ . pipe ( insert . transform ( ( contents , file ) => {
462+ file . path = standaloneDefinitionsFile ;
463+ return contents . replace ( / ^ ( \s * ) ( e x p o r t ) ? c o n s t e n u m ( \S + ) { ( \s * ) $ / gm, "$1$2enum $3 {$4" ) ;
464+ } ) ) ;
465+ return merge2 ( [
466+ completedJs ,
467+ completedJs . pipe ( clone ( ) )
468+ . pipe ( insert . transform ( ( content , file ) => ( file . path = nodePackageFile , content ) ) ) ,
469+ completedDts ,
470+ completedDts . pipe ( clone ( ) )
471+ . pipe ( insert . transform ( ( content , file ) => {
472+ file . path = nodeDefinitionsFile ;
473+ return content + "\r\nexport = ts;" ;
474+ } ) )
475+ . pipe ( gulp . dest ( builtLocalDirectory ) ) ,
476+ completedDts . pipe ( clone ( ) )
477+ . pipe ( insert . transform ( ( content , file ) => {
478+ file . path = nodeStandaloneDefinitionsFile ;
479+ return content . replace ( / d e c l a r e ( n a m e s p a c e | m o d u l e ) t s / g, 'declare module "typescript"' ) ;
480+ } ) )
481+ ] ) . pipe ( gulp . dest ( builtLocalDirectory ) ) ;
486482} ) ;
487483
488484const serverFile = path . join ( builtLocalDirectory , "tsserver.js" ) ;
@@ -493,7 +489,7 @@ gulp.task(serverFile, false, [servicesFile], () => {
493489 . pipe ( newer ( serverFile ) )
494490 . pipe ( sourcemaps . init ( ) )
495491 . pipe ( tsc ( serverProject ) )
496- . pipe ( gIf ( useDebugMode , insert . prepend ( fs . readFileSync ( copyright ) ) ) )
492+ . pipe ( gIf ( useDebugMode , prependCopyright ( ) ) )
497493 . pipe ( sourcemaps . write ( "." ) )
498494 . pipe ( gulp . dest ( builtLocalDirectory ) ) ;
499495} ) ;
@@ -512,10 +508,10 @@ gulp.task(tsserverLibraryFile, false, [servicesFile], (done) => {
512508 . pipe ( tsc ( settings ) ) ;
513509
514510 return merge2 ( [
515- js . pipe ( gIf ( useDebugMode , insert . prepend ( fs . readFileSync ( copyright ) ) ) )
511+ js . pipe ( gIf ( useDebugMode , prependCopyright ( ) ) )
516512 . pipe ( sourcemaps . write ( "." ) )
517513 . pipe ( gulp . dest ( "." ) ) ,
518- dts . pipe ( gIf ( useDebugMode , insert . prepend ( fs . readFileSync ( copyright ) ) ) )
514+ dts . pipe ( gIf ( useDebugMode , prependCopyright ( ) ) )
519515 . pipe ( gulp . dest ( "." ) )
520516 ] ) ;
521517} ) ;
0 commit comments