UNPKG

@wellsite/version-generator

Version:
158 lines (157 loc) 5.76 kB
import { AndroidVersionOptions } from './android-version'; import { IosVersionOptions } from './ios-version'; import { EnvVars as NormalizedEnvVars } from './normalize-env'; export type EnvVars = NormalizedEnvVars; /** * Executor interface for dependency injection * This allows us to mock the external dependencies in tests */ export interface Executor { execCommand(command: string, cwd?: string): string; fileExists(filePath: string): boolean; readFile(filePath: string): string; writeFile(filePath: string, content: string): void; mkdirSync(dirPath: string, options?: { recursive: boolean; }): void; getGitHubData(url: string, env: EnvVars): Promise<Record<string, unknown>>; } /** * Default executor implementation using real commands */ export declare const defaultExecutor: Executor; /** * Gets the commit count from GitHub API * * @param fromTag - The tag to count commits from * @param executor - Custom executor for dependency injection * @param env - Normalized environment variables for dependency injection * @returns Promise resolving to the commit count */ export declare function getCommitCountFromGitHub(fromTag: string, executor: Executor | undefined, env: EnvVars): Promise<number>; /** * Gets the latest tag from git * * @param options - Options for getting the latest tag * @param options.executor - Custom executor for dependency injection * @param options.env - Normalized environment variables for dependency injection * @param options.cwd - Current working directory * @returns Promise resolving to the latest tag */ export declare function getLatestTag({ executor, env, cwd, }: { executor?: Executor; env: EnvVars; cwd?: string; }): Promise<string>; /** * Gets the commit count from git * * @param fromTag - The tag to count commits from * @param options - Options for getting the commit count * @param options.executor - Custom executor for dependency injection * @param options.env - Normalized environment variables for dependency injection * @param options.cwd - Current working directory * @returns Promise resolving to the commit count */ export declare function getCommitCount(fromTag: string, options: { executor?: Executor; env: EnvVars; cwd?: string; }): Promise<number>; /** * Gets the current branch name * * @param options - Options for getting the current branch * @param options.executor - Custom executor for dependency injection * @param options.env - Normalized environment variables for dependency injection * @param options.cwd - Current working directory * @returns The current branch name */ export declare function getCurrentBranch(options: { executor?: Executor; env: EnvVars; cwd?: string; }): string; /** * Gets the short commit hash * * @param options - Options for getting the short commit hash * @param options.executor - Custom executor for dependency injection * @param options.env - Normalized environment variables for dependency injection * @param options.cwd - Current working directory * @returns The short commit hash */ export declare function getShortCommitHash(options: { executor?: Executor; env: EnvVars; cwd?: string; }): string; /** * Cleans a branch name for use in a version string * Removes refs/heads/ or refs/pull/ prefixes if present * * @param branchName - The branch name to clean * @returns The cleaned branch name */ export declare function cleanBranchName(branchName: string): string; /** * Version information object containing all components */ export interface VersionInfo { major: string; minor: string; patch: number; branchName: string; commitHash: string; version: string; appReleaseVersion: string; androidVersionCode?: number; iosBuildNumber?: number; iosBuildNumberString?: string; } /** * Generates version information based on git information * * @param dir - Optional directory for command execution * @param options - Options for version generation * @param options.executor - Custom executor for dependency injection * @param options.env - Normalized environment variables for dependency injection * @param options.android - Android version options * @param options.ios - iOS version options * @returns Promise resolving to the version information object */ export declare function generatePackageVersion(dir: string, options: { executor?: Executor; env: EnvVars; android?: AndroidVersionOptions; ios?: IosVersionOptions; }): Promise<VersionInfo>; /** * Write version information to a file * @param versionInfo - Version information object * @param filePath - Path to the file to write * @param options - Optional configuration * @param options.executor - Custom executor for testing * @param options.cwd - Current working directory */ export declare function writeVersionToFile(versionInfo: VersionInfo, filePath: string, options: { executor: Executor; cwd: string; }): void; /** * Generate a version and write it to a file * @param dir - Directory to use for command execution * @param outputFilePath - Optional output file path(s) (relative to dir if not absolute) * @param options - Options for version generation * @param options.executor - Optional executor for commands * @param options.env - Optional environment variables * @param options.android - Android version options * @param options.ios - iOS version options * @returns Promise resolving to the version information object */ export declare function generateAndWriteVersion(dir: string, outputFilePath?: string | string[], options?: { executor?: Executor; env?: EnvVars; android?: AndroidVersionOptions; ios?: IosVersionOptions; }): Promise<VersionInfo>;