MCPcopy
hub / github.com/matschik/component-party.dev / main

Function main

scripts/generateReadMeProgress.js:8–67  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6import prettier from "prettier";
7
8async function main() {
9 const codeContentDir = await parseContentDir();
10 const readmeContent = await fs.readFile("./README.md", "utf8");
11
12 let progressionContent = "";
13 for (const framework of FRAMEWORKS) {
14 function mdCheck(b) {
15 return b ? "x" : " ";
16 }
17
18 let list = "";
19 const allChecks = [];
20 for (const rootDir of codeContentDir) {
21 let sublist = "";
22 const checks = [];
23 for (const subdir of rootDir.children) {
24 const isChecked =
25 subdir.children.find((n) => n.dirName === framework.id)?.files
26 .length > 0;
27 checks.push(isChecked);
28 sublist += ` * [${mdCheck(isChecked)}] ${subdir.title}\n`;
29 }
30 list += `* [${mdCheck(checks.every((v) => v))}] ${rootDir.title}\n`;
31 list += sublist;
32 allChecks.push(...checks);
33 }
34
35 const percent = Math.ceil(
36 (allChecks.filter((v) => v).length / allChecks.length) * 100
37 );
38 let frameworkContent = `<details>
39 <summary>
40 <img width="18" height="18" src="public/${framework.img}" />
41 <b>${framework.title}</b>
42 <img src="https://us-central1-progress-markdown.cloudfunctions.net/progress/${percent}" /></summary>
43
44${list}
45</details>`;
46 progressionContent += frameworkContent;
47 }
48
49 const MARKER_START = "<!-- progression start -->";
50 const MARKER_END = "<!-- progression end -->";
51 const progressionContentRegex = new RegExp(
52 `${MARKER_START}([\\s\\S]*?)${MARKER_END}`
53 );
54
55 const newProgressionContent =
56 "\n" +
57 (await prettier.format(progressionContent, {
58 parser: "markdown",
59 }));
60
61 const newReadmeContent = readmeContent.replace(
62 progressionContentRegex,
63 `${MARKER_START}${newProgressionContent}${MARKER_END}`
64 );
65

Callers 1

Calls 2

parseContentDirFunction · 0.85
mdCheckFunction · 0.85

Tested by

no test coverage detected