Skip to content

Commit 9fadc5f

Browse files
nexdrewbcoe
authored andcommitted
feat(cli): use conventional default commit message with version
1 parent fc26974 commit 9fadc5f

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

index.js

+17-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var conventionalChangelog = require('conventional-changelog')
33
var conventionalRecommendedBump = require('conventional-recommended-bump')
44
var path = require('path')
55
var argv = require('yargs')
6-
.usage('$0 [options]')
6+
.usage('Usage: $0 [options]')
77
.option('infile', {
88
alias: 'i',
99
describe: 'Read the CHANGELOG from this file',
@@ -12,27 +12,29 @@ var argv = require('yargs')
1212
})
1313
.option('preset', {
1414
alias: 'p',
15-
describe: 'Name of the preset you want to use. Must be one of the following: angular, atom, codemirror, ember, eslint, express, jquery, jscs or jshint',
15+
describe: 'Name of the preset you want to use. Must be one of the following:\nangular, atom, codemirror, ember, eslint, express, jquery, jscs, or jshint',
1616
default: 'angular',
1717
global: true
1818
})
1919
.option('message', {
2020
alias: 'm',
21-
describe: 'commit message',
21+
describe: 'Commit message, replaces %s with new version',
2222
type: 'string',
23-
default: 'see changelog for details',
23+
default: 'chore(release): %s',
2424
global: true
2525
})
2626
.option('first-release', {
2727
alias: 'f',
28-
describe: 'is this the first release',
28+
describe: 'Is this the first release?',
2929
type: 'boolean',
3030
default: false,
3131
global: true
3232
})
3333
.help()
34-
.alias('h', 'help')
35-
.example('$0 -m "see changelog for details"', 'update changelog and tag release')
34+
.alias('help', 'h')
35+
.example('$0', 'Update changelog and tag release')
36+
.example('$0 -m "%s: see changelog for details"', 'Update changelog and tag release with custom commit message')
37+
.wrap(97)
3638
.argv
3739

3840
var addStream = require('add-stream')
@@ -44,6 +46,7 @@ var pkg = require(pkgPath)
4446
var semver = require('semver')
4547
var tempfile = require('tempfile')
4648
var rimraf = require('rimraf')
49+
var util = require('util')
4750

4851
conventionalRecommendedBump({
4952
preset: argv.preset
@@ -65,7 +68,7 @@ conventionalRecommendedBump({
6568
}
6669

6770
outputChangelog(argv, function () {
68-
commit(argv, function () {
71+
commit(argv, newVersion, function () {
6972
return tag(newVersion, argv)
7073
})
7174
})
@@ -107,9 +110,9 @@ function outputChangelog (argv, cb) {
107110
})
108111
}
109112

110-
function commit (argv, cb) {
113+
function commit (argv, newVersion, cb) {
111114
console.log(chalk.bold('3.') + ' commit ' + chalk.bold('package.json') + ' and ' + chalk.bold(argv.infile))
112-
exec('git add package.json ' + argv.infile + ';git commit package.json ' + argv.infile + ' -m "' + argv.message + '"', function (err, stdout, stderr) {
115+
exec('git add package.json ' + argv.infile + ';git commit package.json ' + argv.infile + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', function (err, stdout, stderr) {
113116
var errMessage = null
114117
if (err) errMessage = err.message
115118
if (stderr) errMessage = stderr
@@ -121,6 +124,10 @@ function commit (argv, cb) {
121124
})
122125
}
123126

127+
function formatCommitMessage (msg, newVersion) {
128+
return String(msg).indexOf('%s') !== -1 ? util.format(msg, newVersion) : msg
129+
}
130+
124131
function tag (newVersion, argv) {
125132
console.log(chalk.bold('4.') + ' tag release (' + chalk.green(newVersion) + ')')
126133
exec('git tag -a v' + newVersion + ' -m "' + argv.message + '"', function (err, stdout, stderr) {

0 commit comments

Comments
 (0)