From 78a27a6823843b250f973b3ed8da1e1f6fac9dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionic=C4=83=20Biz=C4=83u?= Date: Sun, 1 Nov 2015 12:40:01 +0200 Subject: [PATCH] Instead of reading the json, `require` the script --- lib/index.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/index.js b/lib/index.js index 571493e..4a46900 100644 --- a/lib/index.js +++ b/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; }