Skip to content

Commit 98290a8

Browse files
committed
add release-notes and release-channel scripts
1 parent 17ceff1 commit 98290a8

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"pretest": "node scripts/install-fixture-deps.js",
2525
"test": "jest",
2626
"prepublishOnly": "npm run build && npm test && node scripts/copy-licenses.js",
27-
"format": "prettier \"src/**/*.js\" \"scripts/**/*.js\" \"tests/test.js\" --write --print-width 100 --single-quote --no-semi --plugin-search-dir ./tests"
27+
"format": "prettier \"src/**/*.js\" \"scripts/**/*.js\" \"tests/test.js\" --write --print-width 100 --single-quote --no-semi --plugin-search-dir ./tests",
28+
"release-channel": "node ./scripts/release-channel.js",
29+
"release-notes": "node ./scripts/release-notes.js"
2830
},
2931
"devDependencies": {
3032
"@ianvs/prettier-plugin-sort-imports": "^3.7.0",

scripts/release-channel.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Given a version, figure out what the release channel is so that we can publish to the correct
2+
// channel on npm.
3+
//
4+
// E.g.:
5+
//
6+
// 1.2.3 -> latest (default)
7+
// 0.0.0-insiders.ffaa88 -> insiders
8+
// 4.1.0-alpha.4 -> alpha
9+
10+
let version =
11+
process.argv[2] ||
12+
process.env.npm_package_version ||
13+
require('../package.json').version
14+
15+
let match = /\d+\.\d+\.\d+-(.*)\.\d+/g.exec(version)
16+
if (match) {
17+
console.log(match[1])
18+
} else {
19+
console.log('latest')
20+
}

scripts/release-notes.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Given a version, figure out what the release notes are so that we can use this to pre-fill the
2+
// relase notes on a GitHub release for the current version.
3+
4+
let path = require('path')
5+
let fs = require('fs')
6+
7+
let version =
8+
process.argv[2] ||
9+
process.env.npm_package_version ||
10+
require('../package.json').version
11+
12+
let changelog = fs.readFileSync(
13+
path.resolve(__dirname, '..', 'CHANGELOG.md'),
14+
'utf8',
15+
)
16+
let match = new RegExp(
17+
`## \\[${version}\\] - (.*)\\n\\n([\\s\\S]*?)\\n(?:(?:##\\s)|(?:\\[))`,
18+
'g',
19+
).exec(changelog)
20+
21+
if (match) {
22+
let [, , notes] = match
23+
console.log(notes.trim())
24+
} else {
25+
console.log(`Placeholder release notes for version: v${version}`)
26+
}

0 commit comments

Comments
 (0)