Programmatic API
Run the relizy commands from Node.js - the exported functions, their shared options, their results and their errors.
Exports
relizy exports one function per command, the config helpers, the commit linter, the errors, and the types of the config, the options and the results.
import {
bump,
changelog,
checkMigration,
commitlint,
defineConfig,
getConfigOptions,
isRelizyCancelError,
lintCommitMessage,
listProfiles,
loadRelizyConfig,
mergePreview,
MergePreviewError,
prComment,
previewChangelog,
previewRelease,
providerRelease,
publish,
release,
RelizyCancelError,
social,
sync,
SyncError,
UnknownProfileError,
} from 'relizy'| Export | Returns | CLI |
|---|---|---|
release() | Promise<ReleaseReport> | relizy release |
bump() | Promise<BumpResult> | relizy bump |
changelog() | Promise<void> | relizy changelog |
publish() | Promise<PublishResponse | undefined> | relizy publish |
providerRelease() | Promise<ProviderReleaseResult> | relizy provider-release |
social() | Promise<SocialResult> | relizy social |
sync() | Promise<SyncResult> | relizy sync |
prComment() | Promise<boolean> | relizy pr-comment |
mergePreview() | Promise<ReleaseReport> | relizy merge-preview |
commitlint() | Promise<CommitlintRunResult> | relizy commitlint |
lintCommitMessage() | Promise<CommitlintResult> | - |
loadRelizyConfig() | Promise<ResolvedRelizyConfig> | - |
previewRelease() | Promise<ReleasePreview> | relizy release --dry-run, as data |
previewChangelog() | Promise<PreviewChangelog[]> | The changelogs of relizy release --dry-run, as data |
getConfigOptions() | Promise<ConfigOptionNode[]> | The options of the config, as a tree |
listProfiles() | ProfileInfo[] | The profiles of a config |
checkMigration() | Promise<MigrationReport> | What to change to upgrade from relizy 1, as data |
defineConfig() | Its argument, typed as RelizyConfig | Configuration |
RelizyCancelError, isRelizyCancelError() | See Errors | - |
UnknownProfileError | See Errors | - |
MergePreviewError | See Errors | - |
SyncError | See Errors | - |
The typedoc lists every export and type.
Shared Options
The commands take the options of their CLI command, camelCased (--format-cmd is formatCmd, --no-push is push: false), and these ones:
| Option | Description |
|---|---|
configName | Config to load, as --config: relizy.standalone for relizy.standalone.config.ts |
config | A config resolved by loadRelizyConfig(), see below |
overrides | Options applied over the config file (or over config), under the options of the call, see below. For release() and mergePreview() |
onProgress | Called with each event of the run, with what each step did as data |
onConfirm | Validates the versions instead of the prompt (release(), bump()), see Answering from the application |
onOtp | Gives the one-time password of the registry instead of the prompt (release(), publish()) |
profile | A profile of the config to apply, as --profile. The options of the call still win over it |
dryRun | Write nothing, as --dry-run |
logLevel | As --log-level |
groups | Only these version groups, as --group (an array of names), for the commands of --group |
With a config, the config file is not loaded: the commands use the given config as it is, the profile of the call, then the options of the call on top. Without it, they load the config file (configName, relizy by default).
release() and mergePreview() also take overrides, a local overlay without writing a file: the config file (or config), then the profile, then overrides, then the options of the call. The hooks of overrides run after the ones of the config for the same step (a function of the overlay after a command of the file), they do not replace them, except generate:changelog, which returns the changelog and is replaced.
import { release } from 'relizy'
await release({
yes: true,
profile: 'beta',
overrides: {
publish: { registry: 'https://registry.example.com' },
hooks: { 'success:publish': () => notifyTheTeam() },
},
})The functions print the logs of the logger, not the output of the CLI, unless RELIZY_REPORTER is set (see Output).
release() and bump() ask to confirm the new versions: pass yes: true in a script. Without an interactive terminal, they throw instead of asking.
Examples
import { release } from 'relizy'
const report = await release({ type: 'minor', yes: true, social: false })
if (report.released) {
console.log(`Released ${report.version}: ${report.tags.join(', ')}`)
}The steps one by one, the result of the bump given to the next ones:
import { bump, changelog, publish } from 'relizy'
const bumpResult = await bump({ yes: true })
if (bumpResult.bumped) {
await changelog({ bumpResult })
await publish({ bumpResult, tag: 'next' })
}bump() returns { bumped: false } when no commit triggers a bump: test bumped before reading newVersion or bumpedPackages.
Errors
The functions throw when they fail. A refused or cancelled prompt (bump confirmation, uncommitted changes, rewritten tag) throws a RelizyCancelError: nothing was written, the error:* hooks did not run and release() did not post a failed PR comment.
import { isRelizyCancelError, release } from 'relizy'
try {
await release({ yes: true })
}
catch (error) {
if (!isRelizyCancelError(error)) {
throw error
}
}mergePreview() throws a MergePreviewError when the release of the merge would fail, its message lists the problems.
sync() throws a SyncError when a branch did not get the release (a conflict, a refused push), once the other branches are synced: its result tells what was done to each branch. In release(), such a branch never fails the release.
UnknownProfileError is thrown by any command given a profile the config does not define: its profile is the name asked and available the names of the profiles.
providerRelease() and social() do not throw when the provider or a platform fails: the error is in their result (error, hasErrors). providerRelease() still throws on an error of the config.
TypeScript
The types of the options and the results are exported (ReleaseOptions, BumpOptions, BumpResult, ReleaseReport, RelizyConfig...):
import type { ReleaseOptions } from 'relizy'
const options: ReleaseOptions = {
type: 'patch',
yes: true,
publish: false,
}