From a325c077af76ea29e9f21d061194012f95dddf11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=97=8D+85CD?= <50108258+kwaa@users.noreply.github.com> Date: Wed, 17 Apr 2024 16:10:08 +0800 Subject: [PATCH] feat(git-changelog): include extensions option --- .../vitepress-plugin-git-changelog/src/vite/git.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/vitepress-plugin-git-changelog/src/vite/git.ts b/packages/vitepress-plugin-git-changelog/src/vite/git.ts index 8f6a440..157627c 100644 --- a/packages/vitepress-plugin-git-changelog/src/vite/git.ts +++ b/packages/vitepress-plugin-git-changelog/src/vite/git.ts @@ -49,6 +49,7 @@ async function aggregateCommit( getReleaseTagsURL: CommitToStringsHandler, log: Commit, includeDirs: string[] = [], + includeExtensions: `.${string}`[] = [], optsRewritePaths?: Record, optsRewritePathsByPatterns?: RewritePathsBy, ) { @@ -80,7 +81,7 @@ async function aggregateCommit( // include is not set, it is /^.+\md$/ // include is set, it is /^(${include.join('|')})\/.+\md$/ // in another word, /^(includeItem1|includeItem2|includeItem3)\/.+\md$/ - const regexp = new RegExp(`^${includeDirs.length > 0 ? `(${includeDirs.join('|')})${sep === win32.sep ? win32.sep : `\\${posix.sep}`}` : ''}.+\\.md$`) + const regexp = new RegExp(`^${includeDirs.length > 0 ? `(${includeDirs.join('|')})${sep === win32.sep ? win32.sep : `\\${posix.sep}`}` : ''}.+\\${includeExtensions.length > 0 ? `(${includeExtensions.join('|')})` : '.md'}$`) return !!i[1]?.match(regexp)?.[0] }), ), @@ -110,6 +111,7 @@ async function aggregateCommits( getReleaseTagsURL: CommitToStringsHandler, commits: SimpleGitCommit, includeDirs: string[] = [], + includeExtensions: `.${string}`[] = [], rewritePaths?: Record, rewritePathsBy?: RewritePathsBy, ) { @@ -144,7 +146,7 @@ async function aggregateCommits( const processedCommits = await Promise.all( transformedCommits.map( async (commit) => { - return aggregateCommit(getReleaseTagURL, getReleaseTagsURL, commit, includeDirs, rewritePaths, rewritePathsBy) + return aggregateCommit(getReleaseTagURL, getReleaseTagsURL, commit, includeDirs, includeExtensions, rewritePaths, rewritePathsBy) }, ), ) @@ -157,6 +159,10 @@ export interface GitChangelogOptions { * When fetching git logs, what directories should be included? */ includeDirs?: string[] + /** + * When fetching git logs, what extensions should be included? + */ + includeExtensions?: `.${string}`[] /** * Your repository URL. * Yes, you can dynamically generate it. @@ -248,6 +254,7 @@ export function GitChangelog(options: GitChangelogOptions = {}): Plugin { maxGitLogCount, maxConcurrentProcesses, includeDirs = [], + includeExtensions = [], repoURL = 'https://github.com/example/example', getReleaseTagURL = defaultReleaseTagURLHandler, getReleaseTagsURL = defaultReleaseTagsURLHandler, @@ -313,6 +320,7 @@ export function GitChangelog(options: GitChangelogOptions = {}): Plugin { getReleaseTagsURL, gitLogsRaw.all, includeDirs, + includeExtensions, options.rewritePaths, options.rewritePathsBy, )