Add changelog script
This commit is contained in:
parent
e77c309e8a
commit
fe1135eb9c
1 changed files with 30 additions and 0 deletions
30
scripts/changelog.ts
Normal file
30
scripts/changelog.ts
Normal 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());
|
||||
|
||||
|
||||
|
Loading…
Reference in a new issue