chore(benchpress): add browserify bundling

Use browserify to bundle benchpress and its dependencies.
This commit is contained in:
uber5001
2015-06-29 10:29:59 -07:00
committed by Tobias Bosch
parent f1cf5298d8
commit c4e10ea9ac
11 changed files with 1413 additions and 14 deletions
+38 -3
View File
@@ -124,10 +124,30 @@ var CONFIG = {
},
dart: 'dist/dart',
docs: 'dist/docs',
docs_angular_io: 'dist/angular.io'
docs_angular_io: 'dist/angular.io',
benchpress_bundle: 'dist/build/benchpress_bundle/'
}
};
var BENCHPRESS_BUNDLE_CONFIG = {
entries: ['./dist/js/cjs/benchpress/index.js'],
packageJson: './dist/js/cjs/benchpress/package.json',
includes: [
'angular2',
'traceur',
'reflect-metadata'
],
excludes: [
'selenium-webdriver',
'rtts_assert',
'zone.js'
],
ignore: [
'rx'
],
dest: CONFIG.dest.benchpress_bundle
}
// ------------
// clean
@@ -151,6 +171,9 @@ gulp.task('build/clean.docs_angular_io', function(done) {
del(CONFIG.dest.docs_angular_io, done);
});
gulp.task('build/clean.benchpress.bundle', function(done) {
del(CONFIG.dest.benchpress_bundle, done);
});
// ------------
// transpile
@@ -888,9 +911,9 @@ gulp.task('bundle.js.sfx.dev.deps', ['bundle.js.sfx.dev'], function() {
gulp.task('bundle.js.deps', ['bundle.js.prod.deps', 'bundle.js.dev.deps', 'bundle.js.min.deps', 'bundle.js.sfx.dev.deps', 'router.bundle.js.dev', 'mock.bundle.js.dev']);
gulp.task('build.js', ['build.js.dev', 'build.js.prod', 'build.js.cjs', 'bundle.js.deps']);
gulp.task('build.js', ['build.js.dev', 'build.js.prod', 'build.js.cjs', 'bundle.js.deps', 'benchpress.bundle']);
gulp.task('clean', ['build/clean.tools', 'build/clean.js', 'build/clean.dart', 'build/clean.docs']);
gulp.task('clean', ['build/clean.tools', 'build/clean.js', 'build/clean.dart', 'build/clean.docs', 'build/clean.benchpress.bundle']);
gulp.task('build', ['build.js', 'build.dart']);
@@ -959,6 +982,18 @@ gulp.task('cleanup.builder', function(done) {
});
});
gulp.task('benchpress.bundle', ['build/clean.benchpress.bundle', 'build.js.cjs'], function(cb) {
bundler.benchpressBundle(
BENCHPRESS_BUNDLE_CONFIG.entries,
BENCHPRESS_BUNDLE_CONFIG.packageJson,
BENCHPRESS_BUNDLE_CONFIG.includes,
BENCHPRESS_BUNDLE_CONFIG.excludes,
BENCHPRESS_BUNDLE_CONFIG.ignore,
BENCHPRESS_BUNDLE_CONFIG.dest,
cb
);
})
// register cleanup listener for ctrl+c/kill used to quit any persistent task (autotest or serve tasks)
process.on('SIGINT', function() {
+3 -1
View File
@@ -1,6 +1,8 @@
export {verifyNoBrowserErrors} from './e2e_util';
import {bind, Options} from 'benchpress/benchpress';
var benchpress = global['benchpress'];
var bind = benchpress.bind;
var Options = benchpress.Options;
export function runClickBenchmark(config) {
var buttons = config.buttons.map(function(selector) { return $(selector); });
+5 -1
View File
@@ -1,2 +1,6 @@
require(require('traceur').RUNTIME_PATH);
require('reflect-metadata');
require('traceur/bin/traceur-runtime');
module.exports = require('./benchpress.js');
// when bundling benchpress to one file, this is used
// for getting exports out of browserify's scope.
global.__benchpressExports = module.exports;
+2 -2
View File
@@ -11,9 +11,9 @@
"angular2": "<%= packageJson.version %>",
"firefox-profile": "<%= packageJson.devDependencies['firefox-profile'] %>",
"jpm": "<%= packageJson.devDependencies.jpm %>",
"rtts_assert": "<%= packageJson.version %>",
"traceur": "<%= packageJson.dependencies.traceur %>",
"selenium-webdriver": "<%= packageJson.dependencies['selenium-webdriver'] %>"
"selenium-webdriver": "<%= packageJson.dependencies['selenium-webdriver'] %>",
"reflect-metadata": "<%= packageJson.dependencies['reflect-metadata'] %>"
},
"devDependencies": <%= JSON.stringify(packageJson.devDependencies) %>
}
File diff suppressed because it is too large Load Diff
+781
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -54,6 +54,7 @@
"broccoli-slow-trees": "^1.1.0",
"broccoli-stew": "^0.2.1",
"broccoli-writer": "^0.1.1",
"browserify": "^10.2.4",
"canonical-path": "0.0.2",
"chokidar": "^1.0.1",
"clang-format": "^1.0.25",
+3 -4
View File
@@ -1,6 +1,6 @@
// load traceur runtime as our tests are written in es6
require('traceur/bin/traceur-runtime.js');
require('reflect-metadata');
// benchpress will also load traceur runtime as our tests are written in es6
var benchpress = require('./dist/build/benchpress_bundle');
global.benchpress = benchpress;
var fs = require('fs-extra');
var argv = require('yargs')
@@ -202,7 +202,6 @@ function patchProtractorWait(browser) {
exports.createBenchpressRunner = function(options) {
var nodeUuid = require('node-uuid');
var benchpress = require('./dist/js/cjs/benchpress/benchpress');
// TODO(tbosch): add cloud reporter again (only when !options.test)
// var cloudReporterConfig;
+1 -1
View File
@@ -7,6 +7,6 @@ SCRIPT_DIR=$(dirname $0)
source $SCRIPT_DIR/env_dart.sh
cd $SCRIPT_DIR/../..
./node_modules/.bin/gulp build.js.cjs build.dart
./node_modules/.bin/gulp build.js.cjs build.dart benchpress.bundle
pub install
+9 -2
View File
@@ -6,7 +6,7 @@ ROOT_DIR=$(cd $(dirname $0)/../..; pwd)
cd $ROOT_DIR
gulp clean
gulp build.js.prod build.js.dev build.js.cjs
gulp build.js.prod build.js.dev build.js.cjs benchpress.bundle
NPM_DIR=$ROOT_DIR/dist/npm
rm -fr $NPM_DIR
@@ -38,7 +38,14 @@ function publishModule {
mkdir -p $PUBLISH_DIR/ts
cp -r $ROOT_DIR/modules/$NAME/$FILES $PUBLISH_DIR/ts
cp -r $ROOT_DIR/dist/js/cjs/$NAME/$FILES $PUBLISH_DIR
if [ $NAME = "benchpress" ]; then
cp -r $ROOT_DIR/dist/build/benchpress_bundle/$FILES $PUBLISH_DIR
cp -r $ROOT_DIR/dist/js/cjs/benchpress/README.md $PUBLISH_DIR
cp -r $ROOT_DIR/dist/js/cjs/benchpress/LICENSE $PUBLISH_DIR
cp -r $ROOT_DIR/dist/js/cjs/benchpress/docs $PUBLISH_DIR
else
cp -r $ROOT_DIR/dist/js/cjs/$NAME/$FILES $PUBLISH_DIR
fi
npm publish $PUBLISH_DIR
}
+63
View File
@@ -2,6 +2,9 @@ var gulp = require('gulp');
var concat = require('gulp-concat');
var replace = require('gulp-replace');
var insert = require('gulp-insert');
var fs = require('fs-extra');
var browserify = require('browserify');
var path = require('path');
module.exports.bundle = function(buildConfig, moduleName, outputFile, outputConfig,
sfx) {
@@ -23,3 +26,63 @@ module.exports.modify = function(srcs, concatName) {
.pipe(concat(concatName))
.pipe(replace('sourceMappingURL', 'sourceMappingURLDisabled')) // TODO: add concat for sourceMaps
}
module.exports.benchpressBundle = function(entries, packageJsonPath, includes, excludes, ignore, dest, cb) {
/*
we need a script in dist/js/cjs so we
can find node modules the same way benchpress does.
This allows us to extract the LICENSE files from each
module included in the bundle, through:
helper(moduleName)
*/
var helperScript = 'module.exports = function(moduleName){return require.resolve(moduleName)}';
var helperPath = path.resolve('./dist/js/cjs/_module_resolver.js');
fs.writeFileSync(helperPath, helperScript);
var helper = require(helperPath);
var b = browserify({
entries: entries,
builtins: [],
insertGlobalVars: ['__filename','__dirname'],
detectGlobals: false
});
for (var i = 0; i < excludes.length; i++) {
b.exclude(excludes[i]);
}
var packageJson = JSON.parse(fs.readFileSync(packageJsonPath));
for (var dep in packageJson.dependencies) {
//remove deps from package that we want to include in the bundle
if (includes.indexOf(dep) > -1) {
delete packageJson.dependencies[dep];
} else {
b.exclude(dep);
}
}
for (var i = 0; i < ignore.length; i++) {
b.ignore(ignore[i]);
}
fs.mkdirsSync(dest);
fs.writeFileSync(dest + '/package.json', JSON.stringify(packageJson, null, ' '));
b.bundle(function(err, buf) {
if (err) {
return cb(err);
}
var contents = buf.toString();
var licenses = "/*\n";
//for packaged dependencies, the license must also be included
for (var i = 0; i < includes.length; i++) {
var licensePath = helper(includes[i] + "/LICENSE");
var licenseContent = fs.readFileSync(licensePath);
licenses += "======================== BEGIN LICENSE FOR BUNDLED MODULE: " + includes[i] + " ========================\n";
licenses += licenseContent;
licenses += "======================== END LICENSE FOR BUNDLED MODULE: " + includes[i] + " ========================\n";
}
licenses += "*/\n";
contents = licenses + contents;
contents += 'module.exports = global.__benchpressExports;\n';
fs.writeFileSync(dest + '/index.js', contents);
cb(null);
});
}