2015-04-13 19:39:47 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var Funnel = require('broccoli-funnel');
|
|
|
|
var htmlReplace = require('../html-replace');
|
2015-09-02 23:58:02 -04:00
|
|
|
var jsReplace = require('../js-replace');
|
2015-04-13 19:39:47 -04:00
|
|
|
var path = require('path');
|
|
|
|
var stew = require('broccoli-stew');
|
|
|
|
|
2015-05-04 11:27:14 -04:00
|
|
|
import compileWithTypescript from '../broccoli-typescript';
|
2015-05-04 11:19:25 -04:00
|
|
|
import destCopy from '../broccoli-dest-copy';
|
2015-06-09 01:08:13 -04:00
|
|
|
import flatten from '../broccoli-flatten';
|
|
|
|
import mergeTrees from '../broccoli-merge-trees';
|
2015-06-08 14:05:32 -04:00
|
|
|
import replace from '../broccoli-replace';
|
2015-11-17 18:24:36 -05:00
|
|
|
import checkImports from '../broccoli-check-imports';
|
2015-05-04 11:19:25 -04:00
|
|
|
|
2015-04-26 03:31:53 -04:00
|
|
|
|
2015-06-05 03:19:34 -04:00
|
|
|
const kServedPaths = [
|
|
|
|
// Relative (to /modules) paths to benchmark directories
|
2016-04-12 12:40:37 -04:00
|
|
|
'benchmarks/src',
|
|
|
|
'benchmarks/src/change_detection',
|
|
|
|
'benchmarks/src/compiler',
|
|
|
|
'benchmarks/src/costs',
|
|
|
|
'benchmarks/src/di',
|
|
|
|
'benchmarks/src/element_injector',
|
|
|
|
'benchmarks/src/largetable',
|
|
|
|
'benchmarks/src/naive_infinite_scroll',
|
2016-04-20 20:01:51 -04:00
|
|
|
'benchmarks/src/page_load',
|
2016-04-12 12:40:37 -04:00
|
|
|
'benchmarks/src/tree',
|
2015-07-21 18:28:10 -04:00
|
|
|
'benchmarks/src/static_tree',
|
2015-06-05 03:19:34 -04:00
|
|
|
|
|
|
|
// Relative (to /modules) paths to external benchmark directories
|
2016-04-12 12:40:37 -04:00
|
|
|
'benchmarks_external/src',
|
|
|
|
'benchmarks_external/src/compiler',
|
|
|
|
'benchmarks_external/src/largetable',
|
|
|
|
'benchmarks_external/src/naive_infinite_scroll',
|
|
|
|
'benchmarks_external/src/tree',
|
|
|
|
'benchmarks_external/src/tree/react',
|
2015-07-21 18:28:10 -04:00
|
|
|
'benchmarks_external/src/static_tree',
|
2015-06-05 03:19:34 -04:00
|
|
|
|
|
|
|
// Relative (to /modules) paths to example directories
|
2016-04-12 12:40:37 -04:00
|
|
|
'playground/src/animate',
|
|
|
|
'playground/src/benchpress',
|
|
|
|
'playground/src/model_driven_forms',
|
|
|
|
'playground/src/template_driven_forms',
|
|
|
|
'playground/src/person_management',
|
|
|
|
'playground/src/order_management',
|
|
|
|
'playground/src/gestures',
|
|
|
|
'playground/src/hash_routing',
|
|
|
|
'playground/src/hello_world',
|
|
|
|
'playground/src/http',
|
|
|
|
'playground/src/jsonp',
|
|
|
|
'playground/src/key_events',
|
|
|
|
'playground/src/relative_assets',
|
|
|
|
'playground/src/routing',
|
|
|
|
'playground/src/sourcemap',
|
|
|
|
'playground/src/svg',
|
|
|
|
'playground/src/todo',
|
|
|
|
'playground/src/upgrade',
|
|
|
|
'playground/src/zippy_component',
|
|
|
|
'playground/src/async',
|
|
|
|
'playground/src/web_workers/kitchen_sink',
|
|
|
|
'playground/src/web_workers/todo',
|
|
|
|
'playground/src/web_workers/images',
|
|
|
|
'playground/src/web_workers/message_broker',
|
2016-03-30 13:15:04 -04:00
|
|
|
'playground/src/web_workers/router',
|
2016-05-26 13:45:37 -04:00
|
|
|
'playground/src/web_workers/input',
|
2015-06-05 03:19:34 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
|
2016-01-22 13:51:16 -05:00
|
|
|
module.exports = function makeBrowserTree(options: any, destinationPath: string) {
|
|
|
|
// TODO: define an interface for the options
|
2015-11-16 19:18:59 -05:00
|
|
|
const modules = options.projects;
|
|
|
|
const noTypeChecks = options.noTypeChecks;
|
|
|
|
const generateEs6 = options.generateEs6;
|
2015-11-23 17:58:18 -05:00
|
|
|
const sourceMaps = options.sourceMaps;
|
2015-12-29 20:01:10 -05:00
|
|
|
const useBundles = options.useBundles;
|
2015-11-13 04:58:17 -05:00
|
|
|
|
|
|
|
if (modules.angular2) {
|
|
|
|
var angular2Tree = new Funnel('modules/angular2', {
|
|
|
|
include: ['**/**'],
|
|
|
|
exclude: [
|
|
|
|
// Exclude ES6 polyfill typings when tsc target=ES6
|
|
|
|
'typings/es6-*/**',
|
|
|
|
],
|
|
|
|
destDir: '/angular2/'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (modules.benchmarks) {
|
2016-05-26 13:45:37 -04:00
|
|
|
var benchmarksTree = new Funnel(
|
|
|
|
'modules/benchmarks',
|
|
|
|
{include: ['**/**'], exclude: ['e2e_test/**'], destDir: '/benchmarks/'});
|
2015-11-13 04:58:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (modules.benchmarks_external) {
|
|
|
|
var benchmarksExternalTree = new Funnel(
|
|
|
|
'modules/benchmarks_external',
|
|
|
|
{include: ['**/**'], exclude: ['e2e_test/**'], destDir: '/benchmarks_external/'});
|
|
|
|
}
|
|
|
|
|
2016-01-08 11:51:02 -05:00
|
|
|
if (modules.payload_tests) {
|
2016-05-26 13:45:37 -04:00
|
|
|
var payloadTestsTree = new Funnel(
|
|
|
|
'modules/payload_tests',
|
|
|
|
{include: ['**/ts/**'], exclude: ['e2e_test/**'], destDir: '/payload_tests/'});
|
2016-01-08 11:51:02 -05:00
|
|
|
}
|
|
|
|
|
2015-11-13 04:58:17 -05:00
|
|
|
if (modules.playground) {
|
2016-05-26 13:45:37 -04:00
|
|
|
var playgroundTree = new Funnel(
|
|
|
|
'modules/playground',
|
|
|
|
{include: ['**/**'], exclude: ['e2e_test/**'], destDir: '/playground/'});
|
2015-11-13 04:58:17 -05:00
|
|
|
}
|
|
|
|
|
2015-12-01 15:42:22 -05:00
|
|
|
if (modules.benchpress) {
|
2016-05-26 13:45:37 -04:00
|
|
|
var benchpressTree = new Funnel(
|
|
|
|
'modules/benchpress',
|
|
|
|
{include: ['**/**'], exclude: ['e2e_test/**'], destDir: '/benchpress/'});
|
2015-12-01 15:42:22 -05:00
|
|
|
}
|
|
|
|
|
2016-04-06 19:10:45 -04:00
|
|
|
let externalTypings =
|
|
|
|
new Funnel('node_modules', {include: ['rxjs/**/*.d.ts', 'zone.js/**/*.d.ts']});
|
|
|
|
|
|
|
|
|
2015-12-01 16:44:41 -05:00
|
|
|
var modulesTree = mergeTrees([
|
|
|
|
angular2Tree,
|
|
|
|
benchmarksTree,
|
|
|
|
benchmarksExternalTree,
|
2016-01-08 11:51:02 -05:00
|
|
|
payloadTestsTree,
|
2015-12-01 16:44:41 -05:00
|
|
|
playgroundTree,
|
2016-04-06 19:10:45 -04:00
|
|
|
benchpressTree,
|
|
|
|
externalTypings,
|
2015-12-01 16:44:41 -05:00
|
|
|
]);
|
2015-09-02 23:58:02 -04:00
|
|
|
|
2015-11-13 04:58:17 -05:00
|
|
|
var es6PolyfillTypings =
|
|
|
|
new Funnel('modules', {include: ['angular2/typings/es6-*/**'], destDir: '/'});
|
|
|
|
|
|
|
|
var es5ModulesTree = mergeTrees([modulesTree, es6PolyfillTypings]);
|
|
|
|
|
2015-07-10 19:09:18 -04:00
|
|
|
var scriptPathPatternReplacement = {
|
2015-10-06 19:35:40 -04:00
|
|
|
match: '@@PATH',
|
2016-01-22 13:51:16 -05:00
|
|
|
replacement: function(replacement: string, relativePath: string) {
|
2015-10-06 19:35:40 -04:00
|
|
|
var parts = relativePath.replace(/\\/g, '/').split('/');
|
|
|
|
return parts.splice(0, parts.length - 1).join('/');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var scriptFilePatternReplacement = {
|
|
|
|
match: '@@FILENAME',
|
2016-01-22 13:51:16 -05:00
|
|
|
replacement: function(replacement: string, relativePath: string) {
|
2015-10-06 19:35:40 -04:00
|
|
|
var parts = relativePath.replace(/\\/g, '/').split('/');
|
|
|
|
return parts[parts.length - 1].replace('html', 'js');
|
2015-05-04 11:19:25 -04:00
|
|
|
}
|
2015-07-10 19:09:18 -04:00
|
|
|
};
|
|
|
|
|
2015-12-29 20:01:10 -05:00
|
|
|
var useBundlesPatternReplacement = {
|
|
|
|
match: '@@USE_BUNDLES',
|
2016-01-22 13:51:16 -05:00
|
|
|
replacement: function(replacement: string, relativePath: string) { return useBundles; }
|
2015-12-29 20:01:10 -05:00
|
|
|
};
|
|
|
|
|
2015-11-17 18:24:36 -05:00
|
|
|
// Check that imports do not break barrel boundaries
|
|
|
|
modulesTree = checkImports(modulesTree);
|
|
|
|
|
2015-07-10 19:09:18 -04:00
|
|
|
modulesTree = replace(modulesTree, {
|
2016-05-26 13:45:37 -04:00
|
|
|
files: ['playground*/**/*.js'],
|
2015-07-10 19:09:18 -04:00
|
|
|
patterns: [{match: /\$SCRIPTS\$/, replacement: jsReplace('SCRIPTS')}]
|
2015-04-13 19:39:47 -04:00
|
|
|
});
|
|
|
|
|
2016-02-01 13:29:42 -05:00
|
|
|
let ambientTypings = [
|
2016-04-12 12:40:37 -04:00
|
|
|
'angular2/typings/hammerjs/hammerjs.d.ts',
|
|
|
|
'angular2/typings/node/node.d.ts',
|
|
|
|
'node_modules/zone.js/dist/zone.js.d.ts',
|
|
|
|
'angular2/manual_typings/globals.d.ts',
|
2016-02-01 13:29:42 -05:00
|
|
|
'angular2/typings/es6-collections/es6-collections.d.ts',
|
2016-05-26 13:45:37 -04:00
|
|
|
'angular2/typings/es6-promise/es6-promise.d.ts',
|
2016-02-01 13:29:42 -05:00
|
|
|
];
|
|
|
|
|
2015-08-17 16:44:31 -04:00
|
|
|
// Use TypeScript to transpile the *.ts files to ES5
|
2015-11-13 04:58:17 -05:00
|
|
|
var es5Tree = compileWithTypescript(es5ModulesTree, {
|
2015-10-26 20:23:01 -04:00
|
|
|
declaration: false,
|
2015-08-17 16:44:31 -04:00
|
|
|
emitDecoratorMetadata: true,
|
|
|
|
experimentalDecorators: true,
|
2015-10-15 19:29:24 -04:00
|
|
|
module: 'commonjs',
|
|
|
|
moduleResolution: 'classic',
|
2015-11-16 19:18:59 -05:00
|
|
|
noEmitOnError: !noTypeChecks,
|
2015-11-13 04:58:17 -05:00
|
|
|
rootDir: './',
|
2016-02-01 13:29:42 -05:00
|
|
|
rootFilePaths: ambientTypings,
|
2015-11-23 17:58:18 -05:00
|
|
|
inlineSourceMap: sourceMaps,
|
|
|
|
inlineSources: sourceMaps,
|
2015-10-15 19:29:24 -04:00
|
|
|
target: 'es5'
|
2015-11-13 04:58:17 -05:00
|
|
|
});
|
2015-04-13 19:39:47 -04:00
|
|
|
|
|
|
|
var vendorScriptsTree = flatten(new Funnel('.', {
|
|
|
|
files: [
|
2016-04-12 12:40:37 -04:00
|
|
|
'node_modules/es6-shim/es6-shim.js',
|
|
|
|
'node_modules/zone.js/dist/zone.js',
|
2015-05-12 03:47:17 -04:00
|
|
|
'node_modules/zone.js/dist/long-stack-trace-zone.js',
|
2016-04-12 12:40:37 -04:00
|
|
|
'node_modules/systemjs/dist/system.src.js',
|
|
|
|
'node_modules/base64-js/lib/b64.js',
|
2016-05-26 13:45:37 -04:00
|
|
|
'node_modules/reflect-metadata/Reflect.js',
|
2015-04-13 19:39:47 -04:00
|
|
|
]
|
|
|
|
}));
|
2015-06-05 03:19:34 -04:00
|
|
|
|
2015-04-13 19:39:47 -04:00
|
|
|
var vendorScripts_benchmark =
|
|
|
|
new Funnel('tools/build/snippets', {files: ['url_params_to_form.js'], destDir: '/'});
|
|
|
|
var vendorScripts_benchmarks_external =
|
|
|
|
new Funnel('node_modules/angular', {files: ['angular.js'], destDir: '/'});
|
|
|
|
|
2015-06-05 03:19:34 -04:00
|
|
|
// Get scripts for each benchmark or example
|
|
|
|
let servingTrees = kServedPaths.reduce(getServedFunnels, []);
|
2016-01-22 13:51:16 -05:00
|
|
|
function getServedFunnels(funnels: BroccoliTree[], destDir: string) {
|
2015-06-12 10:50:45 -04:00
|
|
|
let options = {srcDir: '/', destDir: destDir};
|
2015-06-05 03:19:34 -04:00
|
|
|
funnels.push(new Funnel(vendorScriptsTree, options));
|
2015-04-13 19:39:47 -04:00
|
|
|
if (destDir.indexOf('benchmarks') > -1) {
|
2015-06-05 03:19:34 -04:00
|
|
|
funnels.push(new Funnel(vendorScripts_benchmark, options));
|
2015-04-13 19:39:47 -04:00
|
|
|
}
|
|
|
|
if (destDir.indexOf('benchmarks_external') > -1) {
|
2015-06-05 03:19:34 -04:00
|
|
|
funnels.push(new Funnel(vendorScripts_benchmarks_external, options));
|
2015-04-13 19:39:47 -04:00
|
|
|
}
|
2015-06-05 03:19:34 -04:00
|
|
|
return funnels;
|
2015-04-13 19:39:47 -04:00
|
|
|
}
|
|
|
|
|
2015-11-13 04:58:17 -05:00
|
|
|
|
2016-03-16 14:11:20 -04:00
|
|
|
if (modules.benchmarks || modules.benchmarks_external || modules.playground) {
|
2015-11-13 04:58:17 -05:00
|
|
|
var assetsTree = new Funnel(
|
|
|
|
modulesTree, {include: ['**/*'], exclude: ['**/*.{html,ts,dart}'], destDir: '/'});
|
|
|
|
}
|
|
|
|
|
2016-01-08 11:51:02 -05:00
|
|
|
var htmlTree = new Funnel(modulesTree, {
|
|
|
|
include: ['*/src/**/*.html', '**/playground/**/*.html', '**/payload_tests/**/ts/**/*.html'],
|
|
|
|
destDir: '/'
|
|
|
|
});
|
2015-06-08 14:05:32 -04:00
|
|
|
|
2016-01-20 11:56:00 -05:00
|
|
|
if (modules.playground) {
|
2015-11-13 04:58:17 -05:00
|
|
|
htmlTree = replace(htmlTree, {
|
|
|
|
files: ['playground*/**/*.html'],
|
|
|
|
patterns: [
|
2016-05-26 13:45:37 -04:00
|
|
|
{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS')}, scriptPathPatternReplacement,
|
|
|
|
scriptFilePatternReplacement, useBundlesPatternReplacement
|
2015-11-13 04:58:17 -05:00
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
2015-07-10 19:09:18 -04:00
|
|
|
|
2015-11-13 04:58:17 -05:00
|
|
|
if (modules.benchmarks) {
|
|
|
|
htmlTree = replace(htmlTree, {
|
|
|
|
files: ['benchmarks/**'],
|
|
|
|
patterns: [
|
|
|
|
{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks')},
|
2016-05-26 13:45:37 -04:00
|
|
|
scriptPathPatternReplacement, scriptFilePatternReplacement, useBundlesPatternReplacement
|
2015-11-13 04:58:17 -05:00
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
2015-06-08 14:05:32 -04:00
|
|
|
|
2015-11-13 04:58:17 -05:00
|
|
|
if (modules.benchmarks_external) {
|
|
|
|
htmlTree = replace(htmlTree, {
|
|
|
|
files: ['benchmarks_external/**'],
|
|
|
|
patterns: [
|
|
|
|
{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks_external')},
|
2016-05-26 13:45:37 -04:00
|
|
|
scriptPathPatternReplacement, scriptFilePatternReplacement, useBundlesPatternReplacement
|
2015-11-13 04:58:17 -05:00
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
2015-04-13 19:39:47 -04:00
|
|
|
|
2015-11-13 04:58:17 -05:00
|
|
|
if (modules.playground) {
|
|
|
|
// We need to replace the regular angular bundle with the web-worker bundle
|
|
|
|
// for web-worker e2e tests.
|
|
|
|
htmlTree = replace(htmlTree, {
|
|
|
|
files: ['playground*/**/web_workers/**/*.html'],
|
2016-05-26 13:45:37 -04:00
|
|
|
patterns: [{match: '/bundle/angular2.dev.js', replacement: '/bundle/web_worker/ui.dev.js'}]
|
2015-11-13 04:58:17 -05:00
|
|
|
});
|
|
|
|
}
|
2015-10-06 19:35:40 -04:00
|
|
|
|
2015-11-13 04:58:17 -05:00
|
|
|
if (modules.benchmarks || modules.benchmarks_external) {
|
|
|
|
var scripts = mergeTrees(servingTrees);
|
|
|
|
}
|
2015-06-10 19:51:46 -04:00
|
|
|
|
2015-11-13 04:58:17 -05:00
|
|
|
if (modules.benchmarks_external) {
|
|
|
|
var polymerFiles = new Funnel('.', {
|
|
|
|
files: [
|
2016-04-12 12:40:37 -04:00
|
|
|
'bower_components/polymer/polymer.html',
|
|
|
|
'bower_components/polymer/polymer-micro.html',
|
|
|
|
'bower_components/polymer/polymer-mini.html',
|
2016-05-26 13:45:37 -04:00
|
|
|
'tools/build/snippets/url_params_to_form.js',
|
2015-11-13 04:58:17 -05:00
|
|
|
]
|
|
|
|
});
|
|
|
|
var polymer = stew.mv(flatten(polymerFiles), 'benchmarks_external/src/tree/polymer');
|
2015-04-29 21:11:56 -04:00
|
|
|
|
2015-11-13 04:58:17 -05:00
|
|
|
var reactFiles = new Funnel('.', {files: ['node_modules/react/dist/react.min.js']});
|
|
|
|
var react = stew.mv(flatten(reactFiles), 'benchmarks_external/src/tree/react');
|
|
|
|
}
|
2015-04-29 21:11:56 -04:00
|
|
|
|
2015-11-13 04:58:17 -05:00
|
|
|
if (modules.benchmarks || modules.benchmarks_external || modules.playground) {
|
|
|
|
htmlTree = mergeTrees([htmlTree, scripts, polymer, react]);
|
|
|
|
}
|
2015-04-13 19:39:47 -04:00
|
|
|
|
2015-11-16 19:18:59 -05:00
|
|
|
// this is needed only for creating a bundle
|
|
|
|
// typescript resolves dependencies automatically
|
|
|
|
if (modules.bundle_deps) {
|
|
|
|
var nodeModules = new Funnel(
|
2015-11-30 20:22:52 -05:00
|
|
|
'node_modules', {include: ['rxjs/**/**', 'parse5/**/**', 'css/**/**'], destDir: '/'});
|
2015-11-16 19:18:59 -05:00
|
|
|
}
|
2015-04-13 19:39:47 -04:00
|
|
|
|
2015-11-16 19:18:59 -05:00
|
|
|
if (generateEs6) {
|
|
|
|
// Use TypeScript to transpile the *.ts files to ES6
|
|
|
|
var es6Tree = compileWithTypescript(modulesTree, {
|
|
|
|
declaration: false,
|
|
|
|
emitDecoratorMetadata: true,
|
|
|
|
experimentalDecorators: true,
|
|
|
|
noEmitOnError: false,
|
|
|
|
rootDir: './',
|
2016-02-01 13:29:42 -05:00
|
|
|
rootFilePaths: [
|
|
|
|
'angular2/typings/zone.js/zone.js.d.ts',
|
|
|
|
'angular2/typings/hammerjs/hammerjs.d.ts',
|
|
|
|
'angular2/typings/node/node.d.ts',
|
|
|
|
],
|
2015-11-23 17:58:18 -05:00
|
|
|
inlineSourceMap: sourceMaps,
|
|
|
|
inlineSources: sourceMaps,
|
2015-11-16 19:18:59 -05:00
|
|
|
target: 'es6'
|
|
|
|
});
|
|
|
|
|
|
|
|
es6Tree = stew.mv(mergeTrees([es6Tree, htmlTree, assetsTree, nodeModules]), '/es6');
|
|
|
|
}
|
|
|
|
es5Tree = stew.mv(mergeTrees([es5Tree, htmlTree, assetsTree, nodeModules]), '/es5');
|
2015-04-26 03:31:53 -04:00
|
|
|
|
2015-11-16 19:18:59 -05:00
|
|
|
var mergedTree = mergeTrees([es6Tree, es5Tree]);
|
2015-04-26 03:31:53 -04:00
|
|
|
return destCopy(mergedTree, destinationPath);
|
2015-04-13 19:39:47 -04:00
|
|
|
};
|