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") {