description and source-codefunction Bro(bundleFile) {
var log;
function addBundleFile(bundleFile, config) {
var files = config.files,
preprocessors = config.preprocessors;
// list of patterns using our preprocessor
var patterns = reduce(preprocessors, function(matched, val, key) {
if (val.indexOf('browserify') !== -1) {
matched.push(key);
}
return matched;
}, []);
// first file being preprocessed
var file = find(files, function(f) {
return any(patterns, function(p) {
return minimatch(f.pattern, p);
});
});
var idx = 0;
if (file) {
idx = files.indexOf(file);
} else {
log.debug('no matching preprocessed file was found, defaulting to prepend');
}
log.debug('add bundle to config.files at position', idx);
// insert bundle on the correct spot
files.splice(idx, 0, {
pattern: bundleFile.location,
served: true,
included: true,
watched: true
});
}
/**
* The browserify instance that creates the
* minified bundle and gets added all test files to it.
*/
var b;
/**
* The browserify framework that creates the initial logger and bundle file
* as well as prepends the bundle file to the karma file configuration.
*/
function framework(emitter, config, logger) {
log = logger.create('framework.browserify');
if (!bundleFile) {
bundleFile = new BundleFile();
}
bundleFile.touch();
log.debug('created browserify bundle: %s', bundleFile.location);
b = createBundle(config);
// TODO(Nikku): hook into karma karmas file update facilities
// to remove files from the bundle once karma detects the deletion
// hook into exit for cleanup
emitter.on('exit', function(done) {
log.debug('cleaning up');
if (b.close) {
b.close();
}
bundleFile.remove();
done();
});
// add bundle file to the list of files defined in the
// configuration. be smart by doing so.
addBundleFile(bundleFile, config);
return b;
}
framework.$inject = [ 'emitter', 'config', 'logger' ];
/**
* Create the browserify bundle
*/
function createBundle(config) {
var bopts = config.browserify || {},
bundleDelay = bopts.bundleDelay || DEFAULT_BUNDLE_DELAY,
requireName = bopts.externalRequireName || 'require';
function warn(key) {
log.warn('Invalid config option: "' + key + 's" should be "' + key + '"');
}
forEach([ 'transform', 'plugin' ], function(key) {
if (bopts[key + 's']) {
warn(key);
}
});
var browserifyOptions = assign({
basedir: path.resolve(config.basePath),
// watchify.args
cache: {},
packageCache: {}
}, omit(bopts, [
'transform', 'plugin', 'configure', 'bundleDelay'
]));
if ('prebundle' in browserifyOptions) {
log.warn('The prebundle hook got removed in favor of configure');
}
if ('watchify' in browserifyOptions) {
log.warn('Configure watchify via config.watchify');
}
var w = browserify(browserifyOptions);
w.setMaxListeners(Infinity);
forEach(bopts.plugin, function(p) {
// ensure we can pass plugin options as
// the first parameter
if (!Array.isArray(p)) {
p = [ p ];
}
w.plugin.apply(w, p);
});
forEach(bopts.transform, function(t) {
// ensure we can pass transform options as
// the first parameter
if (!Array.isArray(t)) {
t = [ t ];
}
w.transform.apply(w, t);
});
// test if we have a configure function
if (bopts.configure && typeof bopts.configure ...