mirror of
https://github.com/IonicaBizau/git-stats.git
synced 2024-12-22 13:22:11 +01:00
Read the config file
This commit is contained in:
parent
a2dbe35d26
commit
dfea87a9f4
1 changed files with 28 additions and 3 deletions
31
lib/index.js
31
lib/index.js
|
@ -17,12 +17,37 @@ var Ul = require("ul")
|
|||
;
|
||||
|
||||
// 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) {
|
||||
this.path = Deffy(confPath, Abs("~/.git-stats"));
|
||||
function GitStats(config, data) {
|
||||
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
|
||||
* Records a new commit.
|
||||
|
|
Loading…
Reference in a new issue