mirror of
https://github.com/IonicaBizau/git-stats.git
synced 2024-12-22 13:22:11 +01:00
Instead of reading the json, require
the script
This commit is contained in:
parent
bc36b3e0c8
commit
78a27a6823
1 changed files with 13 additions and 13 deletions
26
lib/index.js
26
lib/index.js
|
@ -23,7 +23,7 @@ const DATE_FORMAT = "MMM D, YYYY"
|
||||||
, DEFAULT_DATA = {
|
, DEFAULT_DATA = {
|
||||||
commits: {}
|
commits: {}
|
||||||
}
|
}
|
||||||
, CONFIG_PATH = Abs("~/.git-stats-config.json")
|
, CONFIG_PATH = Abs("~/.git-stats-config.js")
|
||||||
;
|
;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,7 +66,7 @@ GitStats.DEFAULT_CONFIG = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getConfig
|
* getConfig
|
||||||
* Fetches the configuration object from file (`~/.git-stats-config.json`).
|
* Fetches the configuration object from file (`~/.git-stats-config.js`).
|
||||||
*
|
*
|
||||||
* @name getConfig
|
* @name getConfig
|
||||||
* @function
|
* @function
|
||||||
|
@ -74,20 +74,20 @@ GitStats.DEFAULT_CONFIG = {
|
||||||
* @return {Object|Undefined} If no callback is provided, the configuration object will be returned.
|
* @return {Object|Undefined} If no callback is provided, the configuration object will be returned.
|
||||||
*/
|
*/
|
||||||
GitStats.prototype.getConfig = function (callback) {
|
GitStats.prototype.getConfig = function (callback) {
|
||||||
if (callback) {
|
var data = null;
|
||||||
ReadJson(CONFIG_PATH, function (err, data) {
|
try {
|
||||||
callback(err && err.code !== "ENOENT" ? err : null, data || {});
|
data = require(CONFIG_PATH);
|
||||||
});
|
} catch (err) {
|
||||||
} else {
|
if (err.code !== "MODULE_NOT_FOUND") {
|
||||||
try {
|
if (callback) {
|
||||||
return ReadJson(CONFIG_PATH);
|
return callback(err);
|
||||||
} catch (err) {
|
} else {
|
||||||
if (err.code !== "ENOENT") {
|
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,7 +111,7 @@ GitStats.prototype.initConfig = function (input, callback) {
|
||||||
|
|
||||||
// Handle object input
|
// Handle object input
|
||||||
if (Typpy(input, Object)) {
|
if (Typpy(input, Object)) {
|
||||||
this.config = Ul.deepMerge(this.config, GitStats.DEFAULT_CONFIG);
|
this.config = Ul.deepMerge(input, GitStats.DEFAULT_CONFIG);
|
||||||
callback && callback(null, this.config);
|
callback && callback(null, this.config);
|
||||||
return this.config;
|
return this.config;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue