| 
									
										
										
										
											2015-04-13 16:39:47 -07:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-04 08:19:25 -07:00
										 |  |  | import destCopy from '../broccoli-dest-copy'; | 
					
						
							| 
									
										
										
										
											2015-05-27 18:26:54 -07:00
										 |  |  | import compileWithTypescript from '../broccoli-typescript'; | 
					
						
							| 
									
										
										
										
											2015-04-13 16:39:47 -07:00
										 |  |  | var Funnel = require('broccoli-funnel'); | 
					
						
							| 
									
										
										
										
											2015-05-21 12:07:52 -04:00
										 |  |  | import mergeTrees from '../broccoli-merge-trees'; | 
					
						
							| 
									
										
										
										
											2015-04-13 16:39:47 -07:00
										 |  |  | var path = require('path'); | 
					
						
							| 
									
										
										
										
											2015-06-09 13:35:58 -04:00
										 |  |  | import renderLodashTemplate from '../broccoli-lodash'; | 
					
						
							| 
									
										
										
										
											2015-06-08 11:05:32 -07:00
										 |  |  | import replace from '../broccoli-replace'; | 
					
						
							| 
									
										
										
										
											2015-04-13 16:39:47 -07:00
										 |  |  | var stew = require('broccoli-stew'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-26 01:04:28 -07:00
										 |  |  | var projectRootDir = path.normalize(path.join(__dirname, '..', '..', '..', '..')); | 
					
						
							| 
									
										
										
										
											2015-04-13 16:39:47 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-26 00:31:53 -07:00
										 |  |  | module.exports = function makeNodeTree(destinationPath) { | 
					
						
							| 
									
										
										
										
											2015-04-13 16:39:47 -07:00
										 |  |  |   // list of npm packages that this build will create
 | 
					
						
							| 
									
										
										
										
											2015-07-28 13:10:25 -07:00
										 |  |  |   var outputPackages = ['angular2', 'http', 'benchpress', 'rtts_assert']; | 
					
						
							| 
									
										
										
										
											2015-04-13 16:39:47 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   var modulesTree = new Funnel('modules', { | 
					
						
							| 
									
										
										
										
											2015-07-28 13:10:25 -07:00
										 |  |  |     include: ['angular2/**', 'http/**', 'benchpress/**', 'rtts_assert/**', '**/e2e_test/**'], | 
					
						
							| 
									
										
										
										
											2015-04-13 23:56:07 -07:00
										 |  |  |     exclude: [ | 
					
						
							| 
									
										
										
										
											2015-04-26 18:04:45 -07:00
										 |  |  |       // the following code and tests are not compatible with CJS/node environment
 | 
					
						
							| 
									
										
										
										
											2015-05-12 16:28:57 +02:00
										 |  |  |       'angular2/test/core/zone/**', | 
					
						
							| 
									
										
										
										
											2015-05-27 09:53:37 -07:00
										 |  |  |       'angular2/test/test_lib/fake_async_spec.ts', | 
					
						
							| 
									
										
										
										
											2015-06-09 10:21:25 -07:00
										 |  |  |       'angular2/test/render/xhr_impl_spec.ts', | 
					
						
							| 
									
										
										
										
											2015-05-30 11:56:38 -07:00
										 |  |  |       'angular2/test/forms/**' | 
					
						
							| 
									
										
										
										
											2015-04-13 23:56:07 -07:00
										 |  |  |     ] | 
					
						
							| 
									
										
										
										
											2015-04-13 16:39:47 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-16 11:36:23 -07:00
										 |  |  |   var typescriptTree = compileWithTypescript(modulesTree, { | 
					
						
							|  |  |  |     allowNonTsExtensions: false, | 
					
						
							|  |  |  |     emitDecoratorMetadata: true, | 
					
						
							| 
									
										
										
										
											2015-07-29 20:09:54 -07:00
										 |  |  |     experimentalDecorators: true, | 
					
						
							| 
									
										
										
										
											2015-08-11 16:33:03 -07:00
										 |  |  |     declaration: false, | 
					
						
							| 
									
										
										
										
											2015-07-16 11:36:23 -07:00
										 |  |  |     mapRoot: '', /* force sourcemaps to use relative path */ | 
					
						
							|  |  |  |     module: 'commonjs', | 
					
						
							|  |  |  |     noEmitOnError: true, | 
					
						
							|  |  |  |     rootDir: '.', | 
					
						
							|  |  |  |     rootFilePaths: ['angular2/traceur-runtime.d.ts', 'angular2/globals.d.ts'], | 
					
						
							|  |  |  |     sourceMap: true, | 
					
						
							|  |  |  |     sourceRoot: '.', | 
					
						
							|  |  |  |     target: 'ES5' | 
					
						
							| 
									
										
										
										
											2015-04-13 16:39:47 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Now we add the LICENSE file into all the folders that will become npm packages
 | 
					
						
							|  |  |  |   outputPackages.forEach(function(destDir) { | 
					
						
							|  |  |  |     var license = new Funnel('.', {files: ['LICENSE'], destDir: destDir}); | 
					
						
							| 
									
										
										
										
											2015-07-16 11:36:23 -07:00
										 |  |  |     typescriptTree = mergeTrees([typescriptTree, license]); | 
					
						
							| 
									
										
										
										
											2015-04-13 16:39:47 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Get all docs and related assets and prepare them for js build
 | 
					
						
							|  |  |  |   var docs = new Funnel(modulesTree, {include: ['**/*.md', '**/*.png'], exclude: ['**/*.dart.md']}); | 
					
						
							|  |  |  |   docs = stew.rename(docs, 'README.js.md', 'README.md'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Generate shared package.json info
 | 
					
						
							|  |  |  |   var BASE_PACKAGE_JSON = require(path.join(projectRootDir, 'package.json')); | 
					
						
							|  |  |  |   var COMMON_PACKAGE_JSON = { | 
					
						
							|  |  |  |     version: BASE_PACKAGE_JSON.version, | 
					
						
							|  |  |  |     homepage: BASE_PACKAGE_JSON.homepage, | 
					
						
							|  |  |  |     bugs: BASE_PACKAGE_JSON.bugs, | 
					
						
							|  |  |  |     license: BASE_PACKAGE_JSON.license, | 
					
						
							| 
									
										
										
										
											2015-08-13 15:43:52 +02:00
										 |  |  |     repository: BASE_PACKAGE_JSON.repository, | 
					
						
							| 
									
										
										
										
											2015-04-13 16:39:47 -07:00
										 |  |  |     contributors: BASE_PACKAGE_JSON.contributors, | 
					
						
							|  |  |  |     dependencies: BASE_PACKAGE_JSON.dependencies, | 
					
						
							| 
									
										
										
										
											2015-06-29 10:29:30 -07:00
										 |  |  |     devDependencies: BASE_PACKAGE_JSON.devDependencies, | 
					
						
							|  |  |  |     defaultDevDependencies: { | 
					
						
							| 
									
										
										
										
											2015-04-13 16:39:47 -07:00
										 |  |  |       "yargs": BASE_PACKAGE_JSON.devDependencies['yargs'], | 
					
						
							|  |  |  |       "gulp-sourcemaps": BASE_PACKAGE_JSON.devDependencies['gulp-sourcemaps'], | 
					
						
							|  |  |  |       "gulp-traceur": BASE_PACKAGE_JSON.devDependencies['gulp-traceur'], | 
					
						
							|  |  |  |       "gulp": BASE_PACKAGE_JSON.devDependencies['gulp'], | 
					
						
							|  |  |  |       "gulp-rename": BASE_PACKAGE_JSON.devDependencies['gulp-rename'], | 
					
						
							|  |  |  |       "through2": BASE_PACKAGE_JSON.devDependencies['through2'] | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-09 13:35:58 -04:00
										 |  |  |   var packageJsons = new Funnel(modulesTree, {include: ['**/package.json']}); | 
					
						
							|  |  |  |   packageJsons = | 
					
						
							|  |  |  |       renderLodashTemplate(packageJsons, {context: {'packageJson': COMMON_PACKAGE_JSON}}); | 
					
						
							| 
									
										
										
										
											2015-04-13 16:39:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-16 11:36:23 -07:00
										 |  |  |   var nodeTree = mergeTrees([typescriptTree, docs, packageJsons]); | 
					
						
							| 
									
										
										
										
											2015-05-19 17:39:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-22 12:50:58 -07:00
										 |  |  |   // Transform all tests to make them runnable in node
 | 
					
						
							|  |  |  |   nodeTree = replace(nodeTree, { | 
					
						
							|  |  |  |     files: ['**/test/**/*_spec.js'], | 
					
						
							| 
									
										
										
										
											2015-06-03 13:42:57 -07:00
										 |  |  |     patterns: [ | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2015-06-08 11:05:32 -07:00
										 |  |  |         match: /$/, | 
					
						
							|  |  |  |         replacement: function(_, relativePath) { | 
					
						
							|  |  |  |           return "\r\n main(); \n\r" + | 
					
						
							|  |  |  |                  "var parse5Adapter = require('angular2/src/dom/parse5_adapter'); " + | 
					
						
							|  |  |  |                  "parse5Adapter.Parse5DomAdapter.makeCurrent();"; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-06-03 13:42:57 -07:00
										 |  |  |       } | 
					
						
							|  |  |  |     ] | 
					
						
							| 
									
										
										
										
											2015-05-22 12:50:58 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-19 18:02:35 -04:00
										 |  |  |   // Prepend 'use strict' directive to all JS files.
 | 
					
						
							|  |  |  |   // See https://github.com/Microsoft/TypeScript/issues/3576
 | 
					
						
							|  |  |  |   nodeTree = replace(nodeTree, { | 
					
						
							|  |  |  |     files: ['**/*.js'], | 
					
						
							|  |  |  |     patterns: [{match: /^/, replacement: function() { return `'use strict';` }}] | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-19 17:39:57 -07:00
										 |  |  |   return destCopy(nodeTree, destinationPath); | 
					
						
							|  |  |  | }; |