Read the config file

This commit is contained in:
Ionică Bizău 2015-07-12 16:57:43 +03:00
parent a2dbe35d26
commit dfea87a9f4

View file

@ -17,12 +17,37 @@ var Ul = require("ul")
; ;
// Constants // Constants
const DATE_FORMAT = "MMM D, YYYY"; const DATE_FORMAT = "MMM D, YYYY"
, DEFAULT_STORE = Abs("~/.git-stats")
, CONFIG_PATH = Abs("~/.git-stats-config.json")
, DEFAULT_CONFIG = {}
;
function GitStats(confPath) { function GitStats(config, data) {
this.path = Deffy(confPath, Abs("~/.git-stats")); var self = this;
this.config_path = null;
if (typeof config === "object") {
self.config = config;
} else {
this.config_path = Deffy(confPath, CONFIG_PATH)
self.config = this.getConfig();
}
this.path = Deffy(confPath, DEFAULT_STORE);
} }
GitStats.prototype.getConfig = function () {
try {
return ReadJson(this.config_path);
} catch (err) {
if (err.code === "ENOENT") {
return DEFAULT_CONFIG;
}
throw err;
}
};
/** /**
* record * record
* Records a new commit. * Records a new commit.