forked from ssbc/patchwork
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease-notes.js
More file actions
40 lines (30 loc) · 936 Bytes
/
Copy pathrelease-notes.js
File metadata and controls
40 lines (30 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const fs = require('fs')
const path = require('path')
const version = process.env.npm_package_version
if (version == null) {
throw new Error('no version found, are you running from npm? try `npm run release-notes`')
}
const template = fs.readFileSync(path.join(__dirname, '..', 'docs', 'release-notes-template.md'), 'utf8')
const changelog = fs.readFileSync(path.join(__dirname, '..', 'docs', 'CHANGELOG.md'), 'utf8')
let record = false
const lines = changelog.split('\n')
const relevantLines = lines.reduce((acc, cur) => {
if (cur.startsWith('## ')) {
if (cur.startsWith(`## v${version}`)) {
record = true
return acc
} else {
record = false
return acc
}
}
if (record) {
acc.push(cur)
}
return acc
}, [])
const changes = relevantLines.join('\n')
const releaseNotes = template
.replace(/\$\$VERSION/g, version)
.replace(/\$\$CHANGES/g, changes)
console.log(releaseNotes)