UNPKG

@142vip/changelog

Version:

基于Git提交信息,生成变更记录,输出Markdown格式的日志文件

320 lines (311 loc) 8.3 kB
import { VipSemverReleaseType, VipCommanderOptions } from '@142vip/utils'; import { GitAuthorInfo as GitAuthorInfo$1, Commit as Commit$1 } from '@142vip/changelog'; interface GitCommitAuthor { name: string; email: string; } interface GitCommitRaw { message: string; body: string; shortHash: string; author: GitCommitAuthor; } declare enum GitCommitMessageType { PULL_REQUEST = "pull-request", ISSUE = "issue", HASH = "hash" } interface GitCommitReference { type: GitCommitMessageType; value: string; } interface GitCommitRecord extends GitCommitRaw { description: string; type: string; scope: string; references: GitCommitReference[]; authors: GitCommitAuthor[]; isBreaking: boolean; } interface GitCommitDiffOptions { from?: string; to?: string; } interface Commit extends GitCommitRecord { resolvedAuthors?: GitAuthorInfo[]; } /** * 作者信息 */ interface GitAuthorInfo extends GitCommitAuthor { commits: string[]; login?: string; } /** * changelog cli */ interface ChangelogCliOptions extends VipCommanderOptions { token?: string; from?: string; to?: string; github?: string; name?: string; prerelease?: boolean; output?: string; scopeName?: string; } /** * 日志生成 */ interface ChangelogGenerateOptions { types: Record<string, { title: string; semver?: VipSemverReleaseType; }>; scopeMap: Record<string, string>; titles: { breakingChanges?: string; }; header?: string; scopeName?: string; dryRun?: boolean; output?: string; contributors: boolean; capitalize: boolean; group: boolean | 'multiple'; emoji: boolean; name: string; baseUrlApi: string; baseUrl: string; from: string; to: string; prerelease: boolean; repo: string; } interface GenerateChangelogResult { config: ChangelogGenerateOptions; commits: Commit[]; markdown: string; releaseUrl: string; } /** * 处理git changelog记录生成 */ declare function generateChangelogInfo(config: ChangelogGenerateOptions): Promise<GenerateChangelogResult>; /** * 创建或更新changelog文档 */ declare function upsertChangelogDoc(outputPath: string, markdown: string, releaseVersionName: string, markdownHeader: string): Promise<void>; /** * 处理changelog业务 */ declare function changelogCoreHandler(cliOptions: ChangelogCliOptions): Promise<void>; /** * changelog相关API */ declare const ChangelogAPI: { generateChangelogInfo: typeof generateChangelogInfo; upsertChangelogDoc: typeof upsertChangelogDoc; changelogCoreHandler: typeof changelogCoreHandler; }; /** * 获取不同tag之间的commit记录 */ declare function getGitCommitDiff(options: GitCommitDiffOptions): Promise<GitCommitRaw[]>; /** * 解析所有Commit信息 */ declare function parseGitCommits(commits: GitCommitRaw[], scopeMap: Record<string, string>): GitCommitRecord[]; /** * 生成Markdown文档记录的每行记录 */ declare function parseCommitsToMarkdownStr(commits: Commit[], options: { emoji: boolean; group?: boolean | 'multiple'; scopeName?: string; baseUrl: string; repo: string; capitalize: boolean; scopeMap: Record<string, string>; name: string; from: string; to: string; titles: { breakingChanges?: string; }; types: Record<string, { title: string; }>; }): Promise<string>; declare const GitCommitAPI: { getGitCommitDiff: typeof getGitCommitDiff; parseGitCommits: typeof parseGitCommits; parseCommitsToMarkdownStr: typeof parseCommitsToMarkdownStr; }; declare function getHeaders(token: string): { accept: string; authorization: string; }; declare function getAuthorInfo(options: { token: string; baseUrlApi: string; repo: string; }, info: GitAuthorInfo$1): Promise<GitAuthorInfo$1>; declare function resolveAuthors(commits: Commit$1[], options: { token?: string; baseUrlApi: string; repo: string; }): Promise<GitAuthorInfo$1[]>; /** * 判断是否有tag */ declare function isExistTag(tag: string, options: { baseUrlApi: string; repo: string; token: string; }): Promise<boolean>; /** * 生成手动release发布的地址链接 */ declare function generateReleaseUrl(markdown: string, config: { baseUrl: string; repo: string; name: string; to: string; prerelease: boolean; }): string; /** * 发送github发布 * - https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28 */ declare function createGithubRelease(options: { token: string; repo: string; baseUrlApi: string; name: string; tag: string; content: string; draft?: boolean; prerelease?: boolean; }): Promise<void>; /** * 打印手动发布地址 * - 默认成功输出 */ declare function printReleaseUrl(webUrl: string, success?: boolean): void; declare const GithubAPI: { getAuthorInfo: typeof getAuthorInfo; isExistTag: typeof isExistTag; generateReleaseUrl: typeof generateReleaseUrl; printReleaseUrl: typeof printReleaseUrl; getHeaders: typeof getHeaders; resolveAuthors: typeof resolveAuthors; createGithubRelease: typeof createGithubRelease; }; /** * 格式化Section */ declare function formatSection(commits: Commit[], options: { emoji: boolean; group?: boolean | 'multiple'; scopeName?: string; baseUrl: string; repo: string; capitalize: boolean; scopeMap: Record<string, string>; sectionName: string; }): string[]; /** * 无内容更新 */ declare function getNoSignificantChanges(): string; /** * 获取npm版本描述 */ declare function getNPMVersionDescription(pkgName: string, pkgVersion: string): string; declare function getGithubVersionDescription({ baseUrl, repo, fromVersion, toVersion }: { baseUrl: string; repo: string; fromVersion: string; toVersion: string; }): string; declare const MarkdownAPI: { formatSection: typeof formatSection; getNoSignificantChanges: typeof getNoSignificantChanges; getNPMVersionDescription: typeof getNPMVersionDescription; getGithubVersionDescription: typeof getGithubVersionDescription; }; /** * changelog默认的名称配置 */ declare const CONFIG_DEFAULT_NAME: string; /** * changelog默认的header配置 */ declare const CONFIG_DEFAULT_HEADER: string; /** * 默认配置 */ declare const ChangelogDefaultConfig: { scopeMap: {}; header: string; types: { feat: { title: string; semver: string; }; perf: { title: string; semver: string; }; fix: { title: string; semver: string; }; refactor: { title: string; semver: string; }; docs: { title: string; semver: string; }; build: { title: string; semver: string; }; types: { title: string; semver: string; }; release: { title: string; semver: string; }; }; titles: { breakingChanges: string; }; contributors: boolean; capitalize: boolean; group: boolean; emoji: boolean; baseUrl: string; baseUrlApi: string; prerelease: boolean; }; /** * 定义配置文件 * - 合并默认配置 */ declare function defineChangelogConfig(config: ChangelogGenerateOptions): ChangelogGenerateOptions; /** * 加载配置,读取配置文件 */ declare function loadChangelogConfig(): ChangelogGenerateOptions; /** * 加载配置 * 将用户自定义配置和默认配置合并 */ declare function parseCliOptions(cliOptions: ChangelogCliOptions): ChangelogGenerateOptions; export { CONFIG_DEFAULT_HEADER, CONFIG_DEFAULT_NAME, ChangelogAPI, type ChangelogCliOptions, ChangelogDefaultConfig, type ChangelogGenerateOptions, type Commit, type GenerateChangelogResult, type GitAuthorInfo, GitCommitAPI, type GitCommitAuthor, type GitCommitDiffOptions, GitCommitMessageType, type GitCommitRaw, type GitCommitRecord, type GitCommitReference, GithubAPI, MarkdownAPI, defineChangelogConfig, loadChangelogConfig, parseCliOptions };