0.3.3 • Published 5 years ago

hekla-plugin-csv-reporter v0.3.3

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

hekla-plugin-csv-reporter

A Hekla plugin to report analysis through CSV files

Usage

Install the package into your project:

npm install --save-dev hekla-plugin-csv-reporter

Then add it to your hekla.config.js file, with configuration:

const CSVReporterPlugin = require('hekla-plugin-csv-reporter');

module.exports = {
  // ...
  plugins: [
    // ...
    new CSVReporterPlugin({
      destination: '/path/to/output.csv',
      headers: [
        'file',
        'myProperty',
        'myOtherProperty'
      ],
      moduleToRows: (module) => ([
        [
          module.name,
          module.myProperty,
          module.myOtherProperty
        ]
      ])
    })
  ]
};

Usage with list properties

Suppose you track a list of items for each module, like this example:

{
  "modules": [
    {
      "name": "./common/components/AppWrapper.js",
      "shortName": "AppWrapper.js",
      "nativeElements": [
        "div",
        "footer",
        "h1",
        "header",
        "main"
      ]
    }
    {
      "name": "./my-feature/components/ContactForm.js",
      "shortName": "ContactForm.js",
      "nativeElements": [
        "button",
        "div",
        "input",
        "span",
        "textarea"
      ]
    },
  ]
}

You could create a row for each item in the module, with a hekla.config.js configuration like this:

const CSVReporterPlugin = require('hekla-plugin-csv-reporter');

module.exports = {
  // ...
  plugins: [
    // ...
    new CSVReporterPlugin({
      destination: '/path/to/output.csv',
      headers: [
        'file',
        'nativeElement'
      ],
      moduleToRows: (module) =>
        module.nativeElements
          .map(nativeElement => ([module.name, nativeElement]))
    })
  ]
};

This would create the following data in output.csv:

filenativeElement
./common/components/AppWrapper.jsdiv
./common/components/AppWrapper.jsfooter
./common/components/AppWrapper.jsh1
./common/components/AppWrapper.jsheader
./common/components/AppWrapper.jsmain
./my-feature/components/ContactForm.jsbutton
./my-feature/components/ContactForm.jsdiv
./my-feature/components/ContactForm.jsinput
./my-feature/components/ContactForm.jsspan
./my-feature/components/ContactForm.jstextarea