Last active
August 29, 2015 14:06
-
-
Save kozy4324/fb0bf4f227e0cbe5e5c5 to your computer and use it in GitHub Desktop.
git log --statで出力されるInsertion(s)とDeletion(s)でグラフ表示
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = (grunt) -> | |
grunt.initConfig | |
connect: | |
server: | |
options: | |
port: 0xBEEF | |
hostname: "localhost" | |
keepalive: true | |
processMaxBuffer: 512*1024 | |
graphMaxY: 1000000 | |
middleware: (connect, options) -> | |
data = '' | |
{exec} = require 'child_process' | |
command = 'git log --no-merges --stat | grep "files changed"' | |
exec command, {maxBuffer: options.processMaxBuffer}, (e, o) -> data = o.toString('utf8') | |
return [ | |
(req, res, next) -> | |
res.setHeader 'Content-Type', 'text/html' | |
res.end tmpl data: data, graphMaxY: options.graphMaxY | |
] | |
grunt.loadNpmTasks 'grunt-contrib-connect' | |
tmpl = (data) -> """ | |
<script src="http://ccchart.com/js/ccchart.js" charset="utf-8"></script> | |
<canvas id="chart"></canvas> | |
<textarea id="ta">#{data.data}</textarea> | |
<script> | |
var data = document.getElementById("ta").value; | |
data = data.split("\\n").reverse(); | |
var nums = data.map(function(line, i){ return i + 2; }); | |
nums.unshift("", 1); | |
var sum = 0; | |
var values = data.map(function(line){ | |
if(line.match(/(\\d+) insertion/)){ sum += +RegExp.$1; } | |
if(line.match(/(\\d+) deletion/)){ sum -= +RegExp.$1; } | |
return sum; | |
}); | |
values.unshift("", 0); | |
var o = { | |
config: { | |
maxY: #{data.graphMaxY}, | |
width: document.body.offsetWidth, | |
height: document.body.offsetHeight, | |
type: "bezi2", | |
bgGradient: {direction: "vertical", from:"#222", to:"#687478"} | |
}, | |
data: [nums, values] | |
}; | |
ccchart.init('chart', o); | |
</script> | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment