UNPKG

1.35 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3import * as fs from 'fs';
4import semver from 'semver';
5
6const changelogPath = 'CHANGELOG.md';
7const changelog = fs.readFileSync(changelogPath, 'utf8');
8
9/*
10 Parse the raw changelog text and split it into individual releases.
11
12 This regular expression:
13 - Matches lines starting with "## x.x.x".
14 - Groups the version number.
15 - Skips the (optional) release date.
16 - Groups the changelog content.
17 - Ends when another "## x.x.x" is found.
18*/
19const regex = /^## (\d+\.\d+\.\d+.*?)\n(.+?)(?=\n^## \d+\.\d+\.\d+.*?\n)/gms;
20
21let releaseNotes = [];
22let match;
23// eslint-disable-next-line no-cond-assign
24while (match = regex.exec(changelog)) {
25 releaseNotes.push({
26 'version': match[1],
27 'changelog': match[2].trim(),
28 });
29}
30
31const latest = releaseNotes[0];
32const previous = releaseNotes[1];
33
34
35// Print the release notes template.
36
37const templatedReleaseNotes = `https://github.com/maplibre/maplibre-gl-js
38[Changes](https://github.com/maplibre/maplibre-gl-js/compare/v${previous.version}...v${latest.version}) since [MapLibre GL JS v${previous.version}](https://github.com/maplibre/releases/tag/v${previous.version}):
39
40${latest.changelog}
41
42${semver.prerelease(latest.version) ? 'Pre-release version' : ''}`;
43
44// eslint-disable-next-line eol-last
45process.stdout.write(templatedReleaseNotes.trimEnd());
\No newline at end of file