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-08-20 17:28:25 -04:00
|
|
|
var outputPackages = ['angular2', 'benchpress', 'rtts_assert'];
|
2015-04-13 19:39:47 -04:00
|
|
|
|
|
|
|
var modulesTree = new Funnel('modules', {
|
2015-08-20 17:28:25 -04:00
|
|
|
include: ['angular2/**', 'benchpress/**', 'rtts_assert/**', '**/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-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-08-20 17:28:25 -04:00
|
|
|
'angular2/test/core/render/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-08-20 16:19:34 -04:00
|
|
|
'angular1_router/**'
|
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-07-16 14:36:23 -04:00
|
|
|
noEmitOnError: true,
|
|
|
|
rootDir: '.',
|
2015-09-04 01:01:36 -04:00
|
|
|
rootFilePaths:
|
|
|
|
['angular2/manual_typings/traceur-runtime.d.ts', '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,
|
|
|
|
defaultDevDependencies: {
|
2015-04-13 19:39:47 -04: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 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
|
|
|
|
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);
|
|
|
|
};
|