Base application smart plugin for caching data and adding and running custom report functions.
Install with npm:
$ npm install base-reporter --save
var reporter = require('base-reporter');
Exposes smart plugin for adding a reporter instance to a base application.
Params
config {Object}: Configuration object.returns {Function}: Plugin function to use with app.useExample
app.use(reporter());
Creates a middleware function that can be used with application middleware methods.
Params
fn {String|Function}: Pass a property string or function that will create a middleware function. Defaults to files.returns {Function}: Function that can be used as a middleware function.Example
// Default middleware will cache all files on the `reporter.files` array (can be accessed in report functions):
app.preWrite(/./, app.reporter.middleware());
// Pass a custom property string to cache files on another property:
app.preWrite(/./, app.reporter.middleware('templates'));
// Pass a custom function that creates the middleware function. The function will take the reporter instance:
app.preWrite(/./, app.reporter.middleware(function(reporter) {
var counter = 0;
return function(file, next) {
reporter.union('files', file);
reporter.set('counter', ++counter);
next():
};
}));
Add a report function to the reporter with the given name. Function may take the reporter instance and options as parameters.
Params
name {String}: Name of the reporterfn {Function}: report function to run when .reporter.report(name) is called.returns {Object} this: to enable chainingExample
app.reporter.add('basic', function(reporter, options) {
console.log(this.files);
});
Run a registered report function with the given options.
Params
name {String}: Name of the report to run.returns {Object} this: to enable chainingExample
app.reporter.report('basic', {foo: 'bar'});
//=> file1.js,file2.js,file3.js
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Generate readme and API documentation with verb:
$ npm install verb && npm run docs
Or, if verb is installed globally:
$ verb
Install dev dependencies:
$ npm install -d && npm test
Brian Woodward
Copyright © 2016, Brian Woodward. Released under the MIT license.
This file was generated by verb, v0.9.0, on June 16, 2016.