Standard-version: Getting the next version number

Created on 1 Sep 2017  路  9Comments  路  Source: conventional-changelog/standard-version

Hi, is it possible to get the next version number (in the node API or otherwise) without doing any of the lifecycle events? i.e. bump, changelog, commit, tag.

If we wish to use Git flow and the release branches are created manually, it would be useful to know what version to apply to the release branch name.

Most helpful comment

@nexdrew @stevemao @devdigital what if we added a --json command like npm; which could be combined with --dry-run to output newline delimited JSON.

All 9 comments

Currently doing the following, would be nice if there was a parameter to standard-version:

// package.json
"scripts": {
  "get-next-version": "node ./get-next-version.js"
}
// get-next-version.js
const packageJson = require('./package.json')
const conventionalRecommendedBump = require('conventional-recommended-bump')
const semver = require('semver')

const getNextVersion = currentVersion => {
  return new Promise((resolve, reject) => {
    conventionalRecommendedBump(
      {
        preset: 'angular',
      },
      (err, release) => {
        if (err) {
          reject(err)
          return
        }

        const nextVersion =
          semver.valid(release.releaseType) ||
          semver.inc(currentVersion, release.releaseType)

        resolve(nextVersion)
      }
    )
  })
}

getNextVersion(packageJson.version)
  .then(version => console.log(version))
  .catch(error => console.log(error))

I don't see anything wrong with your code. Maybe you could publish your get-next-version to npm.

Note that you can use the dry run mode to see the version bump in a terminal, but this obviously doesn't help much if you need something programmatic.

@nexdrew @stevemao @devdigital what if we added a --json command like npm; which could be combined with --dry-run to output newline delimited JSON.

馃憖

Hello @bcoe, any updates on this topic?

Could the return of the pipeline here be the newVersion?

+1, also interested in this

For anyone still interested in this: I've just published a package called next-standard-version, which has an CLI and API to get the next version number!

Was this page helpful?
0 / 5 - 0 ratings