()
| 234 | } |
| 235 | |
| 236 | async function main(): Promise<void> { |
| 237 | const response = await fetch(SPONSORS_SOURCE_URL) |
| 238 | |
| 239 | if (!response.ok) { |
| 240 | throw new Error(`Failed to fetch sponsors data: ${response.status} ${response.statusText}`) |
| 241 | } |
| 242 | |
| 243 | const sponsors = (await response.json() as Sponsor[]).map(sponsor => ({ ...sponsor, link: withTracking(sponsor.link) })) |
| 244 | await writeWebsiteSponsorsFile(sponsors) |
| 245 | const readmeFiles = await findReadmes(ROOT_DIR) |
| 246 | const replacement = buildSponsorsSection(sponsors) |
| 247 | |
| 248 | const readmeContents = await Promise.all( |
| 249 | readmeFiles.map(readmePath => readFile(readmePath, 'utf8')), |
| 250 | ) |
| 251 | |
| 252 | const writePromises: Promise<void>[] = [] |
| 253 | let updatedCount = 0 |
| 254 | |
| 255 | for (const [i, content] of readmeContents.entries()) { |
| 256 | const nextContent = replaceSponsorsSection(content, replacement) |
| 257 | |
| 258 | if (nextContent !== content) { |
| 259 | writePromises.push(writeFile(readmeFiles[i]!, nextContent)) |
| 260 | updatedCount += 1 |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | await Promise.all(writePromises) |
| 265 | console.log(`Updated sponsors section in ${updatedCount} README files.`) |
| 266 | } |
| 267 | |
| 268 | main().catch((error) => { |
| 269 | console.error(error) |
no test coverage detected