Fixed #2. Check if the file is not found. If so, create it.

This commit is contained in:
Ionică Bizău 2015-02-10 09:41:13 +02:00
parent c70ecec82e
commit 093ce0d9ce
1 changed files with 7 additions and 0 deletions

View File

@ -95,6 +95,13 @@ GitStats.record = function (data, callback) {
*/
GitStats.get = function (callback) {
Fs.readFile(STORE_PATH, "utf-8", function (err, data) {
if (err && err.code === "ENOENT") {
return GitStats.save({}, function (err) {
callback(err, {});
});
}
if (err) { return callback(err); }
try {
data = JSON.parse(data);