From a84cc75120b3274e52b7f8ad8922533c3b865715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionic=C4=83=20Biz=C4=83u?= Date: Sun, 25 Jan 2015 21:54:02 +0200 Subject: [PATCH] Added the record and get function. --- lib/index.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 3aaecf4..b5d7911 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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); };