()
| 79 | } |
| 80 | |
| 81 | async function updateStats() { |
| 82 | const existingStats = await readExistingStats() |
| 83 | |
| 84 | try { |
| 85 | const [repo, releases] = await Promise.all([ |
| 86 | fetchJson(`https://api.github.com/repos/${repository}`), |
| 87 | fetchAllReleases(), |
| 88 | ]) |
| 89 | |
| 90 | const stats = { |
| 91 | repository, |
| 92 | stars: repo.stargazers_count, |
| 93 | releaseDownloads: getReleaseDownloads(releases), |
| 94 | activeDevelopmentStartYear: startYear, |
| 95 | activeDevelopmentYears: new Date().getUTCFullYear() - startYear, |
| 96 | updatedAt: new Date().toISOString(), |
| 97 | } |
| 98 | |
| 99 | await mkdir(dirname(outputPath), { recursive: true }) |
| 100 | await writeFile(outputPath, `${JSON.stringify(stats, null, 2)}\n`) |
| 101 | |
| 102 | console.log(`Updated GitHub stats: ${stats.stars} stars, ${stats.releaseDownloads} release downloads`) |
| 103 | } |
| 104 | catch (error) { |
| 105 | const message = error instanceof Error ? error.message : String(error) |
| 106 | |
| 107 | console.warn(`Could not update GitHub stats, using existing values: ${message}`) |
| 108 | |
| 109 | await mkdir(dirname(outputPath), { recursive: true }) |
| 110 | await writeFile(outputPath, `${JSON.stringify(existingStats, null, 2)}\n`) |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | await updateStats() |
no test coverage detected