Instead of reading the json, require the script

This commit is contained in:
Ionică Bizău 2015-11-01 12:40:01 +02:00
parent bc36b3e0c8
commit 78a27a6823

View file

@ -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;
}