tender-cli
Version:
Command line interface for Tender
89 lines (74 loc) • 2.88 kB
JavaScript
// Generated by CoffeeScript 1.6.2
var CSVFullReporter, Reporter, csv, moment, path, _ref,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
path = require('path');
moment = require('moment');
csv = require('csv');
Reporter = require('../../reporter');
CSVFullReporter = (function(_super) {
__extends(CSVFullReporter, _super);
function CSVFullReporter() {
this.print = __bind(this.print, this);
this.map = __bind(this.map, this); _ref = CSVFullReporter.__super__.constructor.apply(this, arguments);
return _ref;
}
CSVFullReporter.prototype.map = function(callback) {
var created, header, i, key, _i, _len, _ref1;
this.data = [];
header = {};
_ref1 = this.options.data;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
i = _ref1[_i];
created = moment(i.created_at);
this.data.push({
id: i.id,
number: i.number,
title: i.title,
author_name: i.author_name,
author_email: i.author_email,
state: i.state,
age: created.fromNow(true),
"public": i["public"].toString(),
hidden: i.hidden.toString(),
unread: i.unread.toString(),
unresponded: i.unresponded.toString(),
comments_count: i.comments_count.toString(),
watchers_count: i.watchers_count.toString(),
last_user_id: i.last_user_id.toString(),
last_updated_at: i.last_updated_at,
last_via: i.last_via,
last_author_email: i.last_author_email,
last_author_name: i.last_author_name,
href: i.href
});
}
for (key in this.data[0]) {
header[key] = key;
}
this.data.unshift(header);
return callback();
};
CSVFullReporter.prototype.print = function(callback) {
var file, _ref1, _ref2,
_this = this;
if (!this.data) {
return callback();
}
file = ((_ref1 = this.options) != null ? (_ref2 = _ref1.cmdOptions) != null ? _ref2.output : void 0 : void 0) || "tender_output.csv";
return csv().from(this.data).to.path(path.join(process.cwd(), file)).to(function(data) {
return _this.output = data;
}).on('end', function(count) {
if (!_this.options.silent) {
console.log("" + count + " records exported to " + file);
}
return callback();
});
};
return CSVFullReporter;
})(Reporter);
module.exports = function(options, callback) {
return new CSVFullReporter(options, callback);
};
module.exports.description = "Exports csv file with detailed fields";