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
1 changed files with 17 additions and 5 deletions

View File

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