Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathcreateAttributionJSON.js
More file actions
Latest commit
100 lines (80 loc) · 2.77 KB
/
Copy pathcreateAttributionJSON.js
File metadata and controls
100 lines (80 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const{ execSync }=require("child_process");
constpath=require("path");
constfs=require("fs");
constcrypto=require('crypto');
/**
Updates the JSON file `attribution.json` with contributors based on commits to files, to run:
node createAttributionJSON.js
*/
consthandleDupeNames=(name)=>{
if(name==="Orta")return"Orta Therox"
returnname
}
// Being first gets you a free x commits
constgetOriginalAuthor=filepath=>{
constcreator=execSync(`git log --format='%an | %aE' --diff-filter=A -- "${filepath}"`)
.toString()
.trim();
return{
name: creator.split(" | ")[0],
email: creator.split(" | ")[1]
};
};
// Gets the rest of the authors for a file
constgetAuthorsForFile=filepath=>{
constcmd=`git log --format='%an | %aE' -- "${filepath}"`
constcontributors=execSync(cmd).toString().trim()
constallContributions=contributors.split("\n").map(c=>{
return{
name: handleDupeNames(c.split(" | ")[0]),
email: c.split(" | ")[1]
};
});
// Keep a map of all found authors,
constobjs=newMap()
allContributions.forEach(c=>{
constid=c.name.toLowerCase().replace(/\s/g,"")
constexisting=objs.get(id)
if(existing){
objs.set(id,{name: c.name,gravatar: existing.gravatar,count: existing.count+1})
}else{
constemail=c.email||"NOOP"
objs.set(id,{name: c.name,gravatar: crypto.createHash('md5').update(email).digest('hex'),count: 1})
}
})
return[...objs.values()]
};
constallFiles=recursiveReadDirSync("pages")
// const allFiles = ["pages/JSDoc Supported Types.md"];
constjson={}
allFiles.forEach(f=>{
constfirst=getOriginalAuthor(f);
constrest=getAuthorsForFile(f)
constfirstInRest=rest.find(a=>a.name===first.name)
firstInRest.count+=50
rest.sort((l,r)=>r.count-l.count)
console.log(" - "+f+" ("+rest.length+")")
json[f]={top: rest.slice(0,5),total: rest.length}
});
fs.writeFileSync("attribution.json",JSON.stringify(json))
/** Recursively retrieve file paths from a given folder and its subfolders. */
// https://gist.github.com/kethinov/6658166#gistcomment-2936675
/** @returns {string[]} */
functionrecursiveReadDirSync(folderPath){
if(!fs.existsSync(folderPath))return[]
constentryPaths=fs
.readdirSync(folderPath)
.map(entry=>path.join(folderPath,entry))
constfilePaths=entryPaths.filter(entryPath=>
fs.statSync(entryPath).isFile()
)
constdirPaths=entryPaths.filter(
entryPath=>!filePaths.includes(entryPath)
)
constdirFiles=dirPaths.reduce(
(prev,curr)=>prev.concat(recursiveReadDirSync(curr)),
[]
)
return[...filePaths, ...dirFiles]
.filter(f=>!f.endsWith(".DS_Store")&&!f.endsWith("README.md"))
}