chore(build): Migrate remaining tasks under build.js.dev to broccoli.

This commit is contained in:
Alex Eagle 2015-04-08 08:28:12 -07:00
parent cfc5dd830c
commit b94b04c074
11 changed files with 161 additions and 12 deletions

View File

@ -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')]);

View File

@ -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
);

View File

@ -22,7 +22,8 @@
<h2>Polymer JS 0.8-preview tree benchmark</h2>
<root-tree></root-tree>
$SCRIPTS$
<script src="url_params_to_form.js" type="text/javascript"></script>
</body>
</html>

View File

@ -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",

View File

@ -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);
}

View File

@ -0,0 +1,10 @@
<script src="traceur-runtime.js" type="text/javascript"></script>
<script src="es6-module-loader-sans-promises.src.js" type="text/javascript"></script>
<script src="zone.js" type="text/javascript"></script>
<script src="long-stack-trace-zone.js" type="text/javascript"></script>
<script src="system.src.js" type="text/javascript"></script>
<script src="extension-register.js" type="text/javascript"></script>
<script src="extension-cjs.js" type="text/javascript"></script>
<script src="rx.all.js" type="text/javascript"></script>
<script src="runtime_paths.js" type="text/javascript"></script>
<script type="text/javascript">System.import('@@FILENAME_NO_EXT').then(function(m) { m.main(); }, console.error.bind(console))</script>

View File

@ -0,0 +1,11 @@
<script src="url_params_to_form.js" type="text/javascript"></script>
<script src="traceur-runtime.js" type="text/javascript"></script>
<script src="es6-module-loader-sans-promises.src.js" type="text/javascript"></script>
<script src="zone.js" type="text/javascript"></script>
<script src="long-stack-trace-zone.js" type="text/javascript"></script>
<script src="system.src.js" type="text/javascript"></script>
<script src="extension-register.js" type="text/javascript"></script>
<script src="extension-cjs.js" type="text/javascript"></script>
<script src="rx.all.js" type="text/javascript"></script>
<script src="runtime_paths.js" type="text/javascript"></script>
<script type="text/javascript">System.import('@@FILENAME_NO_EXT').then(function(m) { m.main(); }, console.error.bind(console))</script>

View File

@ -0,0 +1,12 @@
<script src="angular.js" type="text/javascript"></script>
<script src="url_params_to_form.js" type="text/javascript"></script>
<script src="traceur-runtime.js" type="text/javascript"></script>
<script src="es6-module-loader-sans-promises.src.js" type="text/javascript"></script>
<script src="zone.js" type="text/javascript"></script>
<script src="long-stack-trace-zone.js" type="text/javascript"></script>
<script src="system.src.js" type="text/javascript"></script>
<script src="extension-register.js" type="text/javascript"></script>
<script src="extension-cjs.js" type="text/javascript"></script>
<script src="rx.all.js" type="text/javascript"></script>
<script src="runtime_paths.js" type="text/javascript"></script>
<script type="text/javascript">System.import('@@FILENAME_NO_EXT').then(function(m) { m.main(); }, console.error.bind(console))</script>

View File

@ -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"));
}

View File

@ -48,6 +48,7 @@ var TraceurFilter = (function (_super) {
});
});
};
TraceurFilter.RUNTIME_PATH = traceur.RUNTIME_PATH;
return TraceurFilter;
})(Writer);
module.exports = TraceurFilter;

View File

@ -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 => {