karma-preprocess-preprocessor
Version:
A Karma plugin. Preprocess a file using preprocess.
45 lines (32 loc) • 1.06 kB
JavaScript
var fs = require('fs');
var pp = require('preprocess');
function preprocessPreprocessor(args, config, helper) {
return function(content, file, done) {
config = config || {};
var options = helper.merge({}, config.options, args.options);
var context = config.context;
if (typeof context === 'string') {
return fs.readFile(context, 'utf8', function(err, data) {
if (err) {
return console.log(err);
}
var context = JSON.parse(data);
preprocess(content, context, options);
});
} else if (typeof context === 'function') {
context = context();
}
preprocess(content, context, options);
function preprocess(content, context, options) {
options = helper.merge({
type: 'js'
}, options);
done(pp.preprocess(content, context, options));
}
};
}
preprocessPreprocessor.$inject = ['args', 'config.preprocessPreprocessor', 'helper'];
module.exports = {
'preprocessor:preprocess': ['factory', preprocessPreprocessor]
};
;