Skip to content

Commit

Permalink
Switch to standard-changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
HeikoTheissen committed Sep 24, 2021
1 parent f117ab5 commit c7dd50c
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 142 deletions.
60 changes: 2 additions & 58 deletions lib/changelog.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,3 @@
const {Transform} = require("stream");
const changelog = require("standard-changelog");

var entry, blockedEntry, indent;
var blocked = new Map();

function nextLine(t) {
var offset = t.buffer.indexOf("\n");
if (offset >= 0) {
var o = offset;
if (t.buffer[o - 1] === 13) o--; // drop carriage-return before line-feed
t.emit("line", t.buffer.toString("utf8", 0, o));
t.buffer = t.buffer.slice(offset + 1);
process.nextTick(nextLine, t);
} else
t.callback();
}

process.stdin.pipe(
new Transform({
transform(chunk, encoding, callback) {
this.buffer = this.buffer ?
Buffer.concat([this.buffer, chunk], this.buffer.length + chunk.length) :
Buffer.from(chunk);
this.callback = callback;
nextLine(this);
},
flush(callback) {
if (this.buffer && this.buffer.length > 0) // add line-feed to final line
this._transform(Buffer.from("\n"), undefined, callback);
else
callback();
}
})
.on("line", function(line) {
if (/^commit\s+([0-9a-f]*)/.test(line)) {
if (entry && entry.length > 2 && !blockedEntry) this.push(entry.join(""));
blockedEntry = blocked.get(RegExp.$1);
entry = undefined;
} else if (/^Date:\s+(.*)$/.test(line))
entry = ["# " + RegExp.$1 + "\n"];
else if (entry && /^\s+\S/.test(line)) {
if (entry.length === 1)
entry.push("");
else if (entry.length === 2) {
if (!/^(\s+)CHANGELOG(\s+([0-9a-f]*))?\s*$/.test(line))
entry = undefined;
else {
if (RegExp.$3) blocked.set(RegExp.$3, true);
indent = RegExp.$1.length;
entry.push("");
}
} else
entry.push(line.substr(indent) + "\n");
}
})
.on("end", function() {
if (entry && entry.length > 2 && !blockedEntry) process.stdout.write(entry.join(""));
})
).pipe(process.stdout);
changelog().pipe(process.stdout);
4 changes: 2 additions & 2 deletions lib/changelog.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
remote=$(git remote show origin | grep -P -o "(?<=Push URL: ).*")
folder=$(mktemp -d)
git log | node lib/changelog >$folder/CHANGELOG.md
node lib/changelog >$folder/CHANGELOG.md
cd $folder
git init -b main
git add .
git commit -m "changelog"
git push --force $remote main:changelog

# Alternative
# git log | node lib/changelog >CHANGELOG.md
# node lib/changelog >CHANGELOG.md
# git diff-index --quiet HEAD || git commit -m "changelog"
# git push
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"devDependencies": {
"c8": "^7.3.1",
"eslint": "^7.21.0",
"mocha": "^8.3.1"
"mocha": "^8.3.1",
"standard-changelog": "^2.0.27"
},
"scripts": {
"build": "node lib/transform.js",
Expand Down
27 changes: 0 additions & 27 deletions test/changelog.test.js

This file was deleted.

54 changes: 0 additions & 54 deletions test/gitlog.txt

This file was deleted.

0 comments on commit c7dd50c

Please sign in to comment.