Created
January 23, 2019 17:35
-
-
Save yuanliwei/eaba7e3aabc0fcb9c24715705f3898ac to your computer and use it in GitHub Desktop.
统计Git代码行数,js
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
let fs = require('fs') | |
let path = require('path') | |
// git log --stat > stat.txt | |
let content = fs.readFileSync(path.join(__dirname,'stat.txt'), 'utf-8') | |
let lines = content.split('\n') | |
let commits = [] | |
let item = {} | |
lines.forEach((l)=>{ | |
if(l.startsWith('commit ')){ | |
item = {name:l, count: 0} | |
commits.push(item) | |
console.log(l); | |
} else if(l.match(/\| *(\d+) */)){ | |
let num = l.match(/\| *(\d+) */)[1] | |
item.count += parseInt(num) | |
} | |
}) | |
console.log(commits.map((o)=>`${o.name} : ${o.count}`).join('\n')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment