Skip to content

Commit

Permalink
feat(options): add the ability to skip bump/changelog phase by using …
Browse files Browse the repository at this point in the history
…--skip-bump-and-changelog option, and to skip the commit/tag/push phase by using --skip-commit option

closes conventional-changelog#157
  • Loading branch information
denouche committed Feb 23, 2017
1 parent d0d71a5 commit ddcc13a
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 21 deletions.
12 changes: 12 additions & 0 deletions command.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ module.exports = require('yargs')
default: defaults.tagPrefix,
global: true
})
.option('skip-commit', {
describe: 'Bypass the commit, tag and push to git phase. In another words just bump the version and create the changelog.',
type: 'boolean',
default: defaults.skipCommit,
global: true
})
.option('skip-bump-and-changelog', {
describe: 'Bypass the bump and changelog generation phase. In another words, just commit, create the tag, and push to git.',
type: 'boolean',
default: defaults.skipBumpAndChangelog,
global: true
})
.version()
.alias('version', 'v')
.help()
Expand Down
4 changes: 3 additions & 1 deletion defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
"noVerify": false,
"commitAll": false,
"silent": false,
"tagPrefix": "v"
"tagPrefix": "v",
"skipCommit": false,
"skipBumpAndChangelog": false
}
53 changes: 33 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,47 @@ module.exports = function standardVersion (argv, done) {
var defaults = require('./defaults')
var args = objectAssign({}, defaults, argv)

bumpVersion(args.releaseAs, function (err, release) {
if (err) {
printError(args, err.message)
return done(err)
}

var newVersion = pkg.version

if (!args.firstRelease) {
var releaseType = getReleaseType(args.prerelease, release.releaseType, pkg.version)
newVersion = semver.inc(pkg.version, releaseType, args.prerelease)
updateConfigs(args, newVersion)
} else {
checkpoint(args, 'skip version bump on first release', [], chalk.red(figures.cross))
}

outputChangelog(args, function (err) {
if (argv.skipBumpAndChangelog) {
updateConfigs(args, pkg.version)
commitIfNeeded(argv, args, pkg.version, pkg, done)
} else {
bumpVersion(args.releaseAs, function (err, release) {
if (err) {
printError(args, err.message)
return done(err)
}
commit(args, newVersion, function (err) {

var newVersion = pkg.version

if (!args.firstRelease) {
var releaseType = getReleaseType(args.prerelease, release.releaseType, pkg.version)
newVersion = semver.inc(pkg.version, releaseType, args.prerelease)
updateConfigs(args, newVersion)
} else {
checkpoint(args, 'skip version bump on first release', [], chalk.red(figures.cross))
}

outputChangelog(args, function (err) {
if (err) {
return done(err)
}
return tag(newVersion, pkg.private, args, done)
commitIfNeeded(argv, args, newVersion, pkg, done)
})
})
})
}
}

function commitIfNeeded (argv, args, newVersion, pkg, cb) {
if (argv.skipCommit) {
cb()
} else {
commit(args, newVersion, function (err) {
if (err) {
return cb(err)
}
return tag(newVersion, pkg.private, args, cb)
})
}
}

/**
Expand Down
34 changes: 34 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,38 @@ describe('standard-version', function () {
})
})
})

describe('skip bump and changelog generation phase', function () {
it('do not bump the version', function () {
let changelogContent = 'legacy header format<a name="1.0.0">\n'
writePackageJson('1.0.0')
fs.writeFileSync('CHANGELOG.md', changelogContent, 'utf-8')

commit('feat: first commit')
return execCliAsync('--skip-bump-and-changelog')
.then(function () {
getPackageVersion().should.equal('1.0.0')
var content = fs.readFileSync('CHANGELOG.md', 'utf-8')
content.should.equal(changelogContent)
})
})
})

describe('skip commit phase', function () {
it('do not bump the version', function () {
let changelogContent = 'legacy header format<a name="1.0.0">\n'
writePackageJson('1.0.0')
fs.writeFileSync('CHANGELOG.md', changelogContent, 'utf-8')

commit('feat: new feature from branch')
return execCliAsync('--skip-commit')
.then(function () {
getPackageVersion().should.equal('1.1.0')
var content = fs.readFileSync('CHANGELOG.md', 'utf-8')
content.should.match(/new feature from branch/)
// check last commit message
shell.exec('git log --oneline -n1').stdout.should.match(/feat: new feature from branch/)
})
})
})
})

0 comments on commit ddcc13a

Please sign in to comment.