From fbb565c0c1c732ba4f8163124fdad3f42c8b86a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionic=C4=83=20Biz=C4=83u?= Date: Mon, 13 Jul 2015 08:36:48 +0300 Subject: [PATCH] Added the migration script to 2.x.x --- package.json | 3 ++- scripts/migration/2.0.0.js | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100755 scripts/migration/2.0.0.js diff --git a/package.json b/package.json index adea748..6cc646a 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "git-stats": "./bin/git-stats" }, "scripts": { - "test": "node test" + "test": "node test", + "postinstall": "./scripts/migration/2.0.0.js" }, "author": "Ionică Bizău ", "contributors": [ diff --git a/scripts/migration/2.0.0.js b/scripts/migration/2.0.0.js new file mode 100755 index 0000000..ca35256 --- /dev/null +++ b/scripts/migration/2.0.0.js @@ -0,0 +1,40 @@ +#!/usr/bin/env node + +// Dependencies +var ReadJson = require("r-json") + , WriteJson = require("w-json") + , Abs = require("abs") + , Logger = require("bug-killer") + ; + +// Constants +const DATA_FILE = Abs("~/.git-stats"); + +function migrate() { + try { + var data = ReadJson(DATA_FILE) + } catch (e) { + if (e.code === "ENOENT") { + return; + } + Logger.log(e); + } + + if (data.commits) { + return; + } + + var newStats = { commits: {} }; + Object.keys(data).forEach(function (day) { + var cDay = newStats.commits[day] = {}; + Object.keys(data[day]).map(function (c) { + Object.keys(data[day][c]).map(function (h) { + cDay[h] = 1; + }); + }); + }); + + WriteJson(DATA_FILE, newStats); +} + +migrate();