Add changelog script

This commit is contained in:
Alex Gleason 2022-12-28 19:38:19 -06:00
parent e77c309e8a
commit fe1135eb9c
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

30
scripts/changelog.ts Normal file
View file

@ -0,0 +1,30 @@
import fs from 'fs';
import { join } from 'path';
const version = process.argv[2].replace('v', '');
function parseChangelog(changelog: string): Record<string, string> {
const result: Record<string, string> = {};
let currentVersion: string;
changelog.split('\n').forEach(line => {
const match = line.match(/^## \[([\d.]+)\](?: - [\d-]+)?$/);
if (match) {
currentVersion = match[1];
} else if (currentVersion) {
result[currentVersion] = (result[currentVersion] || '') + line + '\n';
}
});
return result;
}
const changelog = fs.readFileSync(join(__dirname, '..', 'CHANGELOG.md'), 'utf8');
const parsed = parseChangelog(changelog);
// Log to stdout so we can redirect it in CI.
// eslint-disable-next-line no-console
console.log((parsed[version] || '').trim());