import { writeFile } from 'node:fs/promises' import { join } from 'node:path' import { fileURLToPath } from 'node:url' const packageName = '@napi-rs/image' const locale = 'en' const releases = await fetch(`https://api.github.com/repos/Brooooooklyn/Image/releases?per_page=100`, { headers: { Authorization: `token ${process.env.GITHUB_TOKEN}` }, }).then((res) => res.json()) const changelog = releases .filter(({ name }) => name?.startsWith(packageName)) .map((release) => { const body = release.body .replace(/'/g, "'") .replace(/@([a-zA-Z0-9_-]+)(?=(,| ))/g, '[@$1](https://github.com/$1)') .replace( /https:\/\/github\.com\/(\S+\/\S+\/pull\/\d+)/g, `$1`, ) .replace( /https:\/\/github\.com\/(.+?)\/(.+?)\/compare\/(.+?)@(.+?)\.\.\.(.+?)@(.+?)$/g, `$3@$4...$5@$6`, ) return `## ${release.tag_name} ${new Date(release.published_at).toLocaleDateString(locale)} \n${body}` }) .join('\n\n') await writeFile( join(fileURLToPath(import.meta.url), '..', 'pages', 'changelog', 'index.md'), `--- title: '@napi-rs/image' description: '@napi-rs/image changelog.' --- # @napi-rs/image ${changelog}`, )