mirror of
https://github.com/IonicaBizau/git-stats.git
synced 2024-12-22 21:32:10 +01:00
68 lines
1.8 KiB
JavaScript
Executable file
68 lines
1.8 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, "");
|
|
try {
|
|
data = JSON.parse(data);
|
|
} catch (e) {
|
|
throw e;
|
|
}
|
|
GitStats.record(data, function (err) {
|
|
if (err) { return Logger.log(err, "error"); }
|
|
});
|
|
break;
|
|
case "--help":
|
|
console.log(Fs.readFileSync(__dirname + "/docs/help", "utf-8"));
|
|
break;
|
|
case "-v":
|
|
console.log(require("../package.json").version);
|
|
break;
|
|
default:
|
|
var options = {};
|
|
|
|
if (process.argv.length !== 2) {
|
|
if (process.argv[2]) {
|
|
options.start = Moment(process.argv[2]);
|
|
|
|
}
|
|
|
|
if (process.argv[3]) {
|
|
options.end = Moment(process.argv[3]);
|
|
}
|
|
}
|
|
|
|
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 (process.argv.indexOf("--no-ansi") === -1) {
|
|
data = GitStatsColors(data, process.argv.indexOf("--light") !== -1 ? "LIGHT": "DARK");
|
|
}
|
|
|
|
console.log(err || data);
|
|
});
|
|
break;
|
|
}
|