mirror of
https://github.com/IonicaBizau/git-stats.git
synced 2024-11-14 08:01:15 +01:00
94 lines
2.8 KiB
JavaScript
Executable file
94 lines
2.8 KiB
JavaScript
Executable file
#!/usr/bin/env node
|
|
|
|
// Dependencies
|
|
var GitStats = require("../lib")
|
|
, Fs = require("fs")
|
|
, AnsiParser = require("ansi-parser")
|
|
, Couleurs = require("couleurs")()
|
|
, Logger = require("bug-killer")
|
|
;
|
|
|
|
Logger.config.displayDate = false;
|
|
Logger.config.logLevel = 4;
|
|
|
|
const THEMES = {
|
|
DARK: {
|
|
background: "#11181F"
|
|
, foreground: "#565656"
|
|
, squares: {
|
|
"⬚": Couleurs.fg("▣", "#565656")
|
|
, "▢": Couleurs.fg("▣", "#00B346")
|
|
, "▤": Couleurs.fg("▣", "#009139")
|
|
, "▣": Couleurs.fg("▣", "#15763b")
|
|
, "⬛": Couleurs.fg("▣", "#005220")
|
|
}
|
|
}
|
|
, LIGHT: {
|
|
background: "#ffffff"
|
|
, foreground: "#565656"
|
|
, squares: {
|
|
"⬚": Couleurs.fg("▣", "#C2C2C2")
|
|
, "▢": Couleurs.fg("▣", "#00B346")
|
|
, "▤": Couleurs.fg("▣", "#009139")
|
|
, "▣": Couleurs.fg("▣", "#15763b")
|
|
, "⬛": Couleurs.fg("▣", "#005220")
|
|
}
|
|
}
|
|
};
|
|
|
|
// 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("./docs/help", "utf-8"));
|
|
break;
|
|
case "-v":
|
|
console.log(require("../package.json").version);
|
|
break;
|
|
default:
|
|
GitStats.ansiCalendar(function (err, data) {
|
|
if (err) { return Logger.log(err, "error"); }
|
|
data = AnsiParser.removeAnsi(data);
|
|
if (process.argv.indexOf("--no-ansi") === -1) {
|
|
var theme = THEMES.DARK
|
|
, parsed = AnsiParser.parse(data)
|
|
, i = 0
|
|
, c = null
|
|
, sq = Object.keys(theme.squares)
|
|
;
|
|
|
|
data = data.replace(/╝|╗/gm, "═$&")
|
|
data = data.replace(/║$/gm, " $&")
|
|
if (process.argv.indexOf("--light") !== -1) {
|
|
theme = THEMES.LIGHT;
|
|
}
|
|
|
|
data = data.split("");
|
|
for (; i < data.length; ++i) {
|
|
c = data[i];
|
|
if (sq.indexOf(c) !== -1) {
|
|
data[i] = theme.squares[c];
|
|
} else if (/^(╔|═|╗|║|╝|═|╚|║|\-|\:|[a-z]|[0-9])$/i.test(c)) {
|
|
data[i] = Couleurs.fg(c, theme.foreground);
|
|
}
|
|
}
|
|
|
|
data = data.join("").split("\n").map(function (c) {
|
|
return Couleurs.bg(c, theme.background)
|
|
}).join("\n")
|
|
}
|
|
|
|
console.log(err || data);
|
|
});
|
|
break;
|
|
}
|