git-stats/scripts/migration/2.0.0.js
Ionică Bizău 3c0d521b1a ⬆️ 2.9.12 🎉
2016-10-23 10:47:38 +03:00

41 lines
874 B
JavaScript
Executable file

#!/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() {
var data = {};
try {
data = ReadJson(DATA_FILE)
} catch (e) {
if (e.code === "ENOENT") {
return;
}
Logger.log(e);
}
data.commits = data.commits || {};
var newStats = { commits: data.commits };
delete data.commits;
Object.keys(data).forEach(function (day) {
var cDay = newStats.commits[day] = 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();