UNPKG

@ruan-cat/commitlint-config

Version:
154 lines (145 loc) 4.91 kB
import { UserConfig, ScopesType } from 'cz-git'; export { ScopesType } from 'cz-git'; import { PackageJson } from 'pkg-types'; /** * 提交类型 * @description * 从 commitlint-config 中提取commit类型配置 * 用于与 changelogen 集成 */ interface CommitType { emoji: string; type: string; description: string; } declare const commitTypes: CommitType[]; /** * 用户自己额外配置的范围项 拆分出表述文本的配置项 * @description */ type ScopesItemWithDesc = { /** 输入时的提示词 */ code: string; /** * 最终显示在 git commit 的文本 * @description * 即 git commit 的 scope 值。 */ value: string; /** 表述文本 */ desc: string; /** * 生成git提交范围用的 glob 匹配路径 * @description * 如果 glob 存在,则表示该范围的提交范围,会根据 glob 的匹配结果,进行范围的合并。 */ glob?: string[]; }; /** * 常用的范围配置 * @description * 该配置是为了提供更多的范围配置,以便于更好的管理提交范围。 * * 这里罗列一些高频更改配置的文件,并定位为专门的提交范围。 * * 这些配置范围,大多数是从具体项目中 不断提炼出来的常用范围 */ declare const commonScopes: ScopesItemWithDesc[]; /** * @description * 这个配置文件不能使用ts格式 ts不被支持 * * 该配置没有 scopes 范围 * * @see https://cz-git.qbb.sh/zh/config/#中英文对照模板 * @see https://cz-git.qbb.sh/zh/recipes/# */ declare const config: UserConfig; /** * 解析 git status --porcelain 输出,提取暂存区文件路径 * @description * 1. 按行分割输出 * 2. 过滤空行 * 3. 只保留暂存区文件(第一个字符不是空格且不是?) * 4. 提取文件路径(从第3个字符开始) * @param gitStatusOutput - git status --porcelain 命令的输出 * @returns 暂存区文件路径数组 */ declare function parseGitStatusOutput(gitStatusOutput: string): string[]; /** * 根据 git 状态,获取默认的提交范围 * @description * 1. 从 getPackagesNameAndDescription 获取所有包信息 * 2. 从 git status --porcelain 获取修改的文件路径 * 3. 匹配被修改的包范围,返回这些范围 * @see https://cz-git.qbb.sh/zh/recipes/default-scope * @returns 返回被修改的包范围数组,如果只有一个则返回字符串 */ declare function getDefaultScope(): string | string[] | undefined; type ScopesTypeItem = Exclude<ScopesType[number], string>; /** * 创建包范围取值 */ declare function createPackagescopes(packageJson: PackageJson): string; /** * 根据 pnpm-workspace.yaml 配置的monorepo有意义的包名,获取包名和包描述 * @description * 根据 pnpm-workspace.yaml 配置的monorepo有意义的包名,获取包名和包描述 */ declare function getPackagesNameAndDescription(): { name: string; value?: string; }[]; /** * 将 commitTypes 转换为 cz-git 格式 * @description * 将内部定义的 CommitType 数组转换为 cz-git 库所需的格式, * * 并实现描述文本的智能对齐,确保提交类型选择界面的美观性 * @returns 包含 value 和 name 字段的对象数组,用于 cz-git 配置 */ declare function convertCommitTypesToCzGitFormat(): { value: string; name: string; }[]; /** * 获取所有提交类型 * @description * 获取所有提交类型,用于 commitlint 的 `type-enum` 规则 * @returns 返回提交类型数组 */ declare function getTypes(): string[]; /** * 获取所有提交范围 * @description * 获取所有提交范围,用于 commitlint 的 `scope-enum` 规则 * @returns 返回提交范围数组 */ declare function getScopes(): string[]; /** * 用户配置项 * @description * 可以是 ScopesTypeItem 或 ScopesItemWithDesc */ type UserScopesItem = ScopesTypeItem | ScopesItemWithDesc; type GetUserConfigParams = { /** 用户提供的范围配置 */ userScopes?: UserScopesItem[]; config?: { /** * 是否打印范围? * @default true 默认打印 提示用户可以使用的提交范围有哪些 */ isPrintScopes?: boolean; }; }; /** * 获取用户配置 * @description * 可以根据用户提供的范围,补充范围配置 * * 其范围配置数组,默认排序到最前面,其次才是自动识别到包范围。 */ declare function getUserConfig(params?: GetUserConfigParams): UserConfig; declare const defExportCommitlintConfig: UserConfig; export { type CommitType, type ScopesItemWithDesc, type ScopesTypeItem, type UserScopesItem, commitTypes, commonScopes, config, convertCommitTypesToCzGitFormat, createPackagescopes, defExportCommitlintConfig as default, getDefaultScope, getPackagesNameAndDescription, getScopes, getTypes, getUserConfig, parseGitStatusOutput };