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-10-13 03:29:13 -04:00
|
|
|
'angular2/test/testing/fake_async_spec.ts',
|
|
|
|
'angular2/test/testing/testing_public_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, {
|
|
|
|
emitDecoratorMetadata: true,
|
2015-07-29 23:09:54 -04:00
|
|
|
experimentalDecorators: true,
|
2015-10-13 17:35:31 -04:00
|
|
|
declaration: true,
|
|
|
|
stripInternal: true,
|
2015-07-16 14:36:23 -04:00
|
|
|
mapRoot: '', /* force sourcemaps to use relative path */
|
2015-10-15 19:29:24 -04:00
|
|
|
module: 'commonjs',
|
|
|
|
moduleResolution: 'classic',
|
2015-07-16 14:36:23 -04:00
|
|
|
noEmitOnError: true,
|
|
|
|
rootDir: '.',
|
2015-10-09 20:21:25 -04:00
|
|
|
rootFilePaths:
|
|
|
|
['angular2/manual_typings/globals.d.ts', 'angular2/typings/es6-shim/es6-shim.d.ts'],
|
2015-07-16 14:36:23 -04:00
|
|
|
sourceMap: true,
|
|
|
|
sourceRoot: '.',
|
2015-10-15 19:29:24 -04:00
|
|
|
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-10-13 17:35:31 -04:00
|
|
|
var typingsTree = new Funnel(
|
|
|
|
'modules',
|
|
|
|
{include: ['angular2/typings/**/*.d.ts', 'angular2/manual_typings/*.d.ts'], destDir: '/'});
|
|
|
|
var nodeTree = mergeTrees([typescriptTree, docs, packageJsons, typingsTree]);
|
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: /^/,
|
2015-10-26 20:23:01 -04:00
|
|
|
replacement:
|
|
|
|
() => `var parse5Adapter = require('angular2/src/core/dom/parse5_adapter');\r\n` +
|
|
|
|
`parse5Adapter.Parse5DomAdapter.makeCurrent();`
|
2015-08-20 17:28:25 -04:00
|
|
|
},
|
2015-10-26 20:23:01 -04:00
|
|
|
{match: /$/, replacement: (_, relativePath) => "\r\n main(); \r\n"}
|
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
|
2015-10-26 20:23:01 -04:00
|
|
|
nodeTree = replace(
|
|
|
|
nodeTree, {files: ['**/*.js'], patterns: [{match: /^/, replacement: () => `'use strict';`}]});
|
2015-06-19 18:02:35 -04:00
|
|
|
|
2015-10-13 17:35:31 -04:00
|
|
|
// Add a line to the end of our top-level .d.ts file.
|
|
|
|
// This HACK for transitive typings is a workaround for
|
|
|
|
// https://github.com/Microsoft/TypeScript/issues/5097
|
|
|
|
//
|
2015-10-26 20:23:01 -04:00
|
|
|
// This allows users to get our top-level dependencies like zone.d.ts
|
2015-10-13 17:35:31 -04:00
|
|
|
// to appear when they compile against angular2.
|
|
|
|
//
|
|
|
|
// This carries the risk that the user brings their own copy of that file
|
|
|
|
// (or any other symbols exported here) and they will get a compiler error
|
|
|
|
// because of the duplicate definitions.
|
|
|
|
// TODO(alexeagle): remove this when typescript releases a fix
|
|
|
|
nodeTree = replace(nodeTree, {
|
|
|
|
files: ['angular2/angular2.d.ts'],
|
2015-10-26 20:23:01 -04:00
|
|
|
patterns: [{match: /$/, replacement: 'import "./manual_typings/globals-es6.d.ts";\r\n'}]
|
2015-10-13 17:35:31 -04:00
|
|
|
});
|
|
|
|
|
2015-05-19 20:39:57 -04:00
|
|
|
return destCopy(nodeTree, destinationPath);
|
|
|
|
};
|