forked from npmx-dev/npmx.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchangelog.ts
More file actions
48 lines (44 loc) · 1.22 KB
/
changelog.ts
File metadata and controls
48 lines (44 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import type { JsDelivrFileNode } from '#shared/types'
/**
* Changelog filenames to check (case-insensitive match, priority order)
* Based on common conventions in npm packages
*/
export const CHANGELOG_FILENAMES = [
'CHANGELOG.md',
'CHANGELOG',
'CHANGELOG.txt',
'changelog.md',
'changelog',
'HISTORY.md',
'HISTORY',
'history.md',
'CHANGES.md',
'CHANGES',
'changes.md',
'NEWS.md',
'RELEASES.md',
] as const
/**
* Find a changelog file in the package's root-level files.
* Returns the actual filename if found, null otherwise.
*
* @param files - The file tree from jsDelivr API (root-level files only)
* @returns The changelog filename if found, null otherwise
*/
export function findChangelogFile(files: JsDelivrFileNode[]): string | null {
// Create a map for case-insensitive lookup of actual filenames
const fileMap = new Map<string, string>()
for (const file of files) {
if (file.type === 'file') {
fileMap.set(file.name.toLowerCase(), file.name)
}
}
// Check for changelog files in priority order
for (const changelogName of CHANGELOG_FILENAMES) {
const actualName = fileMap.get(changelogName.toLowerCase())
if (actualName) {
return actualName
}
}
return null
}