2015-04-13 19:39:47 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var Funnel = require('broccoli-funnel');
|
|
|
|
var flatten = require('broccoli-flatten');
|
|
|
|
var htmlReplace = require('../html-replace');
|
|
|
|
var mergeTrees = require('broccoli-merge-trees');
|
|
|
|
var path = require('path');
|
|
|
|
var replace = require('broccoli-replace');
|
|
|
|
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';
|
|
|
|
import {default as transpileWithTraceur, TRACEUR_RUNTIME_PATH} from '../traceur/index';
|
|
|
|
|
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-04-26 03:31:53 -04:00
|
|
|
module.exports = function makeBrowserTree(options, destinationPath) {
|
2015-04-13 19:39:47 -04:00
|
|
|
var modulesTree = new Funnel(
|
|
|
|
'modules',
|
|
|
|
{include: ['**/**'], exclude: ['**/*.cjs', 'benchmarks/e2e_test/**'], destDir: '/'});
|
|
|
|
|
2015-04-27 19:11:20 -04:00
|
|
|
// Use Traceur to transpile *.js sources to ES6
|
2015-05-04 11:19:25 -04:00
|
|
|
var traceurTree = transpileWithTraceur(modulesTree, {
|
|
|
|
destExtension: '.es6',
|
|
|
|
destSourceMapExtension: '.map',
|
|
|
|
traceurOptions: {
|
|
|
|
sourceMaps: true,
|
|
|
|
annotations: true, // parse annotations
|
|
|
|
types: true, // parse types
|
|
|
|
script: false, // parse as a module
|
|
|
|
memberVariables: true, // parse class fields
|
|
|
|
modules: 'instantiate',
|
|
|
|
// typeAssertionModule: 'rtts_assert/rtts_assert',
|
|
|
|
// typeAssertions: options.typeAssertions,
|
|
|
|
outputLanguage: 'es6'
|
|
|
|
}
|
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
|
|
|
|
// We don't care about errors: we let the TypeScript compilation to ES5
|
|
|
|
// in node_tree.ts do the type-checking.
|
2015-05-04 11:27:14 -04:00
|
|
|
var typescriptTree = compileWithTypescript(modulesTree, {
|
2015-04-27 19:11:20 -04:00
|
|
|
allowNonTsExtensions: false,
|
2015-05-04 11:27:14 -04:00
|
|
|
declaration: true,
|
2015-04-27 19:11:20 -04:00
|
|
|
emitDecoratorMetadata: true,
|
2015-05-04 11:27:14 -04:00
|
|
|
mapRoot: '', // force sourcemaps to use relative path
|
|
|
|
noEmitOnError: false, // temporarily ignore errors, we type-check only via cjs build
|
|
|
|
rootDir: '.',
|
|
|
|
sourceMap: true,
|
|
|
|
sourceRoot: '.',
|
|
|
|
target: 'ES6'
|
2015-04-27 19:11:20 -04:00
|
|
|
});
|
|
|
|
typescriptTree = stew.rename(typescriptTree, '.js', '.es6');
|
|
|
|
|
|
|
|
var es6Tree = mergeTrees([traceurTree, typescriptTree]);
|
2015-04-13 19:39:47 -04:00
|
|
|
|
|
|
|
// Call Traceur again 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/es6-module-loader/dist/es6-module-loader-sans-promises.src.js',
|
|
|
|
'node_modules/systemjs/dist/system.src.js',
|
|
|
|
'node_modules/systemjs/lib/extension-register.js',
|
|
|
|
'node_modules/systemjs/lib/extension-cjs.js',
|
2015-04-27 19:11:20 -04:00
|
|
|
'node_modules/rx/dist/rx.js',
|
2015-04-28 21:17:00 -04:00
|
|
|
'node_modules/reflect-metadata/Reflect.js',
|
2015-04-13 19:39:47 -04:00
|
|
|
'tools/build/snippets/runtime_paths.js',
|
2015-05-04 11:19:25 -04:00
|
|
|
path.relative(projectRootDir, TRACEUR_RUNTIME_PATH)
|
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: '/'});
|
|
|
|
|
|
|
|
var servingTrees = [];
|
|
|
|
|
|
|
|
function copyVendorScriptsTo(destDir) {
|
|
|
|
servingTrees.push(new Funnel(vendorScriptsTree, {srcDir: '/', destDir: destDir}));
|
|
|
|
if (destDir.indexOf('benchmarks') > -1) {
|
|
|
|
servingTrees.push(new Funnel(vendorScripts_benchmark, {srcDir: '/', destDir: destDir}));
|
|
|
|
}
|
|
|
|
if (destDir.indexOf('benchmarks_external') > -1) {
|
|
|
|
servingTrees.push(
|
|
|
|
new Funnel(vendorScripts_benchmarks_external, {srcDir: '/', destDir: destDir}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function writeScriptsForPath(relativePath, result) {
|
|
|
|
copyVendorScriptsTo(path.dirname(relativePath));
|
|
|
|
return result.replace('@@FILENAME_NO_EXT', relativePath.replace(/\.\w+$/, ''));
|
|
|
|
}
|
|
|
|
|
|
|
|
var htmlTree = new Funnel(modulesTree, {include: ['*/src/**/*.html'], destDir: '/'});
|
|
|
|
htmlTree = replace(htmlTree, {
|
|
|
|
files: ['examples*/**'],
|
|
|
|
patterns: [{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS')}],
|
|
|
|
replaceWithPath: writeScriptsForPath
|
|
|
|
});
|
|
|
|
htmlTree = replace(htmlTree, {
|
|
|
|
files: ['benchmarks/**'],
|
|
|
|
patterns: [{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks')}],
|
|
|
|
replaceWithPath: writeScriptsForPath
|
|
|
|
});
|
|
|
|
htmlTree = replace(htmlTree, {
|
|
|
|
files: ['benchmarks_external/**'],
|
|
|
|
patterns: [{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks_external')}],
|
|
|
|
replaceWithPath: writeScriptsForPath
|
|
|
|
});
|
|
|
|
|
|
|
|
// Copy all vendor scripts into all examples and benchmarks
|
|
|
|
['benchmarks/src', 'benchmarks_external/src', 'examples/src/benchpress'].forEach(
|
|
|
|
copyVendorScriptsTo);
|
|
|
|
|
|
|
|
var scripts = mergeTrees(servingTrees, {overwrite: true});
|
|
|
|
var css = new Funnel(modulesTree, {include: ["**/*.css"]});
|
|
|
|
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');
|
|
|
|
|
|
|
|
htmlTree = mergeTrees([htmlTree, scripts, polymer, css, react]);
|
2015-04-13 19:39:47 -04:00
|
|
|
|
|
|
|
es5Tree = mergeTrees([es5Tree, htmlTree]);
|
|
|
|
|
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
|
|
|
};
|