From 94717d98a2412191ab0a8f1eb34848af453ed097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionic=C4=83=20Biz=C4=83u?= Date: Sun, 1 Feb 2015 20:05:12 +0200 Subject: [PATCH] Removed the fs-extra dependency. --- lib/index.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/index.js b/lib/index.js index 0def27c..e2417ed 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,6 @@ // Dependencies -var FsExtra = require("fs-extra") - , Ul = require("ul") +var Ul = require("ul") + , Fs = require("fs") , Moment = require("moment") , CliBox = require("cli-box") ; @@ -63,7 +63,7 @@ GitStats.record = function (data, callback) { } if (typeof data.url !== "string" || !data.url) { - return callback(new Error("Invalid url field.")); + return callback(new Error("Invalid url field. This commit is not recorded into the git-stats history since you didn't added the remote url. You can import the previous commits using the git-stats-importer tool.")); } // Get stats @@ -76,7 +76,7 @@ GitStats.record = function (data, callback) { repo[data.hash] = { date: data.date }; - FsExtra.writeJSON(STORE_PATH, stats, callback); + GitStats.save(stats, callback); }); }; @@ -90,9 +90,21 @@ GitStats.record = function (data, callback) { * @return {undefined} */ GitStats.get = function (callback) { - FsExtra.readJSON(STORE_PATH, callback); + Fs.readFile(STORE_PATH, "utf-8", function (err, data) { + if (err) { return callback(err); } + try { + data = JSON.parse(data); + } catch (e) { + return callback(e); + } + callback(null, data); + }); }; +GitStats.save = function (stats, callback) { + Fs.writeFile(STORE_PATH, JSON.stringify(stats, null, 1), callback); +} + GitStats.iterateDays = function (data, callback) { if (typeof data === "function") {