Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions out/changelog.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}
})();
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
"aicommit",
"aicommits",
"gptcommit",
"commit"
"commit",
"changelog",
"generator"
],
"main": "cli.js",
"bin": {
"opencommit": "./out/cli.cjs",
"oco": "./out/cli.cjs"
"oco": "./out/cli.cjs",
"changelog": "./out/changelog.cjs ./CHANGELOG.html"
},
"repository": {
"url": "https://github.com/di-sukharev/opencommit"
Expand Down Expand Up @@ -77,6 +80,8 @@
"ignore": "^5.2.4",
"ini": "^3.0.1",
"inquirer": "^9.1.4",
"node-emoji": "^2.1.0",
"marked": "9.1.2",
"openai": "^3.2.1"
}
}