From b94b04c0746aa2ed1c4ba824c4d4334d2bf94dc9 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Wed, 8 Apr 2015 08:28:12 -0700 Subject: [PATCH] chore(build): Migrate remaining tasks under build.js.dev to broccoli. --- Brocfile-js_dev.js | 82 ++++++++++++++++++- gulpfile.js | 10 +-- .../src/tree/polymer/index.html | 3 +- package.json | 3 + tools/broccoli/gulp/index.js | 29 ++++++- tools/broccoli/html-replace/SCRIPTS.html | 10 +++ .../html-replace/SCRIPTS_benchmarks.html | 11 +++ .../SCRIPTS_benchmarks_external.html | 12 +++ tools/broccoli/html-replace/index.js | 10 +++ tools/broccoli/traceur/index.js | 1 + tools/broccoli/traceur/index.ts | 2 +- 11 files changed, 161 insertions(+), 12 deletions(-) create mode 100644 tools/broccoli/html-replace/SCRIPTS.html create mode 100644 tools/broccoli/html-replace/SCRIPTS_benchmarks.html create mode 100644 tools/broccoli/html-replace/SCRIPTS_benchmarks_external.html create mode 100644 tools/broccoli/html-replace/index.js diff --git a/Brocfile-js_dev.js b/Brocfile-js_dev.js index 1913bbe825..8ecf34d5e0 100644 --- a/Brocfile-js_dev.js +++ b/Brocfile-js_dev.js @@ -1,11 +1,15 @@ var Funnel = require('broccoli-funnel'); +var flatten = require('broccoli-flatten'); var mergeTrees = require('broccoli-merge-trees'); var stew = require('broccoli-stew'); var TraceurCompiler = require('./tools/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: '/'}); -// First, use Traceur to transpile original sources to ES6 +// Use Traceur to transpile original sources to ES6 var es6DevTree = new TraceurCompiler(modulesTree, '.es6', { sourceMaps: true, annotations: true, // parse annotations @@ -17,6 +21,7 @@ var es6DevTree = new TraceurCompiler(modulesTree, '.es6', { typeAssertions: true, outputLanguage: 'es6' }); +// Munge the filenames since we use an '.es6' extension es6DevTree = stew.rename(es6DevTree, function(relativePath) { return relativePath.replace(/\.(js|es6)\.map$/, '.map').replace(/\.js$/, '.es6'); }); @@ -25,4 +30,79 @@ es6DevTree = stew.rename(es6DevTree, function(relativePath) { var es5DevTree = new TraceurCompiler(es6DevTree, '.js', {modules: 'instantiate', sourceMaps: true}); es5DevTree = stew.rename(es5DevTree, '.es6.map', '.js.map'); +// 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')]); diff --git a/gulpfile.js b/gulpfile.js index cb51a8b2ff..338d9704a8 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -344,10 +344,6 @@ gulp.task('build/transpile.js.dev.es5', function() { }); }); -gulp.task('broccoli.js.dev', function() { - return broccoliBuild(require('./Brocfile-js_dev.js'), path.join('js', 'dev')); -}); - gulp.task('build/transpile.js.prod.es6', transpile(gulp, gulpPlugins, { src: CONFIG.transpile.src.js, dest: CONFIG.dest.js.prod.es6, @@ -542,7 +538,7 @@ gulp.task('build/format.dart', rundartpackage(gulp, gulpPlugins, { })); gulp.task('check-format', function() { - return gulp.src(['modules/**/*.ts', '!**/typings/**/*.d.ts']) + return gulp.src(['Brocfile*.js', 'modules/**/*.ts', '!**/typings/**/*.d.ts']) .pipe(format.checkFormat('file')); }); @@ -793,10 +789,12 @@ gulp.task('build.dart', function(done) { ); }); +gulp.task('broccoli.js.dev', function() { + return broccoliBuild(require('./Brocfile-js_dev.js'), path.join('js', 'dev')); +}); gulp.task('build.js.dev', function(done) { runSequence( 'broccoli.js.dev', - ['build/html.js.dev', 'build/copy.js.dev', 'build/multicopy.js.dev.es6'], 'build/checkCircularDependencies', done ); diff --git a/modules/benchmarks_external/src/tree/polymer/index.html b/modules/benchmarks_external/src/tree/polymer/index.html index 2aba6179e0..e3ad735192 100644 --- a/modules/benchmarks_external/src/tree/polymer/index.html +++ b/modules/benchmarks_external/src/tree/polymer/index.html @@ -22,7 +22,8 @@

Polymer JS 0.8-preview tree benchmark

-$SCRIPTS$ + + diff --git a/package.json b/package.json index e08640a4a4..0a1236779d 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,11 @@ "angular": "1.3.5", "bower": "^1.3.12", "broccoli": "^0.15.3", + "broccoli-flatten": "^0.1.1", "broccoli-funnel": "igorminar/broccoli-funnel#perf-files", "broccoli-merge-trees": "^0.2.1", + "broccoli-replace": "alexeagle/broccoli-replace#angular_patch", + "broccoli-slow-trees": "^1.1.0", "broccoli-stew": "^0.2.1", "broccoli-writer": "^0.1.1", "canonical-path": "0.0.2", diff --git a/tools/broccoli/gulp/index.js b/tools/broccoli/gulp/index.js index b043e80985..222326d769 100644 --- a/tools/broccoli/gulp/index.js +++ b/tools/broccoli/gulp/index.js @@ -1,7 +1,11 @@ +'use strict'; + var broccoli = require('broccoli'); var copyDereferenceSync = require('copy-dereference').sync; var fse = require('fs-extra'); var path = require('path'); +var printSlowTrees = require('broccoli-slow-trees'); + module.exports = broccoliBuild; var broccoliExecuted = {}; @@ -29,24 +33,43 @@ function broccoliBuild(tree, outputRoot) { var builder = new broccoli.Builder(tree); return builder.build() .then(function (hash) { + printSlowTrees(hash.graph); + var dir = hash.directory; try { - copyDereferenceSync(path.join(dir, outputRoot), distPath); + time('Write build output', function() { + copyDereferenceSync(path.join(dir, outputRoot), distPath); + }); } catch (err) { if (err.code === 'EEXIST') err.message += ' (we cannot build into an existing directory)'; throw err; } }) .finally(function () { - builder.cleanup(); + time('Build cleanup', function() { + builder.cleanup(); + }); }) .catch(function (err) { // Should show file and line/col if present if (err.file) { console.error('File: ' + err.file); } - console.error(err.stack); + if (err.stack) { + console.error(err.stack); + } else { + console.error(err); + } console.error('\nBuild failed'); process.exit(1); }); } + + +function time(label, work) { + + var start = Date.now(); + work(); + var duration = Date.now() - start; + console.log("%s: %dms", label, duration); +} diff --git a/tools/broccoli/html-replace/SCRIPTS.html b/tools/broccoli/html-replace/SCRIPTS.html new file mode 100644 index 0000000000..8e9db62c8d --- /dev/null +++ b/tools/broccoli/html-replace/SCRIPTS.html @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/tools/broccoli/html-replace/SCRIPTS_benchmarks.html b/tools/broccoli/html-replace/SCRIPTS_benchmarks.html new file mode 100644 index 0000000000..9c9903bd69 --- /dev/null +++ b/tools/broccoli/html-replace/SCRIPTS_benchmarks.html @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/tools/broccoli/html-replace/SCRIPTS_benchmarks_external.html b/tools/broccoli/html-replace/SCRIPTS_benchmarks_external.html new file mode 100644 index 0000000000..69f2ff7b40 --- /dev/null +++ b/tools/broccoli/html-replace/SCRIPTS_benchmarks_external.html @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/tools/broccoli/html-replace/index.js b/tools/broccoli/html-replace/index.js new file mode 100644 index 0000000000..42c4f5121f --- /dev/null +++ b/tools/broccoli/html-replace/index.js @@ -0,0 +1,10 @@ +var fs = require('fs'); +var path = require('path'); + +module.exports = read; +function read(file) { + var content = fs.readFileSync(path.join(__dirname, file + '.html'), {encoding: 'utf-8'}); + // TODO(broccoli): we don't really need this, it's here to make the output match the tools/build/html + return content.substring(0, content.lastIndexOf("\n")); +} + diff --git a/tools/broccoli/traceur/index.js b/tools/broccoli/traceur/index.js index 61d59a17d0..2b4490891d 100644 --- a/tools/broccoli/traceur/index.js +++ b/tools/broccoli/traceur/index.js @@ -48,6 +48,7 @@ var TraceurFilter = (function (_super) { }); }); }; + TraceurFilter.RUNTIME_PATH = traceur.RUNTIME_PATH; return TraceurFilter; })(Writer); module.exports = TraceurFilter; diff --git a/tools/broccoli/traceur/index.ts b/tools/broccoli/traceur/index.ts index 8909163c24..4154b211ac 100644 --- a/tools/broccoli/traceur/index.ts +++ b/tools/broccoli/traceur/index.ts @@ -8,7 +8,7 @@ var xtend = require('xtend'); class TraceurFilter extends Writer { constructor(private inputTree, private destExtension: string = '.js', private options = {}) {} - + static RUNTIME_PATH = traceur.RUNTIME_PATH; write(readTree, destDir) { return readTree(this.inputTree) .then(srcDir => {