UNPKG

@wellsite/version-generator

Version:
161 lines (160 loc) 5.62 kB
import { AndroidVersionOptions } from './android-version'; import { IosVersionOptions } from './ios-version'; /** * Environment variables type for dependency injection * This allows us to pass environment variables explicitly in tests * instead of relying on process.env */ export type EnvVars = { GITHUB_REF_NAME?: string; GITHUB_HEAD_REF?: string; GITHUB_SHA?: string; NODE_ENV?: string; [key: string]: string | undefined; }; /** * 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): Promise<Record<string, unknown>>; } /** * Default executor implementation using real commands */ export declare const defaultExecutor: Executor; /** * 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 - Environment variables for dependency injection * @returns Promise resolving to the latest tag */ export declare function getLatestTag(options?: { executor?: Executor; env?: EnvVars; cwd?: string; }): Promise<string>; /** * Gets the commit count from GitHub API * * @param fromTag - The tag to count commits from * @param executor - Custom executor for dependency injection * @param env * @returns Promise resolving to the commit count */ export declare function getCommitCountFromGitHub(fromTag: string, executor?: Executor, env?: EnvVars): Promise<number>; /** * Gets the commit count from git * * @param fromTag - The tag to count commits from * @param options - Options for getting commit count * @param options.executor - Custom executor for dependency injection * @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 * @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 * @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 - Environment variables for dependency injection * @param options.android - Android 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>; /** * Writes the generated version to a file * * @param versionInfo - The version information to write * @param filePath - The path to write the version file to * @param options - Options for writing the version file * @param options.executor - Custom executor for dependency injection * @param options.env - Environment variables for dependency injection */ export declare function writeVersionToFile(versionInfo: VersionInfo, filePath: string, options?: { executor?: Executor; env?: EnvVars; }): void; /** * Generates version information and optionally writes it to the specified output file as a JSON object * * @param dir - The directory for command execution and relative path resolution (defaults to current working directory) * @param outputFilePath - Optional output file path (relative to dir if not absolute) where the version file should be written * @param options - Options for generating and writing the version * @param options.executor - Custom executor for dependency injection * @param options.env - Environment variables for dependency injection * @param options.android - Android version options * @returns Promise resolving to the version information object */ export declare function generateAndWriteVersion(dir: string, outputFilePath?: string, options?: { executor?: Executor; env?: EnvVars; android?: AndroidVersionOptions; ios?: IosVersionOptions; }): Promise<VersionInfo>;