diff --git a/scripts/changelog.ts b/scripts/changelog.ts new file mode 100644 index 0000000000..10fb904e8f --- /dev/null +++ b/scripts/changelog.ts @@ -0,0 +1,30 @@ +import fs from 'fs'; +import { join } from 'path'; + +const version = process.argv[2].replace('v', ''); + +function parseChangelog(changelog: string): Record { + const result: Record = {}; + + 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()); + + +