2015-04-02 22:53:11 -04:00
|
|
|
var gulp = require('gulp');
|
|
|
|
var concat = require('gulp-concat');
|
|
|
|
var replace = require('gulp-replace');
|
|
|
|
var insert = require('gulp-insert');
|
2015-06-23 18:26:51 -04:00
|
|
|
var fs = require('fs-extra');
|
|
|
|
var browserify = require('browserify');
|
|
|
|
var path = require('path');
|
2015-09-11 19:00:26 -04:00
|
|
|
var Builder = require('systemjs-builder');
|
2015-04-02 22:53:11 -04:00
|
|
|
|
2015-04-13 19:48:04 -04:00
|
|
|
module.exports.bundle = function(buildConfig, moduleName, outputFile, outputConfig,
|
|
|
|
sfx) {
|
|
|
|
var sfx = sfx || false;
|
2015-03-23 16:18:05 -04:00
|
|
|
var builder = new Builder();
|
|
|
|
builder.config(buildConfig);
|
2015-04-13 19:48:04 -04:00
|
|
|
if (sfx) {
|
|
|
|
return builder.buildSFX(moduleName, outputFile, outputConfig);
|
|
|
|
} else {
|
|
|
|
return builder.build(moduleName, outputFile, outputConfig);
|
|
|
|
}
|
2015-06-29 14:28:23 -04:00
|
|
|
};
|
2015-04-02 22:53:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
module.exports.modify = function(srcs, concatName) {
|
|
|
|
return gulp.src(srcs)
|
|
|
|
.pipe(concat(concatName))
|
|
|
|
.pipe(replace('sourceMappingURL', 'sourceMappingURLDisabled')) // TODO: add concat for sourceMaps
|
2015-06-29 14:28:23 -04:00
|
|
|
};
|
2015-06-23 18:26:51 -04:00
|
|
|
|
|
|
|
|
|
|
|
module.exports.benchpressBundle = function(entries, packageJsonPath, includes, excludes, ignore, dest, cb) {
|
|
|
|
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();
|
|
|
|
|
|
|
|
contents += 'module.exports = global.__benchpressExports;\n';
|
|
|
|
fs.writeFileSync(dest + '/index.js', contents);
|
|
|
|
cb(null);
|
|
|
|
});
|
2015-06-29 14:28:23 -04:00
|
|
|
};
|