Skip to content

Commit ba4e7f6

Browse files
dmfaybcoe
authored andcommitted
feat: add prerelease lifecycle script hook (closes #217) (#234)
1 parent b4ed4f9 commit ba4e7f6

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ If you have your GPG key set up, add the `--sign` or `-s` flag to your `standard
159159
own supplementary commands during the release. The following
160160
hooks are available and execute in the order documented:
161161

162+
* `prerelease`: executed before anything happens. If the `prerelease` script returns a
163+
non-zero exit code, versioning will be aborted, but it has no other effect on the
164+
process.
162165
* `prebump`/`postbump`: executed before and after the version is bumped. If the `prebump`
163166
script returns a version #, it will be used rather than
164167
the version calculated by `standard-version`.

lib/lifecycles/bump.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ function Bump (args, pkg) {
2020

2121
if (args.skip.bump) return Promise.resolve()
2222
var newVersion = pkg.version
23-
return runLifecycleScript(args, 'prebump')
23+
return runLifecycleScript(args, 'prerelease')
24+
.then(runLifecycleScript.bind(this, args, 'prebump'))
2425
.then((stdout) => {
2526
if (stdout && stdout.trim().length) args.releaseAs = stdout.trim()
2627
return bumpVersion(args.releaseAs)

test.js

+36
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,42 @@ describe('cli', function () {
258258
})
259259

260260
describe('lifecycle scripts', () => {
261+
describe('prerelease hook', function () {
262+
it('should run the prerelease hook when provided', function () {
263+
writePackageJson('1.0.0', {
264+
'standard-version': {
265+
'scripts': {
266+
'prerelease': 'node scripts/prerelease'
267+
}
268+
}
269+
})
270+
writeHook('prerelease')
271+
fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')
272+
273+
commit('feat: first commit')
274+
var result = execCli('--patch')
275+
result.code.should.equal(0)
276+
result.stderr.should.match(/prerelease ran/)
277+
})
278+
279+
it('should abort if the hook returns a non-zero exit code', function () {
280+
writePackageJson('1.0.0', {
281+
'standard-version': {
282+
'scripts': {
283+
'prerelease': 'node scripts/prerelease && exit 1'
284+
}
285+
}
286+
})
287+
writeHook('prerelease')
288+
fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')
289+
290+
commit('feat: first commit')
291+
var result = execCli('--patch')
292+
result.code.should.equal(1)
293+
result.stderr.should.match(/prerelease ran/)
294+
})
295+
})
296+
261297
describe('prebump hook', function () {
262298
it('should allow prebump hook to return an alternate version #', function () {
263299
writePackageJson('1.0.0', {

0 commit comments

Comments
 (0)