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.
This commit is contained in:
Ionică Bizău 2015-07-08 10:39:13 +03:00
parent 0750c1e51a
commit e419d6ff87
2 changed files with 13 additions and 14 deletions

View File

@ -1,8 +1,9 @@
// Dependencies // Dependencies
var Ul = require("ul") var Ul = require("ul")
, Fs = require("fs") , Abs = require("abs")
, ReadJson = require("r-json")
, WriteJson = require("w-json")
, Moment = require("moment") , Moment = require("moment")
, CliBox = require("cli-box")
, Couleurs = require("couleurs")() , Couleurs = require("couleurs")()
, Gry = require("gry") , Gry = require("gry")
, IsThere = require("is-there") , IsThere = require("is-there")
@ -11,7 +12,7 @@ var Ul = require("ul")
; ;
// Constants // Constants
const STORE_PATH = Ul.USER_DIR + "/.git-stats" const STORE_PATH = Abs("~/.git-stats")
, DATE_FORMAT = "MMM D, YYYY" , DATE_FORMAT = "MMM D, YYYY"
; ;
@ -83,7 +84,7 @@ GitStats.record = function (data, callback) {
* @return {GitStats} The `GitStats` object. * @return {GitStats} The `GitStats` object.
*/ */
GitStats.get = function (callback) { 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") { if (err && err.code === "ENOENT") {
return GitStats.save({}, function (err) { return GitStats.save({}, function (err) {
@ -92,11 +93,6 @@ GitStats.get = function (callback) {
} }
if (err) { return callback(err); } if (err) { return callback(err); }
try {
data = JSON.parse(data);
} catch (e) {
return callback(e);
}
callback(null, data); callback(null, data);
}); });
return GitStats; return GitStats;
@ -113,7 +109,7 @@ GitStats.get = function (callback) {
* @return {GitStats} The `GitStats` object. * @return {GitStats} The `GitStats` object.
*/ */
GitStats.save = function (stats, callback) { GitStats.save = function (stats, callback) {
Fs.writeFile(STORE_PATH, JSON.stringify(stats, null, 1), callback); WriteJson(STORE_PATH, stats, callback);
return GitStats; return GitStats;
}; };

View File

@ -31,12 +31,15 @@
}, },
"homepage": "https://github.com/IonicaBizau/git-stats", "homepage": "https://github.com/IonicaBizau/git-stats",
"dependencies": { "dependencies": {
"ansi-parser": "^1.4.0", "bug-killer": "^4.0.0",
"bug-killer": "^1.0.0",
"cli-box": "^2.1.1",
"clp": "^3.0.0", "clp": "^3.0.0",
"git-stats-colors": "^1.2.0", "git-stats-colors": "^1.2.0",
"moment": "^2.9.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"
} }
} }