Skip to content

Only bump and create changelog if there ir a breaking change, feature or fix #99

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ module.exports = async function standardVersion (argv) {
}

const newVersion = await bump(args, version)
if (!newVersion) return
await changelog(args, newVersion)
await commit(args, newVersion)
await tag(newVersion, pkg ? pkg.private : false, args)
Expand Down
53 changes: 50 additions & 3 deletions lib/lifecycles/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,45 @@ const runLifecycleScript = require('../run-lifecycle-script')
const semver = require('semver')
const writeFile = require('../write-file')
const { resolveUpdaterObjectFromArgument } = require('../updaters')
const addBangNotes = require('conventional-changelog-conventionalcommits/add-bang-notes')
let configsToUpdate = {}

function _whatBump(config, commits) {
let level = 2
let breakings = 0
let features = 0
let fix = 0

commits.forEach(commit => {
addBangNotes(commit)
if (commit.notes.length > 0) {
breakings += commit.notes.length
level = 0
} else if (commit.type === 'feat' || commit.type === 'feature') {
features += 1
if (level === 2) {
level = 1
}
}
if(commit.type === 'fix') {
fix += 1
}
})

if (config.preMajor && level < 2) {
level++
}

if(!breakings && !features && !fix) return {}

return {
level: level,
reason: breakings === 1
? `There is ${breakings} BREAKING CHANGE and ${features} features`
: `There are ${breakings} BREAKING CHANGES and ${features} features`
}
}

async function Bump (args, version) {
// reset the cache of updated config files each
// time we perform the version bump step.
Expand All @@ -25,6 +62,14 @@ async function Bump (args, version) {
const stdout = await runLifecycleScript(args, 'prebump')
if (stdout && stdout.trim().length) args.releaseAs = stdout.trim()
const release = await bumpVersion(args.releaseAs, version, args)
if (!Object.keys(release).length) {
checkpoint(
args,
'no commits found, so not bumping version',
[]
)
return null
}
if (!args.firstRelease) {
const releaseType = getReleaseType(args.prerelease, release.releaseType, version)
const releaseTypeAsVersion = releaseType === 'pre' + release.releaseType ? semver.valid(release.releaseType + '-' + args.prerelease + '.0') : semver.valid(releaseType)
Expand Down Expand Up @@ -107,8 +152,9 @@ function getTypePriority (type) {
return TypeList.indexOf(type)
}

function bumpVersion (releaseAs, currentVersion, args) {
return new Promise((resolve, reject) => {
function bumpVersion(releaseAs, currentVersion, args) {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
Comment on lines +156 to +157
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
return new Promise((resolve, reject) => {

Unless I'm missing something, you don't need this async

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I'll remove it it's from an old implementation.

if (releaseAs) {
return resolve({
releaseType: releaseAs
Expand All @@ -123,7 +169,8 @@ function bumpVersion (releaseAs, currentVersion, args) {
preset: presetOptions,
path: args.path,
tagPrefix: args.tagPrefix,
lernaPackage: args.lernaPackage
lernaPackage: args.lernaPackage,
whatBump(commits) { return _whatBump(presetOptions, commits) }
}, args.parserOpts, function (err, release) {
if (err) return reject(err)
else return resolve(release)
Expand Down