2023-07-21 23:07:57 +00:00
|
|
|
#!/usr/bin/env -S deno run --allow-env --allow-read --allow-write --allow-net
|
|
|
|
|
2023-11-21 14:25:59 +00:00
|
|
|
import { join } from "std/path/mod.ts";
|
2023-07-21 23:07:57 +00:00
|
|
|
import {
|
|
|
|
portsSchema,
|
2023-11-21 14:25:59 +00:00
|
|
|
updateReadme,
|
2023-07-21 23:07:57 +00:00
|
|
|
userstylesSchema,
|
|
|
|
userstylesYaml,
|
2023-11-21 14:25:59 +00:00
|
|
|
validateYaml,
|
|
|
|
} from "@/deps.ts";
|
|
|
|
import type { PortsSchema, UserStylesSchema } from "@/types/mod.ts";
|
2023-01-29 20:54:12 +00:00
|
|
|
|
|
|
|
const root = new URL(".", import.meta.url).pathname;
|
|
|
|
|
2023-11-21 14:25:59 +00:00
|
|
|
const portsYaml = Deno.readTextFileSync(join(root, "../ports.yml"));
|
|
|
|
|
|
|
|
const [portsData, userstylesData] = await Promise.all([
|
|
|
|
await validateYaml<PortsSchema.PortsSchema>(
|
|
|
|
portsYaml,
|
|
|
|
portsSchema,
|
|
|
|
),
|
|
|
|
await validateYaml<UserStylesSchema.UserstylesSchema>(
|
|
|
|
userstylesYaml,
|
|
|
|
userstylesSchema,
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
if (!portsData.ports || !portsData.categories || !userstylesData.userstyles) {
|
|
|
|
throw new Error("ports.yml is empty");
|
2023-07-21 23:07:57 +00:00
|
|
|
}
|
2023-01-29 20:54:12 +00:00
|
|
|
|
2023-07-21 23:07:57 +00:00
|
|
|
const ports = Object.assign(portsData.ports, userstylesData.userstyles);
|
|
|
|
|
2023-11-21 14:25:59 +00:00
|
|
|
export type MappedPort = (PortsSchema.Port | UserStylesSchema.Userstyle) & {
|
|
|
|
html_url: string;
|
|
|
|
};
|
2023-07-21 23:07:57 +00:00
|
|
|
|
2023-11-21 14:25:59 +00:00
|
|
|
const categorized = Object.entries(ports)
|
|
|
|
.reduce(
|
|
|
|
(acc, [slug, port]) => {
|
|
|
|
// create a new array if it doesn't exist
|
|
|
|
acc[port.category] ??= [];
|
|
|
|
|
|
|
|
acc[port.category].push({
|
|
|
|
html_url: `https://github.com/catppuccin/${
|
|
|
|
port.readme ? `userstyles/tree/main/styles/${slug}` : slug
|
|
|
|
}`,
|
|
|
|
...port,
|
|
|
|
name: [port.name].flat().join(", "),
|
|
|
|
});
|
|
|
|
acc[port.category].sort((a, b) =>
|
|
|
|
[a.name].flat()[0].localeCompare([b.name].flat()[0])
|
|
|
|
);
|
|
|
|
return acc;
|
|
|
|
},
|
|
|
|
{} as Record<string, MappedPort[]>,
|
|
|
|
);
|
2023-07-21 23:07:57 +00:00
|
|
|
|
|
|
|
const portListData = portsData.categories.map((category) => {
|
2023-01-29 20:54:12 +00:00
|
|
|
return {
|
|
|
|
meta: category,
|
|
|
|
ports: categorized[category.key],
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2023-11-21 14:25:59 +00:00
|
|
|
const readmePath = join(root, "../../README.md");
|
2023-01-29 20:54:12 +00:00
|
|
|
let readmeContent = Deno.readTextFileSync(readmePath);
|
|
|
|
|
2023-07-21 23:07:57 +00:00
|
|
|
const portContent = portListData
|
|
|
|
.map((data) => {
|
|
|
|
return `<details open>
|
2023-01-29 20:54:12 +00:00
|
|
|
<summary>${data.meta.emoji} ${data.meta.name}</summary>
|
|
|
|
|
|
|
|
${data.ports.map((port) => `- [${port.name}](${port.html_url})`).join("\n")}
|
|
|
|
|
|
|
|
</details>`;
|
2023-07-21 23:07:57 +00:00
|
|
|
})
|
|
|
|
.join("\n");
|
|
|
|
|
|
|
|
const showcaseContent = portsData.showcases
|
2023-11-21 14:25:59 +00:00
|
|
|
?.map((showcase) => {
|
2023-07-21 23:07:57 +00:00
|
|
|
return `- [${showcase.title}](${showcase.link}) - ${showcase.description}`;
|
|
|
|
})
|
|
|
|
.join("\n");
|
2023-01-29 20:54:12 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
readmeContent = updateReadme({
|
|
|
|
readme: readmeContent,
|
|
|
|
section: "portlist",
|
|
|
|
newContent: portContent,
|
|
|
|
});
|
2023-11-21 14:25:59 +00:00
|
|
|
showcaseContent && (
|
|
|
|
readmeContent = updateReadme({
|
|
|
|
readme: readmeContent,
|
|
|
|
section: "showcase",
|
|
|
|
newContent: showcaseContent,
|
|
|
|
})
|
|
|
|
);
|
2023-01-29 20:54:12 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.log("Failed to update the README:", e);
|
|
|
|
} finally {
|
|
|
|
Deno.writeTextFileSync(readmePath, readmeContent);
|
|
|
|
}
|