forked from catppuccin/userstyles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadme-styles.ts
More file actions
84 lines (76 loc) 路 2.19 KB
/
Copy pathreadme-styles.ts
File metadata and controls
84 lines (76 loc) 路 2.19 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
import type { UserstylesSchema } from "@/types/mod.ts";
import { REPO_ROOT } from "@/constants.ts";
import * as path from "@std/path";
import Handlebars from "handlebars";
// we can have some nice things :)
Handlebars.registerHelper(
"pluralize",
(c: number | unknown[], str: string): string => {
if (typeof c === "undefined") return str;
const num = Array.isArray(c) ? c.length : c;
return num === 1 ? str : `${str}s`;
},
);
const heading = (
name: UserstylesSchema.Name,
link: UserstylesSchema.ApplicationLink,
) => {
const [nameArray, linkArray] = [[name].flat(), [link].flat()];
if (nameArray.length !== linkArray.length) {
throw new Error(
'The "name" and "app-link" arrays must have the same length',
);
}
return nameArray.map((title, i) => {
return { title, url: linkArray[i] };
});
};
function extractName(
collaborators?:
| UserstylesSchema.CurrentMaintainers
| UserstylesSchema.PastMaintainers,
) {
// no-op when undefined
if (!collaborators) return;
// set the name to the github.com/<name>
return collaborators.map((c) => {
c.name ??= c.url.split("/").pop();
return c;
});
}
export function generateStyleReadmes(userstyles: UserstylesSchema.Userstyles) {
const stylesReadmePath = path.join(
REPO_ROOT,
"scripts/generate/templates/userstyle.md",
);
const stylesReadmeContent = Deno.readTextFileSync(stylesReadmePath);
Object.entries(userstyles).map(
(
[
slug,
{
name,
readme,
"current-maintainers": currentMaintainers,
"past-maintainers": pastMaintainers,
},
],
) => {
console.log(`Generating README for ${slug}`);
const readmeContent = Handlebars.compile(stylesReadmeContent)({
heading: heading(name, readme["app-link"]),
slug,
usage: readme.usage,
faq: readme.faq,
collaborators: {
currentMaintainers: extractName(currentMaintainers),
pastMaintainers: extractName(pastMaintainers),
},
});
Deno.writeTextFile(
path.join(REPO_ROOT, "styles", slug.toString(), "README.md"),
readmeContent,
).catch((e) => console.error(e));
},
);
}