Files
vant/packages/vant/docs/formatChangelog.mjs
2023-08-16 18:43:07 +08:00

64 lines
1.9 KiB
JavaScript

/**
* 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.
*
* translation prompt:
* You are a professional software developer who is proficient in both English and Chinese. Please translate the following software changelog from English to Chinese, keeping the header of the commit information in English and the position of the contributor information unchanged.
*/
// 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);
});