angular-cn/tools/build/benchpress.js
Tobias Bosch 8db77f2405 refactor(build): simplify and modularize
simplify:
- use same html file for dart and JS
- build benchmarks automatically when doing `gulp build`
- centralize configuration

modularize:
- move all build tasks into separate node.js modules under
  `tools/build`.

changes:
- the `build` folder is now the `dist` folder

Closes #284
2014-12-05 16:30:36 -08:00

39 lines
1.3 KiB
JavaScript

var util = require('./util');
var path = require('path');
var benchpress = require('angular-benchpress/lib/cli');
var through2 = require('through2');
var Q = require('q');
var path = require('path');
module.exports = function(gulp, plugins, config) {
return function() {
var benchmarkParentFolders = {};
var createBpConfStream = util.streamToPromise(
gulp.src(path.join(config.buildDir, config.mainHtmls))
.pipe(through2.obj(function(file, enc, done) {
file.path = path.join(path.dirname(file.path), config.configFile.name);
file.contents = new Buffer(config.configFile.content);
this.push(file);
benchmarkParentFolders[getParentFolder(file.path)] = true;
done();
}))
.pipe(gulp.dest(config.buildDir)));
return createBpConfStream.then(function() {
return Promise.all(Object.keys(benchmarkParentFolders).map(function(benchmarkParentPath) {
var defer = Q.defer();
benchpress.build({
benchmarksPath: benchmarkParentPath,
buildPath: path.join(benchmarkParentPath, path.join('../', config.outputFolderName))
}, defer.makeNodeResolver());
return defer.promise;
}));
});
};
};
function getParentFolder(file) {
var parts = path.dirname(file).split(path.sep);
parts.pop();
return parts.join(path.sep);
}