mirror of
https://github.com/IonicaBizau/git-stats.git
synced 2024-11-16 00:48:34 +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 = {
|
||||
commits: {}
|
||||
}
|
||||
, CONFIG_PATH = Abs("~/.git-stats-config.json")
|
||||
, CONFIG_PATH = Abs("~/.git-stats-config.js")
|
||||
;
|
||||
|
||||
/**
|
||||
|
@ -66,7 +66,7 @@ GitStats.DEFAULT_CONFIG = {
|
|||
|
||||
/**
|
||||
* getConfig
|
||||
* Fetches the configuration object from file (`~/.git-stats-config.json`).
|
||||
* Fetches the configuration object from file (`~/.git-stats-config.js`).
|
||||
*
|
||||
* @name getConfig
|
||||
* @function
|
||||
|
@ -74,20 +74,20 @@ GitStats.DEFAULT_CONFIG = {
|
|||
* @return {Object|Undefined} If no callback is provided, the configuration object will be returned.
|
||||
*/
|
||||
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") {
|
||||
var data = null;
|
||||
try {
|
||||
data = require(CONFIG_PATH);
|
||||
} catch (err) {
|
||||
if (err.code !== "MODULE_NOT_FOUND") {
|
||||
if (callback) {
|
||||
return callback(err);
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -111,7 +111,7 @@ GitStats.prototype.initConfig = function (input, callback) {
|
|||
|
||||
// Handle object input
|
||||
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);
|
||||
return this.config;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue