-
Notifications
You must be signed in to change notification settings - Fork 29
/
generate-changelog.js
48 lines (40 loc) · 1.68 KB
/
generate-changelog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const fs = require("fs");
const fetch = require("node-fetch");
const format = require("date-fns/format");
const HEADER_PATH = "./docs/changelog/_header.mdx";
const CHANGELOG_PATH = "./docs/changelog/changelog.mdx";
const header = fs.readFileSync(HEADER_PATH, "utf8");
fetch("https://api.github.com/repos/rowyio/rowy/releases")
.then((res) => res.json())
.then((json) => {
const items = json.map((release) => {
const title = release.name.replace(/v[\d\.]+[^\w]*/, "");
const heading =
`## <span className="changelog-version">${release.tag_name}</span>` +
(title
? `<span className="changelog-version-separator"> – </span><span>${title}</span>`
: "");
const releaseDate = `
<p className="changelog-date"><a href="${
release.html_url
}" target="_blank" rel="noopener noreferrer"><time datetime="${
release.published_at
}">${format(new Date(release.published_at), "d MMM yyyy")}</time></a></p>
`;
const body =
release.body
.replace(/##.*/gm, "<ul>")
.replace(/(-\s+.*$)\r\n\r\n/gm, "$1\n\n</ul>\n\n")
.replace("## ")
.replace(
/-\s+\[([\w]+)\] (.*)$/gm,
`<li><span className="changelog-tag" data-tag="$1">$1</span>\n\n$2\n\n</li>`
)
.replace(/#(\d+)/g, "[#$1](https://github.com/rowyio/rowy/issues/$1)")
.replace(/@([a-zA-Z0-9\-]{1,39})/g, "[@$1](https://github.com/$1)") +
(release.tag_name !== "v1.0.0" ? "\n\n</ul>" : "");
return [heading, releaseDate, body].join("\n");
});
fs.writeFileSync(CHANGELOG_PATH, header + "\n" + items.join("\n\n"));
})
.catch((err) => console.log(err));