tender-cli
Version:
Command line interface for Tender
75 lines (60 loc) • 2.28 kB
JavaScript
// Generated by CoffeeScript 1.6.2
var CSVReporter, 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');
CSVReporter = (function(_super) {
__extends(CSVReporter, _super);
function CSVReporter() {
this.print = __bind(this.print, this);
this.map = __bind(this.map, this); _ref = CSVReporter.__super__.constructor.apply(this, arguments);
return _ref;
}
CSVReporter.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({
number: i.number,
title: i.title,
author_name: i.author_name,
state: i.state,
age: created.fromNow(true)
});
}
for (key in this.data[0]) {
header[key] = key;
}
this.data.unshift(header);
return callback();
};
CSVReporter.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 CSVReporter;
})(Reporter);
module.exports = function(options, callback) {
return new CSVReporter(options, callback);
};
module.exports.description = "Exports csv file with minimal fields";