Skip to content

Commit

Permalink
Init repo and transfer script
Browse files Browse the repository at this point in the history
  • Loading branch information
beckerei committed Oct 13, 2019
0 parents commit 6cfbea6
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
*.log
npm-debug.log*
68 changes: 68 additions & 0 deletions cli.js
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);
},
);
}
22 changes: 22 additions & 0 deletions package.json
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": {}
}

0 comments on commit 6cfbea6

Please sign in to comment.