From dfea87a9f4fb9e52c36edcddf2b9315b2415bd30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionic=C4=83=20Biz=C4=83u?= Date: Sun, 12 Jul 2015 16:57:43 +0300 Subject: [PATCH] Read the config file --- lib/index.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index 50034f9..4de2d28 100644 --- a/lib/index.js +++ b/lib/index.js @@ -17,12 +17,37 @@ var Ul = require("ul") ; // Constants -const DATE_FORMAT = "MMM D, YYYY"; +const DATE_FORMAT = "MMM D, YYYY" + , DEFAULT_STORE = Abs("~/.git-stats") + , CONFIG_PATH = Abs("~/.git-stats-config.json") + , DEFAULT_CONFIG = {} + ; -function GitStats(confPath) { - this.path = Deffy(confPath, Abs("~/.git-stats")); +function GitStats(config, data) { + var self = this; + this.config_path = null; + + if (typeof config === "object") { + self.config = config; + } else { + this.config_path = Deffy(confPath, CONFIG_PATH) + self.config = this.getConfig(); + } + + this.path = Deffy(confPath, DEFAULT_STORE); } +GitStats.prototype.getConfig = function () { + try { + return ReadJson(this.config_path); + } catch (err) { + if (err.code === "ENOENT") { + return DEFAULT_CONFIG; + } + throw err; + } +}; + /** * record * Records a new commit.