mirror of
https://github.com/IonicaBizau/git-stats.git
synced 2025-01-03 10:22:11 +01:00
Add the raw option
This commit is contained in:
parent
12948c4d66
commit
e8b643a718
2 changed files with 31 additions and 19 deletions
|
@ -39,6 +39,7 @@ var recordOpt = new Clp.Option(["record"], "Records a new commit. Don't use this
|
||||||
, dataPathOpt = new Clp.Option(["d", "data"], "Sets a custom data store file.", "path", GitStats.config.path)
|
, dataPathOpt = new Clp.Option(["d", "data"], "Sets a custom data store file.", "path", GitStats.config.path)
|
||||||
, globalActivityOpt = new Clp.Option(["g", "global-activity"], "Shows global activity calendar in the current repository.")
|
, globalActivityOpt = new Clp.Option(["g", "global-activity"], "Shows global activity calendar in the current repository.")
|
||||||
, firstDayOpt = new Clp.Option(["f", "first-day"], "Sets the first day of the week.", "day", GitStats.config.first_day)
|
, firstDayOpt = new Clp.Option(["f", "first-day"], "Sets the first day of the week.", "day", GitStats.config.first_day)
|
||||||
|
, rawOpt = new Clp.Option(["r", "raw"], "Outputs a dump of the raw JSON data.")
|
||||||
, parser = new Clp({
|
, parser = new Clp({
|
||||||
name: "Git Stats"
|
name: "Git Stats"
|
||||||
, version: Package.version
|
, version: Package.version
|
||||||
|
@ -102,6 +103,7 @@ if (recordOpt.is_provided) {
|
||||||
options = {
|
options = {
|
||||||
start: sinceDateOpt.value ? Moment(sinceDateOpt.value) : Moment().subtract(1, "years")
|
start: sinceDateOpt.value ? Moment(sinceDateOpt.value) : Moment().subtract(1, "years")
|
||||||
, end: untilDateOpt.value ? Moment(untilDateOpt.value) : Moment()
|
, end: untilDateOpt.value ? Moment(untilDateOpt.value) : Moment()
|
||||||
|
, raw: rawOpt.is_provided
|
||||||
};
|
};
|
||||||
|
|
||||||
// Validate the dates
|
// Validate the dates
|
||||||
|
@ -153,5 +155,6 @@ if (globalActivityOpt.is_provided) {
|
||||||
return GitStats.globalActivity(options, display);
|
return GitStats.globalActivity(options, display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Show the graphs
|
// Show the graphs
|
||||||
GitStats[authorsOpt.is_provided ? "authorsPie" : "ansiCalendar"](options, display);
|
GitStats[authorsOpt.is_provided ? "authorsPie" : "ansiCalendar"](options, display);
|
||||||
|
|
47
lib/index.js
47
lib/index.js
|
@ -459,34 +459,38 @@ GitStats.prototype.calendar = function (data, callback) {
|
||||||
*
|
*
|
||||||
* @name ansiCalendar
|
* @name ansiCalendar
|
||||||
* @function
|
* @function
|
||||||
* @param {Object} data The object passed to the `calendar` method.
|
* @param {Object} options The object passed to the `calendar` method.
|
||||||
* @param {Function} callback The callback function.
|
* @param {Function} callback The callback function.
|
||||||
* @return {GitStats} The `GitStats` instance.
|
* @return {GitStats} The `GitStats` instance.
|
||||||
*/
|
*/
|
||||||
GitStats.prototype.ansiCalendar = function (data, callback) {
|
GitStats.prototype.ansiCalendar = function (options, callback) {
|
||||||
|
|
||||||
if (typeof data === "function") {
|
if (typeof options === "function") {
|
||||||
callback = data;
|
callback = options;
|
||||||
data = undefined;
|
options = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
self.graph(data, function (err, graph) {
|
self.graph(options, function (err, graph) {
|
||||||
var cal = [];
|
var cal = []
|
||||||
|
, data = {
|
||||||
|
theme: options.theme
|
||||||
|
, start: options.start
|
||||||
|
, end: options.end
|
||||||
|
, firstDay: options.firstDay
|
||||||
|
, cal: cal
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
self.iterateDays(data, function (cDay) {
|
self.iterateDays(options, function (cDay) {
|
||||||
cDayObj = graph[cDay];
|
cDayObj = graph[cDay];
|
||||||
if (!cDayObj) { return; }
|
if (!cDayObj) { return; }
|
||||||
cal.push([cDay, cDayObj.c]);
|
cal.push([cDay, cDayObj.c]);
|
||||||
});
|
});
|
||||||
|
|
||||||
callback(null, CliGhCal(cal, {
|
|
||||||
theme: data.theme
|
callback(null, options.raw ? data : CliGhCal(cal, data));
|
||||||
, start: data.start
|
|
||||||
, end: data.end
|
|
||||||
, firstDay: data.firstDay
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
@ -535,6 +539,7 @@ GitStats.prototype.authors = function (options, callback) {
|
||||||
* - `repo` (String): The repository path.
|
* - `repo` (String): The repository path.
|
||||||
* - `radius` (Number): The pie radius.
|
* - `radius` (Number): The pie radius.
|
||||||
* - `no_ansi` (Boolean): If `true`, the pie will not contain ansi characters.
|
* - `no_ansi` (Boolean): If `true`, the pie will not contain ansi characters.
|
||||||
|
* - `raw` (Boolean): If `true`, the raw JSON will be displayed.
|
||||||
*
|
*
|
||||||
* @param {Function} callback The callback function.
|
* @param {Function} callback The callback function.
|
||||||
* @return {GitStats} The `GitStats` instance.
|
* @return {GitStats} The `GitStats` instance.
|
||||||
|
@ -574,13 +579,14 @@ GitStats.prototype.authorsPie = function (options, callback) {
|
||||||
authors.push(others);
|
authors.push(others);
|
||||||
}
|
}
|
||||||
|
|
||||||
pie = new CliPie(options.radius, authors, {
|
var data = {
|
||||||
legend: true
|
legend: true
|
||||||
, flat: true
|
, flat: true
|
||||||
, no_ansi: options.no_ansi
|
, no_ansi: options.no_ansi
|
||||||
});
|
, authors: authors
|
||||||
|
};
|
||||||
|
|
||||||
callback(null, pie.toString());
|
callback(null, options.raw ? data : new CliPie(options.radius, authors, data).toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
@ -598,6 +604,7 @@ GitStats.prototype.authorsPie = function (options, callback) {
|
||||||
* - `start` (String): The start date.
|
* - `start` (String): The start date.
|
||||||
* - `end` (String): The end date.
|
* - `end` (String): The end date.
|
||||||
* - `theme` (String|Object): The calendar theme.
|
* - `theme` (String|Object): The calendar theme.
|
||||||
|
* - `raw` (Boolean): If `true`, the raw JSON will be displayed.
|
||||||
*
|
*
|
||||||
* @param {Function} callback The callback function.
|
* @param {Function} callback The callback function.
|
||||||
* @return {GitStats} The `GitStats` instance.
|
* @return {GitStats} The `GitStats` instance.
|
||||||
|
@ -632,11 +639,13 @@ GitStats.prototype.globalActivity = function (options, callback) {
|
||||||
Object.keys(commits).forEach(function (c) {
|
Object.keys(commits).forEach(function (c) {
|
||||||
cal.push([c, commits[c]])
|
cal.push([c, commits[c]])
|
||||||
});
|
});
|
||||||
callback(null, CliGhCal(cal, {
|
var data = {
|
||||||
theme: options.theme
|
theme: options.theme
|
||||||
, start: options.start
|
, start: options.start
|
||||||
, end: options.end
|
, end: options.end
|
||||||
}));
|
, cal: cal
|
||||||
|
};
|
||||||
|
callback(null, options.raw ? data : CliGhCal(cal, data));
|
||||||
});
|
});
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
Loading…
Reference in a new issue