({
templateDirectory,
}: ValidateD2CButtonsConfig)
| 8 | }; |
| 9 | |
| 10 | export async function validateD2CButtons({ |
| 11 | templateDirectory, |
| 12 | }: ValidateD2CButtonsConfig) { |
| 13 | const templates = getAllTemplates(templateDirectory); |
| 14 | const successes: string[] = []; |
| 15 | const errors: string[] = []; |
| 16 | let numBadStatuses = 0; |
| 17 | await Promise.all( |
| 18 | templates.map(async ({ name }) => { |
| 19 | const readmePath = path.join(templateDirectory, name, "README.md"); |
| 20 | const contents = fs.readFileSync(readmePath, "utf-8"); |
| 21 | const url = `https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/templates/tree/main/${name}`; |
| 22 | const button = `[](${url})`; |
| 23 | if (contents.indexOf(button) === -1) { |
| 24 | numBadStatuses++; |
| 25 | errors.push( |
| 26 | `Please add the following to \`${name}/README.md\`:`, |
| 27 | ["```md", button, "```"].join("\n"), |
| 28 | ); |
| 29 | } else { |
| 30 | successes.push(`- ✅ [${name}](${url})`); |
| 31 | } |
| 32 | }), |
| 33 | ); |
| 34 | if (errors.length) { |
| 35 | throw new MarkdownError( |
| 36 | `Found ${numBadStatuses} ${numBadStatuses === 1 ? "template" : "templates"} without valid Deploy to Cloudflare links in \`README.md\`.`, |
| 37 | errors.join("\n\n"), |
| 38 | ); |
| 39 | } |
| 40 | return successes.join("\n"); |
| 41 | } |
no test coverage detected