From 093ce0d9ce41d2e1539ab5bff3e6742b6d082d63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionic=C4=83=20Biz=C4=83u?= Date: Tue, 10 Feb 2015 09:41:13 +0200 Subject: [PATCH] Fixed #2. Check if the file is not found. If so, create it. --- lib/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/index.js b/lib/index.js index de8e210..bc7c436 100644 --- a/lib/index.js +++ b/lib/index.js @@ -95,6 +95,13 @@ GitStats.record = function (data, callback) { */ GitStats.get = function (callback) { Fs.readFile(STORE_PATH, "utf-8", function (err, data) { + + if (err && err.code === "ENOENT") { + return GitStats.save({}, function (err) { + callback(err, {}); + }); + } + if (err) { return callback(err); } try { data = JSON.parse(data);