Files: 58ab0241031aa549a35cce1e678c27065ae66221 / scripts / release-notes.js
936 bytesRaw
1 | const fs = require('fs') |
2 | const path = require('path') |
3 | |
4 | const version = process.env.npm_package_version |
5 | |
6 | if (version == null) { |
7 | throw new Error('no version found, are you running from npm? try `npm run release-notes`') |
8 | } |
9 | |
10 | const template = fs.readFileSync(path.join(__dirname, '..', 'docs', 'release-notes-template.md'), 'utf8') |
11 | const changelog = fs.readFileSync(path.join(__dirname, '..', 'docs', 'CHANGELOG.md'), 'utf8') |
12 | |
13 | let record = false |
14 | const lines = changelog.split('\n') |
15 | |
16 | const relevantLines = lines.reduce((acc, cur) => { |
17 | if (cur.startsWith('## ')) { |
18 | if (cur.startsWith(`## v${version}`)) { |
19 | record = true |
20 | return acc |
21 | } else { |
22 | record = false |
23 | return acc |
24 | } |
25 | } |
26 | |
27 | if (record) { |
28 | acc.push(cur) |
29 | } |
30 | |
31 | return acc |
32 | }, []) |
33 | |
34 | const changes = relevantLines.join('\n') |
35 | |
36 | const releaseNotes = template |
37 | .replace(/\$\$VERSION/g, version) |
38 | .replace(/\$\$CHANGES/g, changes) |
39 | |
40 | console.log(releaseNotes) |
41 |
Built with git-ssb-web