UNPKG

@favware/cliff-jumper

Version:

A small CLI tool to create a semantic release and git-cliff powered Changelog

41 lines 2.08 kB
import { packageCwd } from '#lib/constants'; import { logVerboseError } from '#lib/logger'; import { readPackageJson, writePackageJson } from '#lib/package-json-parser'; import { doActionAndLog, getReleaseType } from '#lib/utils'; import { isNullishOrEmpty } from '@sapphire/utilities'; import { join } from 'node:path'; import Semver from 'semver'; export function bumpVersion(options, bumperRecommendation) { return doActionAndLog('Bumping version in package.json', async () => { const packageJsonPath = join(packageCwd, 'package.json'); const packageJsonContent = await readPackageJson(packageJsonPath); const currentVersion = packageJsonContent.version; const currentClean = Semver.clean(currentVersion); if (isNullishOrEmpty(currentClean)) { return logVerboseError({ text: ['No current version was found. Make sure there is a package.json at your current working directory'], logWithThrownError: true, verbose: options.verbose }); } const newVersion = Semver.inc(currentClean, `${getReleaseType(options, bumperRecommendation)}`, options.preid ?? '', options.identifierBase); if (isNullishOrEmpty(newVersion)) { return logVerboseError({ text: ['Failed to assign new version.'], verboseText: [ `The resolved current version is ${currentVersion} which was cleaned to ${currentClean} by semver clean`, `A bump with release type ${bumperRecommendation.releaseType} was attempted but failed`, 'Either validate your setup or contact the developer with reproducible code.' ], logWithThrownError: true, verbose: options.verbose }); } packageJsonContent.version = newVersion; if (!options.dryRun) { await writePackageJson(packageJsonPath, packageJsonContent); } return newVersion; }); } //# sourceMappingURL=bump-version.js.map