obsidian-dev-utils
Version:
This is the collection of useful functions that you can use for your Obsidian plugin development
168 lines (167 loc) • 6.49 kB
text/typescript
/**
* @packageDocumentation
*
* 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.
*/
/**
* Enum representing different types of version updates.
*/
export declare enum VersionUpdateType {
Beta = "beta",
Invalid = "invalid",
Major = "major",
Manual = "manual",
Minor = "minor",
Patch = "patch"
}
/**
* Type representing the manifest file format for Obsidian plugins.
*/
export interface Manifest {
/**
* A minimum Obsidian version required for the plugin.
*/
minAppVersion: string;
/**
* A version of the plugin.
*/
version: string;
}
/**
* Type representing the structure of Obsidian releases JSON.
*/
export interface ObsidianReleasesJson {
/**
* A name of the Obsidian release.
*/
name: string;
}
/**
* Creates a Git tag for the new version.
*
* @param newVersion - The new version number to use for the tag.
* @returns A {@link Promise} that resolves when the tag has been created.
*/
export declare function addGitTag(newVersion: string): Promise<void>;
/**
* Adds updated files to the Git staging area and commits them with the new version message.
*
* @param newVersion - The new version number used as the commit message.
* @returns A {@link Promise} that resolves when the files have been added and committed.
*/
export declare function addUpdatedFilesToGit(newVersion: string): Promise<void>;
/**
* Checks if the GitHub CLI is installed on the system.
*
* Throws an error if the GitHub CLI is not installed.
*
* @throws Error if the GitHub CLI is not installed.
*/
export declare function checkGitHubCliInstalled(): Promise<void>;
/**
* Checks if Git is installed on the system.
*
* Throws an error if Git is not installed.
*
* @throws Error if Git is not installed.
*/
export declare function checkGitInstalled(): Promise<void>;
/**
* Checks if the Git repository is clean, meaning there are no uncommitted changes.
*
* Throws an error if the Git repository is not clean.
*
* @throws Error if the Git repository is not clean.
*/
export declare function checkGitRepoClean(): Promise<void>;
/**
* Copies the updated manifest file to the distribution build folder.
*
* @returns A {@link Promise} that resolves when the copy operation is complete.
*/
export declare function copyUpdatedManifest(): Promise<void>;
/**
* Generates a new version string based on the current version and the specified update type.
*
* @param versionUpdateType - The type of version update (major, minor, patch, beta, or manual).
* @returns A {@link Promise} that resolves to the new version string.
* @throws Error if the current version format is invalid.
*/
export declare function getNewVersion(versionUpdateType: string): Promise<string>;
/**
* Retrieves the release notes for a specific version from the changelog.
*
* @param newVersion - The new version number for which to get the release notes.
* @returns A {@link Promise} that resolves to the release notes for the specified version.
*/
export declare function getReleaseNotes(newVersion: string): Promise<string>;
/**
* Determines the type of version update based on the input string.
*
* @param versionUpdateType - The input string representing the version update type.
* @returns The corresponding `VersionUpdateType`.
*/
export declare function getVersionUpdateType(versionUpdateType: string): VersionUpdateType;
/**
* Pushes commits and tags to the remote Git repository.
*
* @returns A {@link Promise} that resolves when the push operation is complete.
*/
export declare function gitPush(): Promise<void>;
/**
* Publishes a GitHub release for the new version.
*
* Handles the creation of a release and uploading files for either an Obsidian plugin or another project.
*
* @param newVersion - The new version number for the release.
* @param isObsidianPlugin - A boolean indicating if the project is an Obsidian plugin.
* @returns A {@link Promise} that resolves when the release has been published.
*/
export declare function publishGitHubRelease(newVersion: string, isObsidianPlugin: boolean): Promise<void>;
/**
* Updates 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.
*
* @param newVersion - The new version number to be added to the changelog.
* @returns A {@link Promise} that resolves when the changelog update is complete.
*/
export declare function updateChangelog(newVersion: string): Promise<void>;
/**
* Updates 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.
*
* @param versionUpdateType - The type of version update to perform (major, minor, patch, beta, or x.y.z[-beta:u]).
* @param prepareGitHubRelease - A callback function to prepare the GitHub release.
* @returns A {@link Promise} that resolves when the version update is complete.
*/
export declare function updateVersion(versionUpdateType?: string, prepareGitHubRelease?: (newVersion: string) => Promise<void>): Promise<void>;
/**
* Updates the version in various files, including `package.json`, `package-lock.json`,
* and Obsidian plugin manifests if applicable.
*
* @param newVersion - The new version string to update in the files.
* @returns A {@link Promise} that resolves when the update is complete.
*/
export declare function updateVersionInFiles(newVersion: string): Promise<void>;
/**
* Validates the version update type to ensure it is either a recognized type
* or a valid manual version string.
*
* @param versionUpdateType - The version update type to validate.
* @throws Error if the version update type is invalid.
*/
export declare function validate(versionUpdateType: string): void;