MCPcopy Create free account
hub / github.com/cloudflare/templates / validateD2CButtons

Function validateD2CButtons

cli/src/validateD2CButtons.ts:10–41  ·  view source on GitHub ↗
({
	templateDirectory,
}: ValidateD2CButtonsConfig)

Source from the content-addressed store, hash-verified

8};
9
10export 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 = `[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/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}

Callers 1

index.tsFile · 0.90

Calls 1

getAllTemplatesFunction · 0.90

Tested by

no test coverage detected