Files
cypress/scripts/get-next-version.js
2021-03-22 22:46:24 +00:00

46 lines
1.1 KiB
JavaScript

/* eslint-disable no-console */
const semver = require('semver')
const Bluebird = require('bluebird')
const bumpCb = require('conventional-recommended-bump')
const currentVersion = require('../package.json').version
const bump = Bluebird.promisify(bumpCb)
const paths = ['packages', 'cli']
let nextVersion
const getNextVersionForPath = async (path) => {
// allow the semantic next version to be overridden by environment
if (process.env.NEXT_VERSION) {
return process.env.NEXT_VERSION
}
const { releaseType } = await bump({ preset: 'angular', path })
return semver.inc(currentVersion, releaseType || 'patch')
}
Bluebird.mapSeries(paths, async (path) => {
const pathNextVersion = await getNextVersionForPath(path)
if (!nextVersion || semver.gt(pathNextVersion, nextVersion)) {
nextVersion = pathNextVersion
}
})
.then(() => {
if (!nextVersion) {
throw new Error('Unable to determine next version.')
}
if (process.argv.includes('--npm')) {
const cmd = `npm --no-git-tag-version version ${nextVersion}`
console.log(`Running '${cmd}'...`)
return require('child_process').execSync(cmd)
}
console.log(nextVersion)
})