-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6cfbea6
Showing
3 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
*.log | ||
npm-debug.log* |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env node | ||
|
||
const fs = require('fs'); | ||
const { exec } = require('child_process'); | ||
|
||
getCommitsPerFile(getPathesWithWeight); | ||
|
||
function getPathesWithWeight(files) { | ||
const pathes = {}; | ||
|
||
files.forEach(file => { | ||
const { commitCount, filePath } = file; | ||
if (filePath) { | ||
const chunkedPath = filePath.split('/'); | ||
if (chunkedPath.length > 0) { | ||
const fileName = chunkedPath.pop(); | ||
pathes[filePath] = { | ||
id: filePath, | ||
name: fileName, | ||
parent: chunkedPath.length > 0 ? chunkedPath.join('/') : undefined, | ||
value: commitCount, | ||
}; | ||
|
||
chunkedPath.forEach((path, i) => { | ||
const id = chunkedPath.slice(0, i).join('/') || path; | ||
if (pathes.hasOwnProperty(id)) { | ||
pathes[id].value += commitCount; | ||
} else { | ||
const parent = | ||
i === 0 ? undefined : chunkedPath.slice(i - 1).join('/'); | ||
pathes[id] = { | ||
id, | ||
name: path, | ||
parent, | ||
value: commitCount, | ||
}; | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
fs.writeFileSync('file-treemap.json', JSON.stringify(pathes), err => { | ||
}); | ||
|
||
return pathes; | ||
} | ||
|
||
function getCommitsPerFile(cb) { | ||
exec( | ||
'git log --name-only --pretty=format: | sort | uniq -c | sort -nr', | ||
(err, stdout) => { | ||
if (err) { | ||
return null; | ||
} | ||
|
||
const lines = stdout.split('\n'); | ||
|
||
const commitsPerFile = lines.map(line => { | ||
const cleanLine = line.trim(); | ||
const [commitCount, path] = cleanLine.split(' '); | ||
return { commitCount: parseInt(commitCount, 10), filePath: path }; | ||
}); | ||
|
||
cb(commitsPerFile); | ||
}, | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "list-hot-spots", | ||
"version": "0.0.1", | ||
"description": "", | ||
"main": "src/index.ts", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/beckerei/list-hot-spots.git" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/beckerei/list-hot-spots/issues" | ||
}, | ||
"homepage": "https://github.com/beckerei/list-hot-spots#readme", | ||
"bin": "./cli.js", | ||
"dependencies": {}, | ||
"devDependencies": {} | ||
} |