Skip to content

Commit 9c44626

Browse files
authored
feat: allow enabling/disabling each part of the release process (#526)
Also splits commit/tagging into two separate commands and checks for file modifications before committing updated contributor lists.
1 parent 73fdff4 commit 9c44626

File tree

5 files changed

+67
-25
lines changed

5 files changed

+67
-25
lines changed

cmds/release.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,23 @@ module.exports = {
5353
type: 'boolean',
5454
default: true
5555
},
56+
commit: {
57+
describe: 'Commit changes to git',
58+
type: 'boolean',
59+
default: true
60+
},
61+
tag: {
62+
describe: 'Create release tag in git',
63+
type: 'boolean',
64+
default: true
65+
},
66+
push: {
67+
describe: 'Push changes to GitHub',
68+
type: 'boolean',
69+
default: true
70+
},
5671
ghrelease: {
57-
describe: 'Genereate GitHub release',
72+
describe: 'Generate GitHub release',
5873
type: 'boolean',
5974
default: true
6075
},

src/release/commit.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@ const getPathToPkg = require('../utils').getPathToPkg
88

99
const files = ['package.json', 'CHANGELOG.md']
1010

11-
function commit () {
12-
let version
13-
return Promise.all([
14-
pify(git.add.bind(git))(files),
15-
fs.readJson(getPathToPkg())
16-
]).then((res) => {
17-
version = res[1].version
18-
return pify(git.commit.bind(git))(
19-
`chore: release version v${version}`,
20-
files
21-
)
22-
}).then(() => pify(git.addTag.bind(git))(`v${version}`))
11+
async function commit () {
12+
await pify(git.add.bind(git))(files)
13+
14+
const {
15+
version
16+
} = await fs.readJson(getPathToPkg())
17+
18+
await pify(git.commit.bind(git))(
19+
`chore: release version v${version}`,
20+
files
21+
)
2322
}
2423

2524
module.exports = commit

src/release/contributors.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
'use strict'
22

3+
const git = require('simple-git')(process.cwd())
4+
const pify = require('pify')
35
const execa = require('execa')
46
const { getPathToPkg } = require('../utils')
57

68
const contributors = async () => {
79
await execa('git-authors-cli', ['--print', 'false'])
8-
await execa('git', [
9-
'commit',
10-
getPathToPkg(),
11-
'-m',
10+
11+
const res = await pify(git.status.bind(git))()
12+
13+
if (!res.modified.length) {
14+
return
15+
}
16+
17+
await pify(git.commit.bind(git))(
1218
'chore: update contributors',
13-
'--no-verify',
14-
'--allow-empty'
15-
])
19+
getPathToPkg(), {
20+
'--no-verify': true
21+
}
22+
)
1623
}
1724

1825
module.exports = contributors

src/release/index.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ const releaseChecks = require('./prerelease')
1212
const bump = require('./bump')
1313
const changelog = require('./changelog')
1414
const commit = require('./commit')
15+
const tag = require('./tag')
1516
const contributors = require('./contributors')
1617
const github = require('./github')
1718
const publish = require('./publish')
1819
const push = require('./push')
1920

2021
function release (opts) {
21-
// enable publishing for docs
22-
opts.publish = true
23-
2422
const tasks = new Listr([{
2523
title: 'Lint',
2624
task: lint,
@@ -47,10 +45,16 @@ function release (opts) {
4745
enabled: (ctx) => ctx.changelog
4846
}, {
4947
title: 'Commit to Git',
50-
task: commit
48+
task: commit,
49+
enabled: (ctx) => ctx.commit
50+
}, {
51+
title: 'Tag release',
52+
task: tag,
53+
enabled: (ctx) => ctx.tag
5154
}, {
5255
title: 'Push to GitHub',
53-
task: push
56+
task: push,
57+
enabled: (ctx) => ctx.push
5458
}, {
5559
title: 'Generate GitHub Release',
5660
task: github,

src/release/tag.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict'
2+
3+
const git = require('simple-git')(process.cwd())
4+
const pify = require('pify')
5+
const fs = require('fs-extra')
6+
7+
const getPathToPkg = require('../utils').getPathToPkg
8+
9+
async function tag () {
10+
const {
11+
version
12+
} = await fs.readJson(getPathToPkg())
13+
14+
await pify(git.addTag.bind(git))(`v${version}`)
15+
}
16+
17+
module.exports = tag

0 commit comments

Comments
 (0)