chore(build): refactor broccoli trees to generate them in order to reduce duplication
This commit is contained in:
parent
0012caa4d5
commit
1f6c6dbf2f
|
@ -1,74 +0,0 @@
|
||||||
var Funnel = require('broccoli-funnel');
|
|
||||||
var mergeTrees = require('broccoli-merge-trees');
|
|
||||||
var stew = require('broccoli-stew');
|
|
||||||
var TraceurCompiler = require('./dist/broccoli/traceur');
|
|
||||||
var TypescriptCompiler = require('./dist/broccoli/typescript');
|
|
||||||
var renderLodashTemplate = require('broccoli-lodash');
|
|
||||||
|
|
||||||
var modulesTree = new Funnel(
|
|
||||||
'modules', {include: ['**/**'], exclude: ['angular2/src/core/zone/vm_turn_zone.es6']});
|
|
||||||
|
|
||||||
// Use Traceur to transpile original sources to ES5
|
|
||||||
var traceurOpts = {
|
|
||||||
sourceMaps: true,
|
|
||||||
annotations: true, // parse annotations
|
|
||||||
types: true, // parse types
|
|
||||||
script: false, // parse as a module
|
|
||||||
memberVariables: true, // parse class fields
|
|
||||||
typeAssertionModule: 'rtts_assert/rtts_assert',
|
|
||||||
// Don't use type assertions since this is partly transpiled by typescript
|
|
||||||
typeAssertions: false,
|
|
||||||
modules: 'commonjs'
|
|
||||||
};
|
|
||||||
var cjsTree = new TraceurCompiler(modulesTree, '.js', '.map', traceurOpts);
|
|
||||||
|
|
||||||
// Add the LICENSE file in each module
|
|
||||||
['angular2', 'benchmarks', 'benchmarks_external', 'benchpress', 'examples', 'rtts_assert'].forEach(
|
|
||||||
function(destDir) {
|
|
||||||
cjsTree = mergeTrees([cjsTree, new Funnel('.', {files: ['LICENSE'], destDir: destDir})]);
|
|
||||||
});
|
|
||||||
|
|
||||||
extras = new Funnel(modulesTree, {include: ['**/*.md', '**/*.png'], exclude: ['**/*.dart.md']});
|
|
||||||
extras = stew.rename(extras, 'README.js.md', 'README.md');
|
|
||||||
|
|
||||||
var BASE_PACKAGE_JSON = require('./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,
|
|
||||||
contributors: BASE_PACKAGE_JSON.contributors,
|
|
||||||
dependencies: BASE_PACKAGE_JSON.dependencies,
|
|
||||||
devDependencies: {
|
|
||||||
"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']
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Add a .template extension since renderLodashTemplate strips one extension
|
|
||||||
var packageJsons =
|
|
||||||
stew.rename(new Funnel(modulesTree, {include: ['**/package.json']}), '.json', '.json.template');
|
|
||||||
packageJsons = renderLodashTemplate(
|
|
||||||
packageJsons, {files: ["**/**"], context: {'packageJson': COMMON_PACKAGE_JSON}});
|
|
||||||
|
|
||||||
var typescriptTree = new TypescriptCompiler(modulesTree, {
|
|
||||||
target: 'ES5',
|
|
||||||
sourceMap: true,
|
|
||||||
mapRoot: '', /* force sourcemaps to use relative path */
|
|
||||||
module: /*system.js*/ 'commonjs',
|
|
||||||
allowNonTsExtensions: false,
|
|
||||||
typescript: require('typescript'),
|
|
||||||
// declarationFiles: true,
|
|
||||||
noEmitOnError: true,
|
|
||||||
outDir: 'angular2'
|
|
||||||
});
|
|
||||||
|
|
||||||
// For now, we just overwrite the Traceur-compiled files with their Typescript equivalent
|
|
||||||
cjsTree = mergeTrees([cjsTree, typescriptTree], { overwrite: true });
|
|
||||||
cjsTree = mergeTrees([cjsTree, extras, packageJsons]);
|
|
||||||
|
|
||||||
module.exports = stew.mv(cjsTree, 'js/cjs');
|
|
|
@ -1,104 +0,0 @@
|
||||||
var Funnel = require('broccoli-funnel');
|
|
||||||
var flatten = require('broccoli-flatten');
|
|
||||||
var mergeTrees = require('broccoli-merge-trees');
|
|
||||||
var stew = require('broccoli-stew');
|
|
||||||
var TraceurCompiler = require('./dist/broccoli/traceur');
|
|
||||||
var replace = require('broccoli-replace');
|
|
||||||
var htmlReplace = require('./tools/broccoli/html-replace');
|
|
||||||
var path = require('path');
|
|
||||||
|
|
||||||
var modulesTree = new Funnel('modules', {include: ['**/**'], exclude: ['**/*.cjs'], destDir: '/'});
|
|
||||||
|
|
||||||
// Use Traceur to transpile original sources to ES6
|
|
||||||
var es6DevTree = new TraceurCompiler(modulesTree, '.es6', '.map', {
|
|
||||||
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: true,
|
|
||||||
outputLanguage: 'es6'
|
|
||||||
});
|
|
||||||
|
|
||||||
// Call Traceur again to lower the ES6 build tree to ES5
|
|
||||||
var es5DevTree =
|
|
||||||
new TraceurCompiler(es6DevTree, '.js', '.js.map', {modules: 'instantiate', sourceMaps: true});
|
|
||||||
|
|
||||||
// Now we add a few more files to the es6 tree that Traceur should not see
|
|
||||||
['angular2', 'benchmarks', 'benchmarks_external', 'benchpress', 'examples', 'rtts_assert'].forEach(
|
|
||||||
function(destDir) {
|
|
||||||
var extras = new Funnel('tools/build', {files: ['es5build.js'], destDir: destDir});
|
|
||||||
es6DevTree = mergeTrees([es6DevTree, extras]);
|
|
||||||
});
|
|
||||||
|
|
||||||
var vendorScriptsTree = flatten(new Funnel('.', {
|
|
||||||
files: [
|
|
||||||
'node_modules/es6-module-loader/dist/es6-module-loader-sans-promises.src.js',
|
|
||||||
'node_modules/zone.js/zone.js',
|
|
||||||
'node_modules/zone.js/long-stack-trace-zone.js',
|
|
||||||
'node_modules/systemjs/dist/system.src.js',
|
|
||||||
'node_modules/systemjs/lib/extension-register.js',
|
|
||||||
'node_modules/systemjs/lib/extension-cjs.js',
|
|
||||||
'node_modules/rx/dist/rx.all.js',
|
|
||||||
'tools/build/snippets/runtime_paths.js',
|
|
||||||
path.relative(__dirname, TraceurCompiler.RUNTIME_PATH)
|
|
||||||
]
|
|
||||||
}));
|
|
||||||
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
|
|
||||||
});
|
|
||||||
// TODO(broccoli): are these needed here, if not loaded by a script tag??
|
|
||||||
['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');
|
|
||||||
htmlTree = mergeTrees([htmlTree, scripts, polymer, css]);
|
|
||||||
|
|
||||||
es5DevTree = mergeTrees([es5DevTree, htmlTree]);
|
|
||||||
|
|
||||||
module.exports = mergeTrees([stew.mv(es6DevTree, 'js/dev/es6'), stew.mv(es5DevTree, 'js/dev/es5')]);
|
|
|
@ -1,105 +0,0 @@
|
||||||
var Funnel = require('broccoli-funnel');
|
|
||||||
var flatten = require('broccoli-flatten');
|
|
||||||
var mergeTrees = require('broccoli-merge-trees');
|
|
||||||
var stew = require('broccoli-stew');
|
|
||||||
var TraceurCompiler = require('./dist/broccoli/traceur');
|
|
||||||
var replace = require('broccoli-replace');
|
|
||||||
var htmlReplace = require('./tools/broccoli/html-replace');
|
|
||||||
var path = require('path');
|
|
||||||
|
|
||||||
var modulesTree = new Funnel('modules', {include: ['**/**'], destDir: '/'});
|
|
||||||
|
|
||||||
// Use Traceur to transpile original sources to ES6
|
|
||||||
var es6ProdTree = new TraceurCompiler(modulesTree, '.es6', '.map', {
|
|
||||||
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: false,
|
|
||||||
outputLanguage: 'es6'
|
|
||||||
});
|
|
||||||
|
|
||||||
// Call Traceur again to lower the ES6 build tree to ES5
|
|
||||||
var es5ProdTree =
|
|
||||||
new TraceurCompiler(es6ProdTree, '.js', '.js.map', {modules: 'instantiate', sourceMaps: true});
|
|
||||||
|
|
||||||
// Now we add a few more files to the es6 tree that Traceur should not see
|
|
||||||
['angular2', 'benchmarks', 'benchmarks_external', 'benchpress', 'examples', 'rtts_assert'].forEach(
|
|
||||||
function(destDir) {
|
|
||||||
var extras = new Funnel('tools/build', {files: ['es5build.js'], destDir: destDir});
|
|
||||||
es6ProdTree = mergeTrees([es6ProdTree, extras]);
|
|
||||||
});
|
|
||||||
|
|
||||||
var vendorScriptsTree = flatten(new Funnel('.', {
|
|
||||||
files: [
|
|
||||||
'node_modules/es6-module-loader/dist/es6-module-loader-sans-promises.src.js',
|
|
||||||
'node_modules/zone.js/zone.js',
|
|
||||||
'node_modules/zone.js/long-stack-trace-zone.js',
|
|
||||||
'node_modules/systemjs/dist/system.src.js',
|
|
||||||
'node_modules/systemjs/lib/extension-register.js',
|
|
||||||
'node_modules/systemjs/lib/extension-cjs.js',
|
|
||||||
'node_modules/rx/dist/rx.all.js',
|
|
||||||
'tools/build/snippets/runtime_paths.js',
|
|
||||||
path.relative(__dirname, TraceurCompiler.RUNTIME_PATH)
|
|
||||||
]
|
|
||||||
}));
|
|
||||||
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
|
|
||||||
});
|
|
||||||
// TODO(broccoli): are these needed here, if not loaded by a script tag??
|
|
||||||
['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');
|
|
||||||
htmlTree = mergeTrees([htmlTree, scripts, polymer, css]);
|
|
||||||
|
|
||||||
es5ProdTree = mergeTrees([es5ProdTree, htmlTree]);
|
|
||||||
|
|
||||||
module.exports =
|
|
||||||
mergeTrees([stew.mv(es6ProdTree, 'js/prod/es6'), stew.mv(es5ProdTree, 'js/prod/es5')]);
|
|
25
gulpfile.js
25
gulpfile.js
|
@ -33,6 +33,7 @@ var util = require('./tools/build/util');
|
||||||
var bundler = require('./tools/build/bundle');
|
var bundler = require('./tools/build/bundle');
|
||||||
var replace = require('gulp-replace');
|
var replace = require('gulp-replace');
|
||||||
var insert = require('gulp-insert');
|
var insert = require('gulp-insert');
|
||||||
|
var makeBroccoliTree = require('./tools/broccoli/make-broccoli-tree');
|
||||||
|
|
||||||
// Note: when DART_SDK is not found, all gulp tasks ending with `.dart` will be skipped.
|
// Note: when DART_SDK is not found, all gulp tasks ending with `.dart` will be skipped.
|
||||||
|
|
||||||
|
@ -573,6 +574,24 @@ gulp.task('serve/benchmarks_external.dart', pubserve(gulp, gulpPlugins, {
|
||||||
path: CONFIG.dest.dart + '/benchmarks_external'
|
path: CONFIG.dest.dart + '/benchmarks_external'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
gulp.task('serve/examples.dart.static', pubserve(gulp, gulpPlugins, {
|
||||||
|
command: DART_SDK.PUB,
|
||||||
|
mode: 'ngstatic',
|
||||||
|
path: CONFIG.dest.dart + '/examples'
|
||||||
|
}));
|
||||||
|
|
||||||
|
gulp.task('serve/benchmarks.dart.static', pubserve(gulp, gulpPlugins, {
|
||||||
|
command: DART_SDK.PUB,
|
||||||
|
mode: 'ngstatic',
|
||||||
|
path: CONFIG.dest.dart + '/benchmarks'
|
||||||
|
}));
|
||||||
|
|
||||||
|
gulp.task('serve/benchmarks_external.dart.static', pubserve(gulp, gulpPlugins, {
|
||||||
|
command: DART_SDK.PUB,
|
||||||
|
mode: 'ngstatic',
|
||||||
|
path: CONFIG.dest.dart + '/benchmarks_external'
|
||||||
|
}));
|
||||||
|
|
||||||
// --------------
|
// --------------
|
||||||
// doc generation
|
// doc generation
|
||||||
var Dgeni = require('dgeni');
|
var Dgeni = require('dgeni');
|
||||||
|
@ -754,11 +773,11 @@ gulp.task('build.broccoli.tools', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('broccoli.js.dev', ['build.broccoli.tools'], function() {
|
gulp.task('broccoli.js.dev', ['build.broccoli.tools'], function() {
|
||||||
return broccoliBuild(require('./Brocfile-js_dev.js'), path.join('js', 'dev'));
|
return broccoliBuild(makeBroccoliTree('dev'), path.join('js', 'dev'));
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('broccoli.js.prod', ['build.broccoli.tools'], function() {
|
gulp.task('broccoli.js.prod', ['build.broccoli.tools'], function() {
|
||||||
return broccoliBuild(require('./Brocfile-js_prod.js'), path.join('js', 'prod'));
|
return broccoliBuild(makeBroccoliTree('prod'), path.join('js', 'prod'));
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('build.js.dev', function(done) {
|
gulp.task('build.js.dev', function(done) {
|
||||||
|
@ -773,7 +792,7 @@ gulp.task('build.js.dev', function(done) {
|
||||||
gulp.task('build.js.prod', ['broccoli.js.prod']);
|
gulp.task('build.js.prod', ['broccoli.js.prod']);
|
||||||
|
|
||||||
gulp.task('broccoli.js.cjs', ['build.broccoli.tools'], function() {
|
gulp.task('broccoli.js.cjs', ['build.broccoli.tools'], function() {
|
||||||
return broccoliBuild(require('./Brocfile-js_cjs.js'), path.join('js', 'cjs'));
|
return broccoliBuild(makeBroccoliTree('cjs'), path.join('js', 'cjs'));
|
||||||
});
|
});
|
||||||
gulp.task('build.js.cjs', function(done) {
|
gulp.task('build.js.cjs', function(done) {
|
||||||
runSequence(
|
runSequence(
|
||||||
|
|
|
@ -0,0 +1,221 @@
|
||||||
|
'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 renderLodashTemplate = require('broccoli-lodash');
|
||||||
|
var replace = require('broccoli-replace');
|
||||||
|
var stew = require('broccoli-stew');
|
||||||
|
var TraceurCompiler;
|
||||||
|
var TypescriptCompiler;
|
||||||
|
|
||||||
|
var projectRootDir = path.normalize(path.join(__dirname, '..', '..'));
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = function makeBroccoliTree(name) {
|
||||||
|
if (!TraceurCompiler) TraceurCompiler = require('../../dist/broccoli/traceur');
|
||||||
|
if (!TypescriptCompiler) TypescriptCompiler = require('../../dist/broccoli/typescript');
|
||||||
|
|
||||||
|
switch (name) {
|
||||||
|
case 'dev': return makeBrowserTree({name: name, typeAssertions: true});
|
||||||
|
case 'prod': return makeBrowserTree({name: name, typeAssertions: false});
|
||||||
|
case 'cjs': return makeCjsTree();
|
||||||
|
default: throw new Error('Unknown build type: ' + name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function makeBrowserTree(options) {
|
||||||
|
var modulesTree = new Funnel('modules', {
|
||||||
|
include: ['**/**'],
|
||||||
|
exclude: ['**/*.cjs', 'benchmarks/e2e_test/**'],
|
||||||
|
destDir: '/'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Use Traceur to transpile original sources to ES6
|
||||||
|
var es6Tree = new TraceurCompiler(modulesTree, '.es6', '.map', {
|
||||||
|
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'
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Call Traceur again to lower the ES6 build tree to ES5
|
||||||
|
var es5Tree = new TraceurCompiler(es6Tree, '.js', '.js.map', {modules: 'instantiate', sourceMaps: true});
|
||||||
|
|
||||||
|
// Now we add a few more files to the es6 tree that Traceur should not see
|
||||||
|
// TODO(broccoli): this is wrong. only angular2 and rtts_assert should contain the es5build.js file
|
||||||
|
['angular2', 'benchmarks', 'benchmarks_external', 'benchpress', 'examples', '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: [
|
||||||
|
'node_modules/es6-module-loader/dist/es6-module-loader-sans-promises.src.js',
|
||||||
|
'node_modules/zone.js/zone.js',
|
||||||
|
'node_modules/zone.js/long-stack-trace-zone.js',
|
||||||
|
'node_modules/systemjs/dist/system.src.js',
|
||||||
|
'node_modules/systemjs/lib/extension-register.js',
|
||||||
|
'node_modules/systemjs/lib/extension-cjs.js',
|
||||||
|
'node_modules/rx/dist/rx.all.js',
|
||||||
|
'tools/build/snippets/runtime_paths.js',
|
||||||
|
path.relative(projectRootDir, TraceurCompiler.RUNTIME_PATH)
|
||||||
|
]
|
||||||
|
}));
|
||||||
|
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
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO(broccoli): are these needed here, if not loaded by a script tag??
|
||||||
|
['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');
|
||||||
|
htmlTree = mergeTrees([htmlTree, scripts, polymer, css]);
|
||||||
|
|
||||||
|
es5Tree = mergeTrees([es5Tree, htmlTree]);
|
||||||
|
|
||||||
|
return mergeTrees([
|
||||||
|
stew.mv(es6Tree, 'js/' + options.name + '/es6'),
|
||||||
|
stew.mv(es5Tree, 'js/' + options.name + '/es5')
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function makeCjsTree() {
|
||||||
|
// list of npm packages that this build will create
|
||||||
|
var outputPackages = ['angular2', 'benchpress', 'rtts_assert'];
|
||||||
|
|
||||||
|
var modulesTree = new Funnel('modules', {
|
||||||
|
// TODO(broccoli): this is wrong. it should be just
|
||||||
|
// include: ['angular2/**', 'benchpress/**', 'rtts_assert/**', 'benchmarks/e2e_test/**'],
|
||||||
|
include: ['**/**'],
|
||||||
|
exclude: ['angular2/src/core/zone/vm_turn_zone.es6']
|
||||||
|
});
|
||||||
|
|
||||||
|
// Use Traceur to transpile original sources to ES6
|
||||||
|
var traceurOpts = {
|
||||||
|
sourceMaps: true,
|
||||||
|
annotations: true, // parse annotations
|
||||||
|
types: true, // parse types
|
||||||
|
script: false, // parse as a module
|
||||||
|
memberVariables: true, // parse class fields
|
||||||
|
typeAssertionModule: 'rtts_assert/rtts_assert',
|
||||||
|
// Don't use type assertions since this is partly transpiled by typescript
|
||||||
|
typeAssertions: false,
|
||||||
|
modules: 'commonjs'
|
||||||
|
}
|
||||||
|
|
||||||
|
var cjsTree = new TraceurCompiler(modulesTree, '.js', '.map', traceurOpts);
|
||||||
|
|
||||||
|
// 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});
|
||||||
|
cjsTree = mergeTrees([cjsTree, license]);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 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,
|
||||||
|
contributors: BASE_PACKAGE_JSON.contributors,
|
||||||
|
dependencies: BASE_PACKAGE_JSON.dependencies,
|
||||||
|
devDependencies: {
|
||||||
|
"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']
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add a .template extension since renderLodashTemplate strips one extension
|
||||||
|
var packageJsons = stew.rename(new Funnel(modulesTree, {include: ['**/package.json']}), '.json', '.json.template');
|
||||||
|
packageJsons = renderLodashTemplate(packageJsons, {
|
||||||
|
files: ["**/**"],
|
||||||
|
context: { 'packageJson': COMMON_PACKAGE_JSON }
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
var typescriptTree = new TypescriptCompiler(modulesTree, {
|
||||||
|
target: 'ES5',
|
||||||
|
sourceMap: true,
|
||||||
|
mapRoot: '', /* force sourcemaps to use relative path */
|
||||||
|
module: /*system.js*/ 'commonjs',
|
||||||
|
allowNonTsExtensions: false,
|
||||||
|
typescript: require('typescript'),
|
||||||
|
// declarationFiles: true,
|
||||||
|
noEmitOnError: true,
|
||||||
|
outDir: 'angular2'
|
||||||
|
});
|
||||||
|
|
||||||
|
// For now, we just overwrite the Traceur-compiled files with their Typescript equivalent
|
||||||
|
cjsTree = mergeTrees([cjsTree, typescriptTree], { overwrite: true });
|
||||||
|
cjsTree = mergeTrees([cjsTree, docs, packageJsons]);
|
||||||
|
|
||||||
|
return stew.mv(cjsTree, 'js/cjs');
|
||||||
|
}
|
Loading…
Reference in New Issue