mirror of
https://github.com/IonicaBizau/git-stats.git
synced 2024-12-22 05:12:11 +01:00
Added the getConfig and initConfig methods
This commit is contained in:
parent
7865ddcbcc
commit
f28e390309
1 changed files with 45 additions and 0 deletions
45
lib/index.js
45
lib/index.js
|
@ -35,6 +35,7 @@ const DATE_FORMAT = "MMM D, YYYY"
|
|||
*/
|
||||
function GitStats(dataPath) {
|
||||
this.path = Abs(Deffy(dataPath, DEFAULT_STORE));
|
||||
this.config = {};
|
||||
}
|
||||
|
||||
// Defaults
|
||||
|
@ -66,6 +67,50 @@ GitStats.DEFAULT_CONFIG = {
|
|||
, global_activity: false
|
||||
};
|
||||
|
||||
GitStats.prototype.getConfig = function (callback) {
|
||||
if (callback) {
|
||||
ReadJson(CONFIG_PATH, function (err, data) {
|
||||
callback(err && err.code !== "ENOENT" ? err : null, data || {});
|
||||
});
|
||||
} else {
|
||||
try {
|
||||
return ReadJson(CONFIG_PATH);
|
||||
} catch (err) {
|
||||
if (err.code !== "ENOENT") {
|
||||
throw err;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GitStats.prototype.initConfig = function (input, callback) {
|
||||
|
||||
var self = this;
|
||||
if (Typpy(input, Function)) {
|
||||
callback = input;
|
||||
input = null;
|
||||
}
|
||||
|
||||
input = input || CONFIG_PATH;
|
||||
|
||||
// Handle object input
|
||||
if (Typpy(input, Object)) {
|
||||
this.config = Ul.deepMerge(this.config, GitStats.DEFAULT_CONFIG);
|
||||
callback && callback(null, this.config);
|
||||
return this.config;
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
this.getConfig(function (err, data) {
|
||||
if (err) { return callback(err); }
|
||||
self.initConfig(data, callback);
|
||||
});
|
||||
} else {
|
||||
this.initConfig(this.getConfig());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* record
|
||||
* Records a new commit.
|
||||
|
|
Loading…
Reference in a new issue