MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / updateDocsJsonWithChangelogs

Function updateDocsJsonWithChangelogs

scripts/get-changelog.ts:234–296  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

232}
233
234async function updateDocsJsonWithChangelogs() {
235 const docsJsonPath = path.join(process.cwd(), 'changelog', 'docs.json')
236 const changelogDir = path.join(process.cwd(), 'changelog')
237 const changelogFiles = fs
238 .readdirSync(changelogDir)
239 .filter((file) => file.endsWith('.mdx'))
240 .sort()
241
242 // Group changelogs by quarter
243 const changelogGroups: { [key: string]: string[] } = {}
244 for (const file of changelogFiles) {
245 const match = file.match(/(\d{4})-(\d{2})-\d{2}-.+/)
246 if (!match) continue
247 const year = match[1]
248 const month = parseInt(match[2], 10)
249 let quarter = 'Q1'
250 if (month >= 10) quarter = 'Q4'
251 else if (month >= 7) quarter = 'Q3'
252 else if (month >= 4) quarter = 'Q2'
253 // else Q1
254 const groupName = `${quarter} ${year}`
255 if (!changelogGroups[groupName]) changelogGroups[groupName] = []
256 changelogGroups[groupName].push(`changelog/${file.replace(/\.mdx$/, '')}`)
257 }
258
259 // Read and parse docs.json
260 let docsJson: any
261 try {
262 docsJson = JSON.parse(fs.readFileSync(docsJsonPath, 'utf-8'))
263 } catch (error) {
264 docsJson = { navigation: { tabs: [{ tab: 'Changelog', groups: [] }] } }
265 }
266 const tabs: { tab: string; groups: { group: string; pages: string[] }[] }[] =
267 docsJson.navigation.tabs
268 const changelogTab = tabs.find((tab) => tab.tab === 'Changelog')
269 if (!changelogTab) return
270
271 // Replace groups with new changelog groups, sorted by most recent year and quarter (Q4, Q3, Q2, Q1)
272 changelogTab.groups = Object.entries(changelogGroups)
273 .sort((a, b) => {
274 // a[0] and b[0] are like 'Q3 2024'
275 const [qa, ya] = a[0].split(' ')
276 const [qb, yb] = b[0].split(' ')
277 // Sort by year descending
278 if (yb !== ya) return parseInt(yb) - parseInt(ya)
279 // Sort by quarter: Q4 > Q3 > Q2 > Q1
280 const quarterOrder: { [key: string]: number } = {
281 Q4: 4,
282 Q3: 3,
283 Q2: 2,
284 Q1: 1,
285 }
286 return quarterOrder[qb] - quarterOrder[qa]
287 })
288 .map(([group, pages]) => ({
289 group,
290 pages: (pages as string[]).sort((a, b) => b.localeCompare(a)), // latest post on top
291 }))

Callers 1

generateAllChangelogsFunction · 0.85

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected