mirror of
https://github.com/IonicaBizau/git-stats.git
synced 2025-01-03 10:22:11 +01:00
82 lines
2.3 KiB
JavaScript
Executable file
82 lines
2.3 KiB
JavaScript
Executable file
#!/usr/bin/env node
|
|
|
|
// Dependencies
|
|
var GitStats = require("../lib")
|
|
, Moment = require("moment")
|
|
, Fs = require("fs")
|
|
, AnsiParser = require("ansi-parser")
|
|
, Logger = require("bug-killer")
|
|
, GitStatsColors = require("git-stats-colors")
|
|
;
|
|
|
|
// Configurations
|
|
Logger.config.displayDate = false;
|
|
Logger.config.logLevel = 4;
|
|
Moment.suppressDeprecationWarnings = true;
|
|
|
|
// CLI options
|
|
switch (process.argv[2]) {
|
|
case "--record":
|
|
var data = process.argv[3].replace(/^\"|\"$/g, "");
|
|
data = JSON.parse(data);
|
|
|
|
GitStats.record(data, function (err) {
|
|
if (err) { return Logger.log(err, "error"); }
|
|
});
|
|
break;
|
|
case "--help":
|
|
case "-h":
|
|
console.log(Fs.readFileSync(__dirname + "/docs/help", "utf-8"));
|
|
break;
|
|
case "-v":
|
|
console.log(require("../package.json").version);
|
|
break;
|
|
default:
|
|
var options = {
|
|
theme: "DARK"
|
|
}
|
|
, parameter
|
|
, i
|
|
;
|
|
|
|
// iterate over all parameters and assign them in options object
|
|
for (i = 2; i < process.argv.length; i++) {
|
|
parameter = process.argv[i];
|
|
// does the parameter represent a date?
|
|
if (Moment(parameter).isValid()) {
|
|
// the date is end date if start date is set
|
|
if (options.start) {
|
|
options.end = Moment(parameter);
|
|
} else {
|
|
options.start = Moment(parameter);
|
|
}
|
|
} else if (parameter == "--light") {
|
|
// change theme
|
|
options.theme = "LIGHT";
|
|
} else if (parameter == "--no-ansi") {
|
|
// request no-ansi
|
|
options.noansi = true;
|
|
}
|
|
}
|
|
|
|
|
|
if (!options.start || !options.start.isValid()) {
|
|
options.start = Moment().subtract(1, "years");
|
|
}
|
|
|
|
if (!options.end || !options.end.isValid()) {
|
|
options.end = Moment();
|
|
}
|
|
|
|
GitStats.ansiCalendar(options, function (err, data) {
|
|
if (err) { return Logger.log(err, "error"); }
|
|
|
|
data = AnsiParser.removeAnsi(data);
|
|
if (!options.noansi) {
|
|
data = GitStatsColors(data, options.theme);
|
|
}
|
|
|
|
console.log(err || data);
|
|
});
|
|
break;
|
|
}
|