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 = { , 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) {
callback(err && err.code !== "ENOENT" ? err : null, data || {});
});
} else {
try { try {
return ReadJson(CONFIG_PATH); data = require(CONFIG_PATH);
} catch (err) { } catch (err) {
if (err.code !== "ENOENT") { if (err.code !== "MODULE_NOT_FOUND") {
if (callback) {
return callback(err);
} else {
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;
} }