Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(options): add the ability to skip bump/changelog phase by using … #158

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/)
})
})
})
})