-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
77 lines (62 loc) · 2.03 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { exists } from "jsr:@std/fs";
import { parse } from "jsr:@std/yaml";
import { z } from "https://deno.land/x/[email protected]/mod.ts";
// Clone oss-fuzz
if (!(await exists("./output"))) {
const cmd = new Deno.Command("git", {
args: [
"clone",
"--depth",
"1",
"https://github.com/google/oss-fuzz",
"./output",
],
});
const { code } = await cmd.output();
if (code !== 0) {
console.error("git clone failed.");
Deno.exit(1);
}
}
const projectSchema = z.object({
homepage: z.string().optional(),
main_repo: z.string().optional(),
language: z.string().optional(),
});
type Project = z.infer<typeof projectSchema>;
const projects: Record<string, (Project | [error: unknown])> = {};
// Go to projects, and acc projects
for await (const dirEntry of Deno.readDir("./output/projects")) {
const projectYAML = await Deno.readTextFile(
`./output/projects/${dirEntry.name}/project.yaml`,
);
try {
const parsedYAML = parse(projectYAML);
const sanitizedYAML = await projectSchema.safeParseAsync(parsedYAML);
if (sanitizedYAML.error) {
console.error(`Error while getting metadata from ${dirEntry.name}:`);
projects[dirEntry.name] = [JSON.stringify(sanitizedYAML.error)];
}
projects[dirEntry.name] = sanitizedYAML.data!;
} catch (e) {
projects[dirEntry.name] = [JSON.stringify(e)];
}
}
function markdownProject(name: string, project: Project | [error: unknown]) {
if (Array.isArray(project)) {
return `Couldn't parse. [View file](https://github.com/google/oss-fuzz/blob/master/projects/${name}/project.yaml).`;
}
return `([homepage](${project.homepage})) made in ${project.language}`;
}
await Deno.writeTextFile("./data.json", JSON.stringify(projects, null, 2));
await Deno.writeTextFile(
"./README.md",
`# fuzz-directory
sorted and usable list from [oss-fuzz](https://github.com/google/oss-fuzz/).
## Projects
${
Object.entries(projects).map(([name, project]) => {
return `- ${name}: ${markdownProject(name, project)}`;
}).join("\n")
}`,
);