Added the record and get function.

This commit is contained in:
Ionică Bizău 2015-01-25 21:54:02 +02:00
parent e14f250a0e
commit a84cc75120
1 changed files with 17 additions and 2 deletions

View File

@ -3,9 +3,24 @@ var FsExtra = require("fs-extra")
, Ul = require("ul")
;
const STORE_PATH = Ul.USER_DIR + "/.git-stats";
// Constructor
var GitStats = module.exports = {};
GitStats.record = function (data) {
console.log(data);
GitStats.record = function (data, callback) {
FsExtra.readJSON(STORE_PATH, function (err, stats) {
stats = stats || {};
var thisRepo = stats[data.url] = Object(stats[data.url]);
thisRepo[data.hash] = { date: data.date };
FsExtra.writeJSON(STORE_PATH, stats, callback);
});
};
GitStats.get = function (data, callback) {
if (typeof data === "function") {
callback = data;
data = {};
}
FsExtra.readJSON(STORE_PATH, callback);
};