2015-04-13 19:39:47 -04:00
|
|
|
'use strict';
|
|
|
|
|
2015-05-04 11:19:25 -04:00
|
|
|
import destCopy from '../broccoli-dest-copy';
|
2015-05-27 21:26:54 -04:00
|
|
|
import compileWithTypescript from '../broccoli-typescript';
|
2015-04-13 19:39:47 -04:00
|
|
|
var Funnel = require('broccoli-funnel');
|
2015-05-21 12:07:52 -04:00
|
|
|
import mergeTrees from '../broccoli-merge-trees';
|
2015-04-13 19:39:47 -04:00
|
|
|
var path = require('path');
|
2015-06-09 13:35:58 -04:00
|
|
|
import renderLodashTemplate from '../broccoli-lodash';
|
2015-06-08 14:05:32 -04:00
|
|
|
import replace from '../broccoli-replace';
|
2015-04-13 19:39:47 -04:00
|
|
|
var stew = require('broccoli-stew');
|
|
|
|
|
2015-04-26 04:04:28 -04:00
|
|
|
var projectRootDir = path.normalize(path.join(__dirname, '..', '..', '..', '..'));
|
2015-04-13 19:39:47 -04:00
|
|
|
|
|
|
|
|
2015-04-26 03:31:53 -04:00
|
|
|
module.exports = function makeNodeTree(destinationPath) {
|
2015-04-13 19:39:47 -04:00
|
|
|
// list of npm packages that this build will create
|
2015-09-09 22:00:22 -04:00
|
|
|
var outputPackages = ['angular2', 'benchpress'];
|
2015-04-13 19:39:47 -04:00
|
|
|
|
|
|
|
var modulesTree = new Funnel('modules', {
|
2015-09-09 22:00:22 -04:00
|
|
|
include: ['angular2/**', 'benchpress/**', '**/e2e_test/**'],
|
2015-04-14 02:56:07 -04:00
|
|
|
exclude: [
|
2015-04-26 21:04:45 -04:00
|
|
|
// the following code and tests are not compatible with CJS/node environment
|
2015-08-28 17:39:34 -04:00
|
|
|
'angular2/test/animate/**',
|
2015-05-12 10:28:57 -04:00
|
|
|
'angular2/test/core/zone/**',
|
2015-05-27 12:53:37 -04:00
|
|
|
'angular2/test/test_lib/fake_async_spec.ts',
|
2015-10-02 12:30:36 -04:00
|
|
|
'angular2/test/core/compiler/xhr_impl_spec.ts',
|
2015-09-04 01:01:36 -04:00
|
|
|
'angular2/test/core/forms/**',
|
2015-09-04 17:44:24 -04:00
|
|
|
'angular2/test/tools/tools_spec.ts',
|
2015-10-05 19:28:53 -04:00
|
|
|
'angular1_router/**',
|
|
|
|
'angular2/examples/**/!(*_spec.ts)',
|
2015-04-14 02:56:07 -04:00
|
|
|
]
|
2015-04-13 19:39:47 -04:00
|
|
|
});
|
|
|
|
|
2015-07-16 14:36:23 -04:00
|
|
|
var typescriptTree = compileWithTypescript(modulesTree, {
|
|
|
|
allowNonTsExtensions: false,
|
|
|
|
emitDecoratorMetadata: true,
|
2015-07-29 23:09:54 -04:00
|
|
|
experimentalDecorators: true,
|
2015-08-11 19:33:03 -04:00
|
|
|
declaration: false,
|
2015-07-16 14:36:23 -04:00
|
|
|
mapRoot: '', /* force sourcemaps to use relative path */
|
2015-08-17 16:44:31 -04:00
|
|
|
module: 'CommonJS',
|
2015-09-23 18:02:37 -04:00
|
|
|
moduleResolution: 1 /* classic */,
|
2015-07-16 14:36:23 -04:00
|
|
|
noEmitOnError: true,
|
|
|
|
rootDir: '.',
|
2015-09-29 14:11:06 -04:00
|
|
|
rootFilePaths: ['angular2/manual_typings/globals.d.ts'],
|
2015-07-16 14:36:23 -04:00
|
|
|
sourceMap: true,
|
|
|
|
sourceRoot: '.',
|
|
|
|
target: 'ES5'
|
2015-04-13 19:39:47 -04: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 14:36:23 -04:00
|
|
|
typescriptTree = mergeTrees([typescriptTree, license]);
|
2015-04-13 19:39:47 -04: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 09:43:52 -04:00
|
|
|
repository: BASE_PACKAGE_JSON.repository,
|
2015-04-13 19:39:47 -04:00
|
|
|
contributors: BASE_PACKAGE_JSON.contributors,
|
|
|
|
dependencies: BASE_PACKAGE_JSON.dependencies,
|
2015-06-29 13:29:30 -04:00
|
|
|
devDependencies: BASE_PACKAGE_JSON.devDependencies,
|
2015-10-03 12:48:44 -04:00
|
|
|
defaultDevDependencies: {}
|
2015-04-13 19:39:47 -04:00
|
|
|
};
|
|
|
|
|
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 19:39:47 -04:00
|
|
|
|
2015-07-16 14:36:23 -04:00
|
|
|
var nodeTree = mergeTrees([typescriptTree, docs, packageJsons]);
|
2015-05-19 20:39:57 -04:00
|
|
|
|
2015-05-22 15:50:58 -04:00
|
|
|
// Transform all tests to make them runnable in node
|
|
|
|
nodeTree = replace(nodeTree, {
|
|
|
|
files: ['**/test/**/*_spec.js'],
|
2015-06-03 16:42:57 -04:00
|
|
|
patterns: [
|
|
|
|
{
|
2015-08-20 17:28:25 -04:00
|
|
|
match: /^/,
|
|
|
|
replacement: function() {
|
|
|
|
return `var parse5Adapter = require('angular2/src/core/dom/parse5_adapter');\n\r
|
2015-09-23 18:02:37 -04:00
|
|
|
parse5Adapter.Parse5DomAdapter.makeCurrent();`;
|
2015-06-08 14:05:32 -04:00
|
|
|
}
|
2015-08-20 17:28:25 -04:00
|
|
|
},
|
|
|
|
{match: /$/, replacement: function(_, relativePath) { return "\r\n main(); \n\r"; }}
|
2015-06-03 16:42:57 -04:00
|
|
|
]
|
2015-05-22 15:50:58 -04: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 20:39:57 -04:00
|
|
|
return destCopy(nodeTree, destinationPath);
|
|
|
|
};
|