forked from catppuccin/userstyles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadme-repo.ts
More file actions
88 lines (76 loc) 路 2.35 KB
/
Copy pathreadme-repo.ts
File metadata and controls
88 lines (76 loc) 路 2.35 KB
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
78
79
80
81
82
83
84
85
86
87
88
import type { PortsSchema, UserstylesSchema } from "@/types/mod.ts";
import { REPO_ROOT } from "@/constants.ts";
import * as path from "@std/path";
import Handlebars from "handlebars";
import { updateReadme } from "@/generate/utils.ts";
type MappedPorts = {
[k: string]: (
UserstylesSchema.Userstyle & { path: string }
)[];
};
export async function generateMainReadme(
userstyles: UserstylesSchema.Userstyles,
portsData: PortsSchema.PortsSchema,
) {
if (!portsData.categories) throw ("Ports data is missing categories");
const categorized = Object.entries(userstyles)
.reduce((acc, [slug, { categories, ...port }]) => {
// initialize category array if it doesn't exist
// only care about the first (primary) category in the categories array
acc[categories[0]] ??= [];
acc[categories[0]].push({
path: `styles/${slug}`,
categories,
...port,
});
// Sort by name, first array entry if necessary
acc[categories[0]].sort((a, b) =>
[a.name].flat()[0].localeCompare([b.name].flat()[0])
);
return acc;
}, {} as MappedPorts);
const portListData = portsData.categories
.filter((category) => categorized[category.key] !== undefined)
.map((category) => {
return { meta: category, ports: categorized[category.key] };
});
const portContent = Handlebars.compile(`{{#each category}}
<details open>
<summary>{{emoji}} {{name}}</summary>
{{#each ports}}
- {{#unless maintained}}馃毀 {{/unless}}[{{#each name}}{{ this }}{{#unless @last}}, {{/unless}}{{/each}}]({{ path }})
{{/each}}
</details>
{{/each}}`)({
category: portListData.map(({ meta, ports }) => {
return {
emoji: meta.emoji,
name: meta.name,
ports: ports.map(
(
{
name,
path,
"current-maintainers": currentMaintainers,
},
) => {
return {
name: [name].flat(),
maintained: currentMaintainers.length > 0,
path,
};
},
),
};
}),
});
const readmePath = path.join(REPO_ROOT, "README.md");
await Deno.writeTextFile(
readmePath,
updateReadme({
readme: Deno.readTextFileSync(readmePath),
section: "userstyles",
newContent: portContent,
}),
).catch((e) => console.error(e));
}