Skip to content

Commit adbed85

Browse files
authored
feat: add changelog pages for cli releases (npm#265)
1 parent 5f3fbe1 commit adbed85

File tree

6 files changed

+8450
-0
lines changed

6 files changed

+8450
-0
lines changed

cli/lib/extract.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,31 @@ const getNav = async ({ path, release }) => {
9797
}
9898
}
9999

100+
const writeChangelog = async ({ release, nav, cwd, srcPath, contentPath }) => {
101+
const title = 'Changelog'
102+
const changelog = await gh.getFile({ ref: release.branch, path: srcPath })
103+
104+
await fs.writeFile(
105+
join(cwd, contentPath + '.md'),
106+
// mdx needs `>` escaped
107+
Transform.sync(changelog.toString().replace(/([^\\])>/g, '$1\\>'), {
108+
release,
109+
path: contentPath,
110+
frontmatter: {
111+
github_path: srcPath,
112+
title,
113+
},
114+
}),
115+
'utf-8'
116+
)
117+
118+
nav.children[nav.children.length - 1].children.push({
119+
title,
120+
url: `${release.url}/${contentPath}`,
121+
description: 'Changelog notes for each version',
122+
})
123+
}
124+
100125
const resolveRelease = async (
101126
{ resolved: current, ...release },
102127
{ force, prerelease }
@@ -208,6 +233,14 @@ const unpackRelease = async (
208233
})
209234
)
210235

236+
await writeChangelog({
237+
release,
238+
nav,
239+
cwd,
240+
srcPath: 'CHANGELOG.md',
241+
contentPath: posix.join('using-npm', 'changelog'),
242+
})
243+
211244
log.info(release.id, `${[...files, ...indexes].length} files`)
212245

213246
return {

0 commit comments

Comments
 (0)