forked from bugsnag/bugsnag-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-changelog
executable file
·56 lines (43 loc) · 1.44 KB
/
update-changelog
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
const version = require('../package.json').version
const semver = require('semver')
const editor = require('editor')
const { readFileSync, writeFileSync, unlinkSync } = require('fs')
const { resolve } = require('path')
const template = (summary) => `
## ${version} (${datestamp()})
<!-- optional: if this is a significant release, describe it in a sentence or two -->
### Added
- Modify or remove as appropriate
### Changed
- Modify or remove as appropriate
### Deprecated
- Modify or remove as appropriate
### Removed
- Modify or remove as appropriate
### Fixed
- Modify or remove as appropriate
### Security
- Modify or remove as appropriate
`.trim()
const datestamp = () => (new Date().toISOString()).replace(/T.*$/, '')
const insert = (entry) => {
const changelog = readFileSync(resolve(__dirname, '../CHANGELOG.md'), 'utf8')
const replaced = changelog.replace(
/(<!-- \{entry_placeholder\} -->)/,
`$1\n\n${entry}`
)
writeFileSync(resolve(__dirname, '../CHANGELOG.md'), replaced, 'utf8')
}
const isUnstable = semver.prerelease(version) !== null
if (isUnstable) {
console.log('skipping changelog update (prerelease versions don’t need changelogs)')
} else {
const tmp = resolve(__dirname, '..', '.CHANGELOG_CURRENT_ENTRY.md')
writeFileSync(tmp, template())
editor(tmp, (code, sig) => {
if (code !== 0) throw new Error('non-zero exit code from editor')
insert(readFileSync(tmp))
unlinkSync(tmp)
})
}