From e419d6ff876dc8541422a3fc8f752a1226d3b0c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionic=C4=83=20Biz=C4=83u?= Date: Wed, 8 Jul 2015 10:39:13 +0300 Subject: [PATCH] New dependencies: r-json, w-json, abs Use r-json to read json files, w-json to write json files and abs to find the absolute path to the file. --- lib/index.js | 16 ++++++---------- package.json | 11 +++++++---- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/index.js b/lib/index.js index a006e13..8c69194 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,8 +1,9 @@ // Dependencies var Ul = require("ul") - , Fs = require("fs") + , Abs = require("abs") + , ReadJson = require("r-json") + , WriteJson = require("w-json") , Moment = require("moment") - , CliBox = require("cli-box") , Couleurs = require("couleurs")() , Gry = require("gry") , IsThere = require("is-there") @@ -11,7 +12,7 @@ var Ul = require("ul") ; // Constants -const STORE_PATH = Ul.USER_DIR + "/.git-stats" +const STORE_PATH = Abs("~/.git-stats") , DATE_FORMAT = "MMM D, YYYY" ; @@ -83,7 +84,7 @@ GitStats.record = function (data, callback) { * @return {GitStats} The `GitStats` object. */ GitStats.get = function (callback) { - Fs.readFile(STORE_PATH, "utf-8", function (err, data) { + ReadJson(STORE_PATH, "utf-8", function (err, data) { if (err && err.code === "ENOENT") { return GitStats.save({}, function (err) { @@ -92,11 +93,6 @@ GitStats.get = function (callback) { } if (err) { return callback(err); } - try { - data = JSON.parse(data); - } catch (e) { - return callback(e); - } callback(null, data); }); return GitStats; @@ -113,7 +109,7 @@ GitStats.get = function (callback) { * @return {GitStats} The `GitStats` object. */ GitStats.save = function (stats, callback) { - Fs.writeFile(STORE_PATH, JSON.stringify(stats, null, 1), callback); + WriteJson(STORE_PATH, stats, callback); return GitStats; }; diff --git a/package.json b/package.json index 7a2bb1b..eb3340e 100644 --- a/package.json +++ b/package.json @@ -31,12 +31,15 @@ }, "homepage": "https://github.com/IonicaBizau/git-stats", "dependencies": { - "ansi-parser": "^1.4.0", - "bug-killer": "^1.0.0", - "cli-box": "^2.1.1", + "bug-killer": "^4.0.0", "clp": "^3.0.0", "git-stats-colors": "^1.2.0", "moment": "^2.9.0", - "ul": "^2.1.0" + "ul": "^5.0.0", + "r-json": "^1.0.0", + "w-json": "^1.0.0", + "is-there": "^4.0.0", + "cli-pie": "^2.0.0", + "cli-gh-cal": "^1.0.0" } }