mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
chore: add script to format GitHub changelog (#12158)
This commit is contained in:
parent
1f12af7e83
commit
c2bef6cdf0
60
packages/vant/docs/formatChangelog.mjs
Normal file
60
packages/vant/docs/formatChangelog.mjs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/**
|
||||||
|
* This script is used to format changelog which is generated by GitHub
|
||||||
|
* because we need to paste it to the changelog page of Vant website.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// paste changelog here
|
||||||
|
const changelog = ``;
|
||||||
|
|
||||||
|
changelog.split('\n').map((line) => {
|
||||||
|
// Skip unused lines
|
||||||
|
if (
|
||||||
|
line.startsWith('> Please refer to') ||
|
||||||
|
line.startsWith('release:') ||
|
||||||
|
line.includes("What's Changed") ||
|
||||||
|
line.includes('Full Changelog') ||
|
||||||
|
line.includes('docs(changelog)')
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.startsWith('<!-- Release notes generated')) {
|
||||||
|
const version = line.match(/v\d+\.\d+\.\d+/)[0];
|
||||||
|
if (version) {
|
||||||
|
console.log(`### ${version}`);
|
||||||
|
// log the current date
|
||||||
|
const now = new Date();
|
||||||
|
const padZero = (num) => (num < 10 ? `0${num}` : num);
|
||||||
|
console.log(
|
||||||
|
`\`${now.getFullYear()}-${padZero(now.getMonth() + 1)}-${padZero(
|
||||||
|
now.getDate(),
|
||||||
|
)}\``,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// format title
|
||||||
|
if (line.startsWith('### ')) {
|
||||||
|
line = line.replace('### ', '#### ');
|
||||||
|
} else if (line.startsWith('## ')) {
|
||||||
|
line = line.replace('## ', '#### ');
|
||||||
|
}
|
||||||
|
|
||||||
|
// format PR link
|
||||||
|
const regex = /https:\/\/github\.com\/(\w+\/\w+)\/pull\/(\d+)/;
|
||||||
|
const match = line.match(regex);
|
||||||
|
const repoName = match ? match[1] : null;
|
||||||
|
const pullRequestNumber = match ? match[2] : null;
|
||||||
|
|
||||||
|
if (repoName && pullRequestNumber) {
|
||||||
|
line = line.replace(
|
||||||
|
regex,
|
||||||
|
`[#${pullRequestNumber}](https://github.com/${repoName}/pull/${pullRequestNumber})`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// format author
|
||||||
|
line = line.replace(/@([\w-]+)/, '[$1](https://github.com/$1)');
|
||||||
|
console.log(line);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user