MCPcopy Create free account
hub / github.com/LevelUpWeb3/app / processVyperMarkdownFiles

Function processVyperMarkdownFiles

scripts/processVyperMarkdown.js:9–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7const outputDirectory = path.join(process.cwd(), "public/data/vyper");
8
9const processVyperMarkdownFiles = async () => {
10 const fileNames = fs.readdirSync(markdownDirectory);
11
12 const allChallengesDataPromises = fileNames.map(async (fileName) => {
13 const id = fileName.replace(/\.mdx$/, "");
14
15 const fullPath = path.join(markdownDirectory, fileName);
16 const fileContents = fs.readFileSync(fullPath, "utf8");
17
18 const { data } = matter(fileContents);
19 if (!data.name) return null;
20
21 const challengeData = {
22 id,
23 ...data,
24 };
25 const individualOutputPath = path.join(outputDirectory, `${id}.mdx`);
26
27 if (!fs.existsSync(outputDirectory))
28 fs.mkdirSync(outputDirectory, { recursive: true });
29 fs.writeFileSync(individualOutputPath, fileContents);
30
31 return challengeData;
32 });
33
34 const allChallengesData = await Promise.all(allChallengesDataPromises);
35
36 const markdownData = allChallengesData
37 .filter((data) => data)
38 .sort(({ index: a }, { index: b }) => {
39 return a - b;
40 });
41
42 fs.writeFileSync(
43 path.join(JSONDirectory, "markdownData.json"),
44 JSON.stringify(markdownData, null, 2),
45 ); // Pretty print JSON
46};
47
48processVyperMarkdownFiles().catch(console.error);

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected