11'use strict' ;
22
33import destCopy from '../broccoli-dest-copy' ;
4- import compileWithTypescript from '../broccoli-typescript' ;
4+ import compileWithTypescript , { INTERNAL_TYPINGS_PATH }
5+ from '../broccoli-typescript' ;
56var Funnel = require ( 'broccoli-funnel' ) ;
67import mergeTrees from '../broccoli-merge-trees' ;
78var path = require ( 'path' ) ;
@@ -11,13 +12,47 @@ var stew = require('broccoli-stew');
1112
1213var projectRootDir = path . normalize ( path . join ( __dirname , '..' , '..' , '..' , '..' ) ) ;
1314
14-
1515module . exports = function makeNodeTree ( projects , destinationPath ) {
1616 // list of npm packages that this build will create
1717 var outputPackages = [ 'angular2' , 'benchpress' ] ;
1818
19- var modulesTree = new Funnel ( 'modules' , {
20- include : [ 'angular2/**' , 'benchpress/**' , '**/e2e_test/**' ] ,
19+ let srcTree = new Funnel ( 'modules' , {
20+ include : [ 'angular2/**' ] ,
21+ exclude : [
22+ '**/e2e_test/**' ,
23+ 'angular2/test/**' ,
24+ 'angular2/examples/**' ,
25+
26+ 'angular2/src/testing/**' ,
27+ 'angular2/testing.ts' ,
28+ 'angular2/testing_internal.ts' ,
29+ 'angular2/src/upgrade/**' ,
30+ 'angular2/upgrade.ts' ,
31+ 'angular2/platform/testing/**' ,
32+ ]
33+ } ) ;
34+
35+ // Compile the sources and generate the @internal .d.ts
36+ let compiledSrcTreeWithInternals =
37+ compileTree ( srcTree , true , [ 'angular2/manual_typings/globals.d.ts' ] ) ;
38+
39+ var testTree = new Funnel ( 'modules' , {
40+ include : [
41+ 'angular2/manual_typings/**' ,
42+ 'angular2/typings/**' ,
43+
44+ 'angular2/test/**' ,
45+ 'benchpress/**' ,
46+ '**/e2e_test/**' ,
47+ 'angular2/examples/**/*_spec.ts' ,
48+
49+ 'angular2/src/testing/**' ,
50+ 'angular2/testing.ts' ,
51+ 'angular2/testing_internal.ts' ,
52+ 'angular2/src/upgrade/**' ,
53+ 'angular2/upgrade.ts' ,
54+ 'angular2/platform/testing/**' ,
55+ ] ,
2156 exclude : [
2257 // the following code and tests are not compatible with CJS/node environment
2358 'angular2/test/animate/**' ,
@@ -41,58 +76,48 @@ module.exports = function makeNodeTree(projects, destinationPath) {
4176 'angular2/test/upgrade/**/*.ts' ,
4277
4378 'angular1_router/**' ,
44- 'angular2/examples/**/!(*_spec.ts)' ,
4579 ]
4680 } ) ;
4781
48- var typescriptTree = compileWithTypescript ( modulesTree , {
49- emitDecoratorMetadata : true ,
50- experimentalDecorators : true ,
51- declaration : true ,
52- stripInternal : true ,
53- module : 'commonjs' ,
54- moduleResolution : 'classic' ,
55- noEmitOnError : true ,
56- rootDir : '.' ,
57- rootFilePaths :
58- [ 'angular2/manual_typings/globals.d.ts' , 'angular2/typings/es6-shim/es6-shim.d.ts' ] ,
59- inlineSourceMap : true ,
60- inlineSources : true ,
61- target : 'es5'
62- } ) ;
82+ // Compile the tests against the src @internal .d.ts
83+ let srcPrivateDeclarations =
84+ new Funnel ( compiledSrcTreeWithInternals , { srcDir : INTERNAL_TYPINGS_PATH } ) ;
85+
86+ testTree = mergeTrees ( [ testTree , srcPrivateDeclarations ] ) ;
87+
88+ let compiledTestTree = compileTree ( testTree , false , [
89+ 'angular2/typings/jasmine/jasmine.d.ts' ,
90+ 'angular2/typings/angular-protractor/angular-protractor.d.ts' ,
91+ 'angular2/manual_typings/globals.d.ts'
92+ ] ) ;
93+
94+ // Merge the compiled sources and tests
95+ let compiledSrcTree =
96+ new Funnel ( compiledSrcTreeWithInternals , { exclude : [ `${ INTERNAL_TYPINGS_PATH } /**` ] } ) ;
97+
98+ let compiledTree = mergeTrees ( [ compiledSrcTree , compiledTestTree ] ) ;
6399
64100 // Now we add the LICENSE file into all the folders that will become npm packages
65101 outputPackages . forEach ( function ( destDir ) {
66102 var license = new Funnel ( '.' , { files : [ 'LICENSE' ] , destDir : destDir } ) ;
67- typescriptTree = mergeTrees ( [ typescriptTree , license ] ) ;
103+ // merge the test tree
104+ compiledTree = mergeTrees ( [ compiledTree , license ] ) ;
68105 } ) ;
69106
70107 // Get all docs and related assets and prepare them for js build
71- var docs = new Funnel ( modulesTree , { include : [ '**/*.md' , '**/*.png' ] , exclude : [ '**/*.dart.md' ] } ) ;
72- docs = stew . rename ( docs , 'README.js.md' , 'README.md' ) ;
108+ var srcDocs = extractDocs ( srcTree ) ;
109+ var testDocs = extractDocs ( testTree ) ;
73110
74- // Generate shared package.json info
75111 var BASE_PACKAGE_JSON = require ( path . join ( projectRootDir , 'package.json' ) ) ;
76- var COMMON_PACKAGE_JSON = {
77- version : BASE_PACKAGE_JSON . version ,
78- homepage : BASE_PACKAGE_JSON . homepage ,
79- bugs : BASE_PACKAGE_JSON . bugs ,
80- license : BASE_PACKAGE_JSON . license ,
81- repository : BASE_PACKAGE_JSON . repository ,
82- contributors : BASE_PACKAGE_JSON . contributors ,
83- dependencies : BASE_PACKAGE_JSON . dependencies ,
84- devDependencies : BASE_PACKAGE_JSON . devDependencies ,
85- defaultDevDependencies : { }
86- } ;
87-
88- var packageJsons = new Funnel ( modulesTree , { include : [ '**/package.json' ] } ) ;
89- packageJsons =
90- renderLodashTemplate ( packageJsons , { context : { 'packageJson' : COMMON_PACKAGE_JSON } } ) ;
112+ var srcPkgJsons = extractPkgJsons ( srcTree , BASE_PACKAGE_JSON ) ;
113+ var testPkgJsons = extractPkgJsons ( testTree , BASE_PACKAGE_JSON ) ;
91114
92115 var typingsTree = new Funnel (
93116 'modules' ,
94117 { include : [ 'angular2/typings/**/*.d.ts' , 'angular2/manual_typings/*.d.ts' ] , destDir : '/' } ) ;
95- var nodeTree = mergeTrees ( [ typescriptTree , docs , packageJsons , typingsTree ] ) ;
118+
119+ var nodeTree =
120+ mergeTrees ( [ compiledTree , srcDocs , testDocs , srcPkgJsons , testPkgJsons , typingsTree ] ) ;
96121
97122 // Transform all tests to make them runnable in node
98123 nodeTree = replace ( nodeTree , {
@@ -132,3 +157,46 @@ module.exports = function makeNodeTree(projects, destinationPath) {
132157
133158 return destCopy ( nodeTree , destinationPath ) ;
134159} ;
160+
161+ function compileTree ( tree , genInternalTypings , rootFilePaths : string [ ] = [ ] ) {
162+ return compileWithTypescript ( tree , {
163+ // build pipeline options
164+ "rootFilePaths" : rootFilePaths ,
165+ "internalTypings" : genInternalTypings ,
166+ // tsc options
167+ "emitDecoratorMetadata" : true ,
168+ "experimentalDecorators" : true ,
169+ "declaration" : true ,
170+ "stripInternal" : true ,
171+ "module" : "commonjs" ,
172+ "moduleResolution" : "classic" ,
173+ "noEmitOnError" : true ,
174+ "rootDir" : "." ,
175+ "inlineSourceMap" : true ,
176+ "inlineSources" : true ,
177+ "target" : "es5"
178+ } ) ;
179+ }
180+
181+ function extractDocs ( tree ) {
182+ var docs = new Funnel ( tree , { include : [ '**/*.md' , '**/*.png' ] , exclude : [ '**/*.dart.md' ] } ) ;
183+ return stew . rename ( docs , 'README.js.md' , 'README.md' ) ;
184+ }
185+
186+ function extractPkgJsons ( tree , BASE_PACKAGE_JSON ) {
187+ // Generate shared package.json info
188+ var COMMON_PACKAGE_JSON = {
189+ version : BASE_PACKAGE_JSON . version ,
190+ homepage : BASE_PACKAGE_JSON . homepage ,
191+ bugs : BASE_PACKAGE_JSON . bugs ,
192+ license : BASE_PACKAGE_JSON . license ,
193+ repository : BASE_PACKAGE_JSON . repository ,
194+ contributors : BASE_PACKAGE_JSON . contributors ,
195+ dependencies : BASE_PACKAGE_JSON . dependencies ,
196+ devDependencies : BASE_PACKAGE_JSON . devDependencies ,
197+ defaultDevDependencies : { }
198+ } ;
199+
200+ var packageJsons = new Funnel ( tree , { include : [ '**/package.json' ] } ) ;
201+ return renderLodashTemplate ( packageJsons , { context : { 'packageJson' : COMMON_PACKAGE_JSON } } ) ;
202+ }
0 commit comments