Skip to content

Commit

Permalink
Add initial implementation of minigun report (#4)
Browse files Browse the repository at this point in the history
- The command generates a self-contained HTML file with a summary of
  stats from the JSON file.
- HTML is written to minigun_report_xxxxxxx.json.html
- Resulting HTML is opened in user's default browser
  • Loading branch information
hassy committed Aug 7, 2015
1 parent 36ed7e1 commit b174ac2
Show file tree
Hide file tree
Showing 5 changed files with 463 additions and 3 deletions.
5 changes: 5 additions & 0 deletions bin/minigun
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ program
'Set content-type (defaults to application/json)')
.action(commands.quick);

program
.command('report <file>')
.description('Create a report from a JSON file created by "minigun run"')
.action(commands.report);

program
.command('dino')
.description('Show dinosaur of the day')
Expand Down
3 changes: 2 additions & 1 deletion lib/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
module.exports = {
run: require('./run'),
quick: require('./quick'),
dino: require('./dino')
dino: require('./dino'),
report: require('./report')
};
25 changes: 25 additions & 0 deletions lib/commands/report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

var fs = require('fs');
var path = require('path');
var l = require('lodash');
var openfile = require('open');

module.exports = report;

function report(jsonReportPath) {
var data = JSON.parse(fs.readFileSync(jsonReportPath, 'utf-8'));
var templateFn = path.join(
path.dirname(__filename),
'../report/index.html.ejs');
var template = fs.readFileSync(templateFn, 'utf-8');
var compiledTemplate = l.template(template);
var html = compiledTemplate({report: JSON.stringify(data, null, 2)});
var reportFilename = jsonReportPath + '.html';
fs.writeFileSync(
reportFilename,
html,
{encoding: 'utf-8', flag: 'w'});
console.log('Report generated: %s', reportFilename);
openfile(reportFilename);
}

0 comments on commit b174ac2

Please sign in to comment.