Skip to content

script-utils/version

This module provides functions for managing version updates in a project. It includes tasks such as validating version update types, checking the state of Git and GitHub CLI, updating version numbers in files, and performing Git operations such as tagging and pushing.

InterfaceDescription
AddUpdatedFilesToGitOptionsOptions for addUpdatedFilesToGit.
ManifestType representing the manifest file format for Obsidian plugins.
ObsidianReleasesJsonType representing the structure of Obsidian releases JSON.
ParsedVersionArgsThe result of parsing the command-line arguments for a version update.
UpdateChangelogOptionsOptions for updateChangelog.
UpdateVersionOptionsOptions for updateVersion.
FunctionDescription
addGitTagCreates a Git tag for the new version.
addUpdatedFilesToGitAdds updated files to the Git staging area and commits them with the new version message. If the commit fails (for example, the pre-commit hook rejects a new word in the changelog) and the process is attached to an interactive terminal, the user is prompted to fix the issue (for example, add the missing word to cspell.json) and press Enter to retry. The retry re-stages all files, so the fix is picked up without restarting the whole release lifecycle. In a non-interactive environment (no TTY, such as CI), the error is re-thrown instead of prompting, so the script fails fast rather than hanging. Pass shouldVerifyCommit: false to skip the pre-commit hook entirely in such cases.
checkGitHubCliInstalledChecks if the GitHub CLI is installed on the system. Throws an error if the GitHub CLI is not installed.
checkGitInstalledChecks if Git is installed on the system. Throws an error if Git is not installed.
checkGitRepoCleanChecks if the Git repository is clean, meaning there are no uncommitted changes. Throws an error if the Git repository is not clean.
copyUpdatedManifestCopies the updated manifest file to the distribution build folder.
getNewVersionGenerates a new version string based on the current version and the specified update type. Uses the semver package to compute the next version, supporting all npm increment types: major, minor, patch, premajor, preminor, prepatch, and prerelease. Pre-release versions use the beta identifier by default (e.g., 1.2.4-beta.0).
getReleaseNotesRetrieves the release notes for a specific version from the changelog.
getVersionUpdateTypeDetermines the type of version update based on the input string.
gitPushPushes commits and tags to the remote Git repository.
parseVersionArgsParses the command-line arguments for a version update into a version update type and UpdateVersionOptions. Each behavior is enabled by default; the corresponding --no-* flag turns it off. Recognized flags: - --no-build — skip the build step (only safe when the build output already matches the current code). - --no-changelog-editing — generate the changelog without opening it for manual review. - --no-checks — skip the clean-repo check, format, spellcheck, lint, over-exposure analysis, and tests (the build still runs). - --no-commit-verification — pass --no-verify to the release commit, skipping the pre-commit hook. - --no-demo-vault — skip archiving the plugin’s demo vault (demo-vault/) as a release artifact. - --no-release — run all local steps but skip the push and the GitHub release.
publishGitHubReleasePublishes a GitHub release for the new version. Handles the creation of a release and uploading files for either an Obsidian plugin or another project.
updateChangelogUpdates the changelog file with new version information and commit messages. This function reads the current changelog, appends new entries for the latest version, and prompts the user to review the changes.
updateVersionUpdates the version of the project based on the specified update type. This function performs a series of tasks to handle version updates: 1. Validates the version update type. 2. Checks if Git and GitHub CLI are installed. 3. Verifies that the Git repository is clean. 4. Runs spellcheck and linting. 5. Builds the project. 6. Updates version in files and changelog. 7. Adds updated files to Git, tags the commit, and pushes to the repository. 8. If an Obsidian plugin, copies the updated manifest and publishes a GitHub release.
updateVersionInFilesUpdates the version in various files, including package.json, package-lock.json, and Obsidian plugin manifests if applicable.
validateValidates the version update type to ensure it is either a recognized type or a valid manual version string.
EnumDescription
VersionUpdateTypeEnum representing different types of version updates. Aligns with npm’s npm version increment types plus Manual for explicit versions.