Removed the fs-extra dependency.

This commit is contained in:
Ionică Bizău 2015-02-01 20:05:12 +02:00
parent e61edcd509
commit 94717d98a2

View file

@ -1,6 +1,6 @@
// Dependencies // Dependencies
var FsExtra = require("fs-extra") var Ul = require("ul")
, Ul = require("ul") , Fs = require("fs")
, Moment = require("moment") , Moment = require("moment")
, CliBox = require("cli-box") , CliBox = require("cli-box")
; ;
@ -63,7 +63,7 @@ GitStats.record = function (data, callback) {
} }
if (typeof data.url !== "string" || !data.url) { 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 // Get stats
@ -76,7 +76,7 @@ GitStats.record = function (data, callback) {
repo[data.hash] = { date: data.date }; 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} * @return {undefined}
*/ */
GitStats.get = function (callback) { 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) { GitStats.iterateDays = function (data, callback) {
if (typeof data === "function") { if (typeof data === "function") {