-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathchangelog.cjs
More file actions
executable file
·85 lines (79 loc) · 1.78 KB
/
changelog.cjs
File metadata and controls
executable file
·85 lines (79 loc) · 1.78 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
#!/usr/bin/env node
const fs = require('fs');
const {execSync} = require("child_process");
const {marked} = require("marked");
const {emojify} = require("node-emoji");
function getLogsByDate() {
const logs = execSync(`git log --date=short`).toString();
const commits = [];
for (let log of logs.split(/[a-zA-Z0-9]{40}/)) {
log = log.split('Date: ')[1];
if (!log) {
continue;
}
const obj = {
date: log.split('\n\n ')[0],
subject: log.split('\n\n ')[1].split('\n\ncommit ')[0]
}
commits.push(obj);
}
const dates = {};
for (const com of commits) {
if (!dates[com.date]) {
dates[com.date] = [];
}
dates[com.date].push(com);
}
return dates;
}
(async () => {
try {
const logs = getLogsByDate();
let html = "";
for (const [date, commit] of Object.entries(logs)) {
let lis = '';
for (const com of commit) {
let sub = com.subject.trim();
sub = emojify(sub);
sub = marked(sub, {mangle: false, headerIds: false});
sub = sub.replaceAll('\n', '<br>');
sub = sub.replaceAll('\t', ' - ');
if (sub.length < 30) {
continue;
}
lis += `<li><div class='msg'>${sub}</div></li>`;
}
if (lis.length < 1) {
continue;
}
html += `<div class='changelog-day'><h2>${date}</h2><ul>${lis}</ul></div>`;
}
fs.writeFileSync(process.argv[2], `<html><head>
<style>
p {
margin: 0px;
}
.changelog-day {
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
min-height: 130px;
}
h2 {
margin-bottom: 0px;
transform: rotate(270deg);
white-space: nowrap;
width: 20px;
height: 36px;
min-width: 85px;
}
ul {
border-left: 1px solid black;
}
</style>
</head><body><div class='changelog'>${html}</div></body></html>`);
} catch (error) {
console.error(error);
}
})();