Skip to content

Commit

Permalink
refactor: remove userstyles from metadata
Browse files Browse the repository at this point in the history
Instead, we're grabbing it from
https://github.com/catppuccin/userstyles.

Co-authored-by: rubyowo <perhaps-you-know@what-is.ml>
  • Loading branch information
sgoudham and rubyowo committed Jul 21, 2023
1 parent 53d154c commit 6641f27
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 262 deletions.
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ Catppuccin is available for various apps and in different formats. Here is a lis
- [mdBook](https://github.com/catppuccin/mdBook)
- [Tailwind CSS](https://github.com/catppuccin/tailwindcss)
- [Unreal Engine](https://github.com/catppuccin/unreal-engine)
- [Vercel](https://github.com/catppuccin/vercel)
- [Vercel](https://github.com/catppuccin/userstyles/tree/main/styles/vercel)

</details>
<details open>
Expand Down Expand Up @@ -1087,10 +1087,10 @@ Catppuccin is available for various apps and in different formats. Here is a lis
<details open>
<summary>🔎 Search Engines</summary>

- [Brave Search](https://github.com/catppuccin/brave-search)
- [Brave Search](https://github.com/catppuccin/userstyles/tree/main/styles/brave-search)
- [DuckDuckGo](https://github.com/catppuccin/duckduckgo)
- [NixOS Search](https://github.com/catppuccin/nixos-search)
- [SearXNG](https://github.com/catppuccin/SearXNG)
- [NixOS Search](https://github.com/catppuccin/userstyles/tree/main/styles/nixos-search)
- [SearXNG](https://github.com/catppuccin/userstyles/tree/main/styles/searxng)
- [Startpage](https://github.com/catppuccin/startpage)
- [Whoogle](https://github.com/catppuccin/whoogle)

Expand All @@ -1099,7 +1099,7 @@ Catppuccin is available for various apps and in different formats. Here is a lis
<summary>💬 Messaging</summary>

- [Aliucord](https://github.com/catppuccin/aliucord)
- [Cinny](https://github.com/catppuccin/cinny)
- [Cinny](https://github.com/catppuccin/userstyles/tree/main/styles/cinny)
- [Discord](https://github.com/catppuccin/discord)
- [Element](https://github.com/catppuccin/element)
- [Enmity](https://github.com/catppuccin/enmity)
Expand Down Expand Up @@ -1127,59 +1127,59 @@ Catppuccin is available for various apps and in different formats. Here is a lis
- [Alfred](https://github.com/catppuccin/alfred)
- [Anki](https://github.com/catppuccin/anki)
- [Bento](https://github.com/catppuccin/bento)
- [Codeberg](https://github.com/catppuccin/codeberg)
- [DeepL](https://github.com/catppuccin/deepl)
- [Codeberg](https://github.com/catppuccin/userstyles/tree/main/styles/codeberg)
- [DeepL](https://github.com/catppuccin/userstyles/tree/main/styles/deepl)
- [DioHub](https://github.com/catppuccin/diohub)
- [Foliate](https://github.com/catppuccin/foliate)
- [FreshRSS](https://github.com/catppuccin/freshrss)
- [ghostwriter](https://github.com/catppuccin/ghostwriter)
- [Gitea](https://github.com/catppuccin/gitea)
- [GitHub](https://github.com/catppuccin/github)
- [ichi.moe](https://github.com/catppuccin/ichi.moe)
- [GitHub](https://github.com/catppuccin/userstyles/tree/main/styles/github)
- [ichi.moe](https://github.com/catppuccin/userstyles/tree/main/styles/ichi.moe)
- [Mailspring](https://github.com/catppuccin/mailspring)
- [OBS Studio](https://github.com/catppuccin/obs)
- [Pomotroid](https://github.com/catppuccin/pomotroid)
- [PowerPoint Slides](https://github.com/catppuccin/powerpoint-slides)
- [Proton](https://github.com/catppuccin/proton)
- [Proton](https://github.com/catppuccin/userstyles/tree/main/styles/proton)
- [qBittorrent](https://github.com/catppuccin/qbittorrent)
- [Raycast](https://github.com/catppuccin/raycast)
- [ShareX](https://github.com/catppuccin/sharex)
- [SolveSpace](https://github.com/catppuccin/solvespace)
- [SumatraPDF](https://github.com/catppuccin/sumatra-pdf)
- [Thunderbird](https://github.com/catppuccin/thunderbird)
- [Tutanota](https://github.com/catppuccin/tutanota)
- [WikiWand](https://github.com/catppuccin/wikiwand)
- [Tutanota](https://github.com/catppuccin/userstyles/tree/main/styles/tutanota)
- [WikiWand](https://github.com/catppuccin/userstyles/tree/main/styles/wikiwand)
- [Zathura](https://github.com/catppuccin/zathura)

</details>
<details open>
<summary>✨ Social</summary>

- [Elk](https://github.com/catppuccin/elk)
- [Elk](https://github.com/catppuccin/userstyles/tree/main/styles/elk)
- [GitHub Readme Stats](https://github.com/catppuccin/github-readme-stats)
- [GitHub Readme Tech Stack](https://github.com/catppuccin/github-readme-tech-stack)
- [Hacker News](https://github.com/catppuccin/hacker-news)
- [Hacker News](https://github.com/catppuccin/userstyles/tree/main/styles/hacker-news)
- [Infinity for Reddit](https://github.com/catppuccin/infinity)
- [Invidious](https://github.com/catppuccin/invidious)
- [Libreddit](https://github.com/catppuccin/libreddit)
- [Mastodon](https://github.com/catppuccin/mastodon)
- [Invidious](https://github.com/catppuccin/userstyles/tree/main/styles/invidious)
- [Libreddit](https://github.com/catppuccin/userstyles/tree/main/styles/libreddit)
- [Mastodon](https://github.com/catppuccin/userstyles/tree/main/styles/mastodon)
- [Misskey](https://github.com/catppuccin/misskey)
- [Nitter](https://github.com/catppuccin/nitter)
- [Reddit](https://github.com/catppuccin/reddit)
- [Twitch](https://github.com/catppuccin/twitch)
- [YouTube](https://github.com/catppuccin/youtube)
- [Nitter](https://github.com/catppuccin/userstyles/tree/main/styles/nitter)
- [Reddit](https://github.com/catppuccin/userstyles/tree/main/styles/reddit)
- [Twitch](https://github.com/catppuccin/userstyles/tree/main/styles/twitch)
- [YouTube](https://github.com/catppuccin/userstyles/tree/main/styles/youtube)

</details>
<details open>
<summary>🌈 Leisure</summary>

- [Amfora](https://github.com/catppuccin/amfora)
- [AniList](https://github.com/catppuccin/anilist)
- [AniList, AniChart](https://github.com/catppuccin/userstyles/tree/main/styles/anilist)
- [Cider](https://github.com/catppuccin/cider)
- [Dopamine](https://github.com/catppuccin/dopamine)
- [Heroic](https://github.com/catppuccin/heroic)
- [Home Assistant](https://github.com/catppuccin/home-assistant)
- [Last.fm](https://github.com/catppuccin/lastfm)
- [Last.fm](https://github.com/catppuccin/userstyles/tree/main/styles/lastfm)
- [monkeytype](https://github.com/catppuccin/monkeytype)
- [MusicBee](https://github.com/catppuccin/musicbee)
- [PyRadio](https://github.com/catppuccin/pyradio)
Expand All @@ -1199,7 +1199,7 @@ Catppuccin is available for various apps and in different formats. Here is a lis
- [Blockbench](https://github.com/catppuccin/blockbench)
- [Dwarf Fortress](https://github.com/catppuccin/dwarf-fortress)
- [Minecraft](https://github.com/catppuccin/minecraft)
- [Modrinth](https://github.com/catppuccin/modrinth)
- [Modrinth](https://github.com/catppuccin/userstyles/tree/main/styles/modrinth)
- [Moon Animator 2](https://github.com/catppuccin/moon-animator-2)
- [Prism Launcher](https://github.com/catppuccin/prismlauncher)
- [ULTRAKILL](https://github.com/catppuccin/ultrakill)
Expand Down
3 changes: 2 additions & 1 deletion resources/generate/deno.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"https://deno.land/std@0.172.0/path/posix.ts": "0874b341c2c6968ca38d323338b8b295ea1dae10fa872a768d812e2e7d634789",
"https://deno.land/std@0.172.0/path/separator.ts": "0fb679739d0d1d7bf45b68dacfb4ec7563597a902edbaf3c59b50d5bcadd93b1",
"https://deno.land/std@0.172.0/path/win32.ts": "672942919dd66ce1b8c224e77d3447e2ad8254eaff13fe6946420a9f78fa141e",
"https://deno.land/std@0.172.0/types.d.ts": "220ed56662a0bd393ba5d124aa6ae2ad36a00d2fcbc0e8666a65f4606aaa9784"
"https://deno.land/std@0.172.0/types.d.ts": "220ed56662a0bd393ba5d124aa6ae2ad36a00d2fcbc0e8666a65f4606aaa9784",
"https://raw.githubusercontent.com/catppuccin/userstyles/main/src/userstyles.schema.json": "6613d4fe2df651c606a885212b4232e5250e5f401f1b349d1801cf63428b0fab"
},
"npm": {
"specifiers": {
Expand Down
9 changes: 7 additions & 2 deletions resources/generate/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ export { parse as parseYaml } from "https://deno.land/std@0.172.0/encoding/yaml.

import Ajv from "npm:ajv@8.12.0";
import * as path from "https://deno.land/std@0.172.0/path/mod.ts";
import schema from "../ports.schema.json" assert { type: "json" };
import portsSchema from "../ports.schema.json" assert { type: "json" };
const userstylesYaml = await fetch(
"https://raw.githubusercontent.com/catppuccin/userstyles/main/src/userstyles.yml",
);
import userstylesSchema from "https://raw.githubusercontent.com/catppuccin/userstyles/main/src/userstyles.schema.json" assert { type: "json" };
import type { Userstyle, Userstyles } from "https://raw.githubusercontent.com/catppuccin/userstyles/main/src/generate/types.d.ts";

export { Ajv, path, schema };
export { Ajv, path, portsSchema, userstylesSchema, userstylesYaml, Userstyle, Userstyles };
213 changes: 124 additions & 89 deletions resources/generate/main.ts
Original file line number Diff line number Diff line change
@@ -1,110 +1,145 @@
#!/usr/bin/env -S deno run --allow-env --allow-read --allow-write

import { Ajv, parseYaml, path, schema } from "./deps.ts";
import type { Categories, Port, Ports, Showcases } from "./types.d.ts";
#!/usr/bin/env -S deno run --allow-env --allow-read --allow-write --allow-net

import {
Ajv,
parseYaml,
path,
portsSchema,
userstylesSchema,
userstylesYaml,
Userstyle,
Userstyles,
} from './deps.ts'
import type { Categories, Port, Ports, Showcases } from './types.d.ts'

const root = new URL('.', import.meta.url).pathname

type PortsMetadata = {
categories: Categories
ports: Ports
showcases: Showcases
}

const root = new URL(".", import.meta.url).pathname;
type UserstylesMetadata = {
userstyles: Userstyles
}

type Metadata = {
categories: Categories;
ports: Ports;
showcases: Showcases;
};
const ajv = new Ajv()
const validatePorts = ajv.compile<PortsMetadata>(portsSchema)
const validateUserstyles = ajv.compile<PortsMetadata>(userstylesSchema)

const ajv = new Ajv();
const validate = ajv.compile<Metadata>(schema);
const portsYaml = Deno.readTextFileSync(path.join(root, '../ports.yml'))
const portsData = parseYaml(portsYaml) as PortsMetadata

const portsYaml = Deno.readTextFileSync(path.join(root, "../ports.yml"));
const data = parseYaml(portsYaml) as Metadata;
const userstylesData = parseYaml(
await userstylesYaml.text()
) as UserstylesMetadata

// throw error if the YAML is invalid
if (!validate(data)) {
console.log(validate.errors);
Deno.exit(1);
if (!validatePorts(portsData)) {
console.log(validatePorts.errors)
Deno.exit(1)
}

if (!validateUserstyles(userstylesData)) {
console.log(validateUserstyles.errors)
Deno.exit(1)
}

export type MappedPort = Port & { html_url: string };

const categorized = Object.entries(data.ports).reduce((acc, [slug, port]) => {
!acc[port.category] && (acc[port.category] = []);
acc[port.category].push({
html_url: `https://github.com/catppuccin/${slug}`,
...port,
});
acc[port.category].sort((a, b) => a.name.localeCompare(b.name));
return acc;
}, {} as Record<string, MappedPort[]>);

const portListData = data.categories.map((category) => {
return {
meta: category,
ports: categorized[category.key],
};
});
const ports = Object.assign(portsData.ports, userstylesData.userstyles)

export type MappedPort = (Port | Userstyle) & { html_url: string }

const categorized = Object.entries(ports).reduce(
(acc, [slug, port]: [string, MappedPort]) => {
!acc[port.category] && (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.localeCompare(b.name))
return acc
},
{} as Record<string, MappedPort[]>
)

const portListData = portsData.categories.map((category) => {
return {
meta: category,
ports: categorized[category.key],
}
})

const updateReadme = ({
readme,
section,
newContent,
readme,
section,
newContent,
}: {
readme: string;
section: string;
newContent: string;
readme: string
section: string
newContent: string
}): string => {
const preamble =
"<!-- the following section is auto-generated, do not edit -->";
const markers = {
start: `<!-- AUTOGEN:${section.toUpperCase()} START -->`,
end: `<!-- AUTOGEN:${section.toUpperCase()} END -->`,
};

const wrapped = markers.start + "\n" + preamble + "\n" + newContent + "\n" +
markers.end;

if (
!(
readmeContent.includes(markers.start) &&
readmeContent.includes(markers.end)
)
) {
throw new Error("Markers not found in README.md");
}

const pre = readme.split(markers.start)[0];
const end = readme.split(markers.end)[1];

return pre + wrapped + end;
};

const readmePath = path.join(root, "../../README.md");
let readmeContent = Deno.readTextFileSync(readmePath);

const portContent = portListData.map((data) => {
return `<details open>
const preamble =
'<!-- the following section is auto-generated, do not edit -->'
const markers = {
start: `<!-- AUTOGEN:${section.toUpperCase()} START -->`,
end: `<!-- AUTOGEN:${section.toUpperCase()} END -->`,
}

const wrapped =
markers.start + '\n' + preamble + '\n' + newContent + '\n' + markers.end

if (
!(
readmeContent.includes(markers.start) &&
readmeContent.includes(markers.end)
)
) {
throw new Error('Markers not found in README.md')
}

const pre = readme.split(markers.start)[0]
const end = readme.split(markers.end)[1]

return pre + wrapped + end
}

const readmePath = path.join(root, '../../README.md')
let readmeContent = Deno.readTextFileSync(readmePath)

const portContent = portListData
.map((data) => {
return `<details open>
<summary>${data.meta.emoji} ${data.meta.name}</summary>
${data.ports.map((port) => `- [${port.name}](${port.html_url})`).join("\n")}
${data.ports.map((port) => `- [${port.name}](${port.html_url})`).join('\n')}
</details>`;
}).join("\n");
</details>`
})
.join('\n')

const showcaseContent = data.showcases.map((showcase) => {
return `- [${showcase.title}](${showcase.link}) - ${showcase.description}`;
}).join("\n");
const showcaseContent = portsData.showcases
.map((showcase) => {
return `- [${showcase.title}](${showcase.link}) - ${showcase.description}`
})
.join('\n')

try {
readmeContent = updateReadme({
readme: readmeContent,
section: "portlist",
newContent: portContent,
});
readmeContent = updateReadme({
readme: readmeContent,
section: "showcase",
newContent: showcaseContent,
});
readmeContent = updateReadme({
readme: readmeContent,
section: 'portlist',
newContent: portContent,
})
readmeContent = updateReadme({
readme: readmeContent,
section: 'showcase',
newContent: showcaseContent,
})
} catch (e) {
console.log("Failed to update the README:", e);
console.log('Failed to update the README:', e)
} finally {
Deno.writeTextFileSync(readmePath, readmeContent);
Deno.writeTextFileSync(readmePath, readmeContent)
}

0 comments on commit 6641f27

Please sign in to comment.