Skip to content

Base application plugin for gathering information about files and reporting the results using custom reporters.

License

Notifications You must be signed in to change notification settings

base-repos/base-reporter

Repository files navigation

base-reporter NPM version NPM downloads Build Status

Base application smart plugin for caching data and adding and running custom report functions.

Install

Install with npm:

$ npm install base-reporter --save

Usage

var reporter = require('base-reporter');

API

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.use

Example

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 reporter
  • fn {Function}: report function to run when .reporter.report(name) is called.
  • returns {Object} this: to enable chaining

Example

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 chaining

Example

app.reporter.report('basic', {foo: 'bar'});
//=> file1.js,file2.js,file3.js

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

Generate readme and API documentation with verb:

$ npm install verb && npm run docs

Or, if verb is installed globally:

$ verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Brian Woodward

License

Copyright © 2016, Brian Woodward. Released under the MIT license.


This file was generated by verb, v0.9.0, on June 16, 2016.

About

Base application plugin for gathering information about files and reporting the results using custom reporters.

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  
  •  

Packages

No packages published