2015-04-13 19:39:47 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var Funnel = require('broccoli-funnel');
|
|
|
|
var htmlReplace = require('../html-replace');
|
2015-07-10 19:09:18 -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-06-09 01:08:13 -04:00
|
|
|
import {default as transpileWithTraceur, TRACEUR_RUNTIME_PATH} from '../traceur/index';
|
2015-05-04 11:19:25 -04:00
|
|
|
|
2015-04-26 03:31:53 -04:00
|
|
|
|
2015-04-26 04:04:28 -04:00
|
|
|
var projectRootDir = path.normalize(path.join(__dirname, '..', '..', '..', '..'));
|
2015-04-13 19:39:47 -04:00
|
|
|
|
|
|
|
|
2015-06-05 03:19:34 -04:00
|
|
|
const kServedPaths = [
|
|
|
|
// Relative (to /modules) paths to benchmark directories
|
|
|
|
'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',
|
|
|
|
'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
|
|
|
|
'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
|
|
|
|
'examples/src/benchpress',
|
2015-06-05 18:37:20 -04:00
|
|
|
'examples/src/model_driven_forms',
|
|
|
|
'examples/src/template_driven_forms',
|
2015-07-01 13:51:36 -04:00
|
|
|
'examples/src/person_management',
|
|
|
|
'examples/src/order_management',
|
2015-06-05 03:19:34 -04:00
|
|
|
'examples/src/gestures',
|
|
|
|
'examples/src/hello_world',
|
2015-04-29 02:07:55 -04:00
|
|
|
'examples/src/http',
|
2015-07-14 20:53:04 -04:00
|
|
|
'examples/src/jsonp',
|
2015-06-05 03:19:34 -04:00
|
|
|
'examples/src/key_events',
|
2015-07-09 13:25:58 -04:00
|
|
|
'examples/src/routing',
|
2015-06-05 03:19:34 -04:00
|
|
|
'examples/src/sourcemap',
|
|
|
|
'examples/src/todo',
|
2015-06-22 04:52:00 -04:00
|
|
|
'examples/src/zippy_component',
|
2015-07-24 15:46:12 -04:00
|
|
|
'examples/src/async',
|
2015-06-05 03:19:34 -04:00
|
|
|
'examples/src/material/button',
|
|
|
|
'examples/src/material/checkbox',
|
|
|
|
'examples/src/material/dialog',
|
|
|
|
'examples/src/material/grid_list',
|
|
|
|
'examples/src/material/input',
|
|
|
|
'examples/src/material/progress-linear',
|
|
|
|
'examples/src/material/radio',
|
2015-07-10 19:09:18 -04:00
|
|
|
'examples/src/material/switcher',
|
2015-07-10 19:09:18 -04:00
|
|
|
'examples/src/message_broker',
|
2015-07-28 19:38:55 -04:00
|
|
|
'examples/src/web_workers/kitchen_sink',
|
2015-07-31 13:33:22 -04:00
|
|
|
'examples/src/web_workers/todo',
|
|
|
|
'examples/src/web_workers/images'
|
2015-06-05 03:19:34 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
|
2015-04-26 03:31:53 -04:00
|
|
|
module.exports = function makeBrowserTree(options, destinationPath) {
|
2015-08-06 12:52:33 -04:00
|
|
|
var modulesTree = new Funnel('modules', {
|
|
|
|
include: ['**/**'],
|
|
|
|
exclude: [
|
|
|
|
'**/*.cjs',
|
|
|
|
'benchmarks/e2e_test/**',
|
2015-08-20 16:19:34 -04:00
|
|
|
'angular1_router/**',
|
2015-08-06 12:52:33 -04:00
|
|
|
// Exclude ES6 polyfill typings when tsc target=ES6
|
|
|
|
'angular2/traceur-runtime.d.ts',
|
|
|
|
'angular2/typings/es6-promise/**'
|
|
|
|
],
|
|
|
|
destDir: '/'
|
|
|
|
});
|
2015-04-13 19:39:47 -04:00
|
|
|
|
2015-07-10 19:09:18 -04:00
|
|
|
var scriptPathPatternReplacement = {
|
|
|
|
match: '@@FILENAME_NO_EXT',
|
|
|
|
replacement: function(replacement, relativePath) {
|
|
|
|
return relativePath.replace(/\.\w+$/, '').replace(/\\/g, '/');
|
2015-05-04 11:19:25 -04:00
|
|
|
}
|
2015-07-10 19:09:18 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
modulesTree = replace(modulesTree, {
|
|
|
|
files: ["examples*/**/*.js"],
|
|
|
|
patterns: [{match: /\$SCRIPTS\$/, replacement: jsReplace('SCRIPTS')}]
|
2015-04-13 19:39:47 -04:00
|
|
|
});
|
|
|
|
|
2015-04-27 19:11:20 -04:00
|
|
|
// Use TypeScript to transpile the *.ts files to ES6
|
2015-07-10 19:09:18 -04:00
|
|
|
var es6Tree = compileWithTypescript(modulesTree, {
|
2015-04-27 19:11:20 -04:00
|
|
|
allowNonTsExtensions: false,
|
2015-08-11 19:33:03 -04:00
|
|
|
declaration: false,
|
2015-04-27 19:11:20 -04:00
|
|
|
emitDecoratorMetadata: true,
|
2015-08-06 12:52:33 -04:00
|
|
|
mapRoot: '', // force sourcemaps to use relative path
|
2015-08-07 14:41:38 -04:00
|
|
|
noEmitOnError: false,
|
2015-05-04 11:27:14 -04:00
|
|
|
rootDir: '.',
|
|
|
|
sourceMap: true,
|
|
|
|
sourceRoot: '.',
|
|
|
|
target: 'ES6'
|
2015-04-27 19:11:20 -04:00
|
|
|
});
|
|
|
|
|
2015-08-06 12:52:33 -04:00
|
|
|
// Call Traceur to lower the ES6 build tree to ES5
|
2015-05-04 11:19:25 -04:00
|
|
|
var es5Tree = transpileWithTraceur(es6Tree, {
|
|
|
|
destExtension: '.js',
|
|
|
|
destSourceMapExtension: '.js.map',
|
|
|
|
traceurOptions: {modules: 'instantiate', sourceMaps: true}
|
|
|
|
});
|
2015-04-13 19:39:47 -04:00
|
|
|
|
|
|
|
// Now we add a few more files to the es6 tree that Traceur should not see
|
|
|
|
['angular2', 'rtts_assert'].forEach(function(destDir) {
|
|
|
|
var extras = new Funnel('tools/build', {files: ['es5build.js'], destDir: destDir});
|
|
|
|
es6Tree = mergeTrees([es6Tree, extras]);
|
|
|
|
});
|
|
|
|
|
|
|
|
var vendorScriptsTree = flatten(new Funnel('.', {
|
|
|
|
files: [
|
2015-05-12 03:47:17 -04:00
|
|
|
'node_modules/zone.js/dist/zone-microtask.js',
|
|
|
|
'node_modules/zone.js/dist/long-stack-trace-zone.js',
|
2015-04-13 19:39:47 -04:00
|
|
|
'node_modules/systemjs/dist/system.src.js',
|
2015-04-27 19:11:20 -04:00
|
|
|
'node_modules/rx/dist/rx.js',
|
2015-07-31 13:33:22 -04:00
|
|
|
'node_modules/base64-js/lib/b64.js',
|
2015-04-28 21:17:00 -04:00
|
|
|
'node_modules/reflect-metadata/Reflect.js',
|
2015-05-04 11:19:25 -04:00
|
|
|
path.relative(projectRootDir, TRACEUR_RUNTIME_PATH)
|
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, []);
|
|
|
|
function getServedFunnels(funnels, destDir) {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
var htmlTree = new Funnel(modulesTree, {include: ['*/src/**/*.html'], destDir: '/'});
|
|
|
|
htmlTree = replace(htmlTree, {
|
2015-07-10 19:09:18 -04:00
|
|
|
files: ['examples*/**/*.html'],
|
2015-06-08 14:05:32 -04:00
|
|
|
patterns: [
|
|
|
|
{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS')},
|
|
|
|
scriptPathPatternReplacement
|
|
|
|
]
|
2015-04-13 19:39:47 -04:00
|
|
|
});
|
2015-06-08 14:05:32 -04:00
|
|
|
|
2015-07-10 19:09:18 -04:00
|
|
|
|
2015-04-13 19:39:47 -04:00
|
|
|
htmlTree = replace(htmlTree, {
|
|
|
|
files: ['benchmarks/**'],
|
2015-06-08 14:05:32 -04:00
|
|
|
patterns: [
|
|
|
|
{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks')},
|
|
|
|
scriptPathPatternReplacement
|
|
|
|
]
|
2015-04-13 19:39:47 -04:00
|
|
|
});
|
2015-06-08 14:05:32 -04:00
|
|
|
|
2015-04-13 19:39:47 -04:00
|
|
|
htmlTree = replace(htmlTree, {
|
|
|
|
files: ['benchmarks_external/**'],
|
2015-06-08 14:05:32 -04:00
|
|
|
patterns: [
|
|
|
|
{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks_external')},
|
|
|
|
scriptPathPatternReplacement
|
|
|
|
]
|
2015-04-13 19:39:47 -04:00
|
|
|
});
|
|
|
|
|
2015-06-10 19:52:19 -04:00
|
|
|
var assetsTree =
|
|
|
|
new Funnel(modulesTree, {include: ['**/*'], exclude: ['**/*.{html,ts,dart}'], destDir: '/'});
|
2015-06-10 19:51:46 -04:00
|
|
|
|
2015-06-05 03:19:34 -04:00
|
|
|
var scripts = mergeTrees(servingTrees);
|
2015-04-13 19:39:47 -04:00
|
|
|
var polymerFiles = new Funnel('.', {
|
|
|
|
files: [
|
|
|
|
'bower_components/polymer/lib/polymer.html',
|
|
|
|
'tools/build/snippets/url_params_to_form.js'
|
|
|
|
]
|
|
|
|
});
|
|
|
|
var polymer = stew.mv(flatten(polymerFiles), 'benchmarks_external/src/tree/polymer');
|
2015-04-29 21:11:56 -04: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-06-10 19:51:46 -04:00
|
|
|
htmlTree = mergeTrees([htmlTree, scripts, polymer, react]);
|
2015-04-13 19:39:47 -04:00
|
|
|
|
2015-06-10 19:51:46 -04:00
|
|
|
es5Tree = mergeTrees([es5Tree, htmlTree, assetsTree]);
|
2015-07-09 18:34:33 -04:00
|
|
|
es6Tree = mergeTrees([es6Tree, htmlTree, assetsTree]);
|
2015-04-13 19:39:47 -04:00
|
|
|
|
2015-04-26 03:31:53 -04:00
|
|
|
var mergedTree = mergeTrees([stew.mv(es6Tree, '/es6'), stew.mv(es5Tree, '/es5')]);
|
|
|
|
|
|
|
|
return destCopy(mergedTree, destinationPath);
|
2015-04-13 19:39:47 -04:00
|
|
|
};
|