refactor(scripts): pull in separate categories.schema.json (#1658)

This commit is contained in:
Hammy authored and GitHub committed 2025-03-20 08:39:11 -04:00
1 parent ef1a2be3c2
commit ac0f3f6677
8 files changed
+106 -99

No files matched your search

+2 -2
View File
@@ -1,4 +1,4 @@
import PORTS_SCHEMA from "@catppuccin/catppuccin/resources/ports.schema.json" with {
import CATEGORIES_SCHEMA from "@catppuccin/catppuccin/resources/categories.schema.json" with {
type: "json",
};
import USERSTYLES_SCHEMA from "@/userstyles.schema.json" with {
@@ -15,4 +15,4 @@ if (!ROOT) throw new Error("ROOT was not located.");
*/
export const REPO_ROOT = path.join(ROOT, "..");
export { PORTS_SCHEMA, USERSTYLES_SCHEMA };
export { CATEGORIES_SCHEMA, USERSTYLES_SCHEMA };
+3 -3
View File
@@ -7,7 +7,7 @@ import { generateStyleReadmes } from "@/generate/readme-styles.ts";
import { writeWithPreamble } from "@/generate/utils.ts";
import {
getAuthenticatedOctokit,
getPortsData,
getCategoriesData,
getUserstylesData,
getUserstylesTeamMembers,
} from "@/utils.ts";
@@ -19,12 +19,12 @@ if (!Deno.env.get("CI")) {
}
const userstylesData = getUserstylesData();
const portsData = await getPortsData();
const categoriesData = await getCategoriesData();
/**
* Generate the main README.md, listing all ports as a table of contents
*/
await generateMainReadme(userstylesData.userstyles, portsData);
await generateMainReadme(userstylesData.userstyles, categoriesData);
/**
* Generate README.md files for each style
*/
+4 -4
View File
@@ -1,4 +1,4 @@
import type { PortsSchema, UserstylesSchema } from "@/types/mod.ts";
import type { CategoriesSchema, UserstylesSchema } from "@/types/mod.ts";
import { REPO_ROOT } from "@/constants.ts";
import * as path from "@std/path";
@@ -14,9 +14,9 @@ type MappedPorts = {
export async function generateMainReadme(
userstyles: UserstylesSchema.Userstyles,
portsData: PortsSchema.PortsSchema,
categoriesData: CategoriesSchema.CategoryDefinitions,
) {
if (!portsData.categories) throw ("Ports data is missing categories");
if (!categoriesData) throw ("Categories data is missing categories");
const categorized = Object.entries(userstyles)
.reduce((acc, [slug, { categories, ...port }]) => {
@@ -37,7 +37,7 @@ export async function generateMainReadme(
return acc;
}, {} as MappedPorts);
const portListData = portsData.categories
const portListData = categoriesData
.filter((category) => categorized[category.key] !== undefined)
.map((category) => {
return { meta: category, ports: categorized[category.key] };
+1 -1
View File
@@ -1,2 +1,2 @@
export * as UserstylesSchema from "@/types/userstyles.d.ts";
export * as PortsSchema from "@catppuccin/catppuccin/resources/types/ports.d.ts";
export * as CategoriesSchema from "@catppuccin/catppuccin/resources/types/categories.d.ts";
+38 -52
View File
@@ -14,7 +14,9 @@
"title": "Userstyle",
"type": "object",
"description": "The directory of the userstyle.",
"examples": ["youtube"],
"examples": [
"youtube"
],
"additionalProperties": false,
"properties": {
"name": {
@@ -28,11 +30,18 @@
"type": "string"
},
"minItems": 2,
"examples": [["AniList", "AniChart"]]
"examples": [
[
"AniList",
"AniChart"
]
]
},
{
"type": "string",
"examples": ["YouTube"]
"examples": [
"YouTube"
]
}
]
},
@@ -64,14 +73,19 @@
"lavender",
"text"
],
"examples": ["pink"]
"examples": [
"pink"
]
},
"icon": {
"$id": "#userstyles/userstyle/icon",
"title": "Icon",
"description": "The icon to use on the website. This should be the same name as the SVG file on https://simpleicons.org/. If a `.svg` suffix is present, it's taken from the local website repository resources.",
"type": "string",
"examples": ["twitch", "twitch.svg"]
"examples": [
"twitch",
"twitch.svg"
]
},
"readme": {
"$id": "#userstyles/userstyle/readme",
@@ -92,12 +106,17 @@
},
"minItems": 2,
"examples": [
["https://anilist.co", "https://anichart.net"]
[
"https://anilist.co",
"https://anichart.net"
]
]
},
{
"type": "string",
"examples": ["https://github.com"]
"examples": [
"https://github.com"
]
}
]
},
@@ -128,11 +147,16 @@
"description": "An answer to the question about the userstyle."
}
},
"required": ["question", "answer"]
"required": [
"question",
"answer"
]
}
}
},
"required": ["app-link"]
"required": [
"app-link"
]
},
"current-maintainers": {
"$id": "#userstyles/userstyle/current-maintainers",
@@ -183,58 +207,20 @@
"description": "The GitHub profile link of the collaborator to show in the userstyle README."
}
},
"required": ["url"]
"required": [
"url"
]
}
},
"categories": {
"$id": "#categories",
"type": "array",
"description": "The categories that fit the port the most, the first category is the primary category which the port will be listed under on the README.",
"minItems": 1,
"maxItems": 3,
"items": {
"$ref": "#/$defs/category"
"$ref": "https://raw.githubusercontent.com/catppuccin/catppuccin/refs/heads/main/resources/categories.schema.json#/$defs/category"
}
},
"category": {
"$id": "#category",
"type": "string",
"enum": [
"3d_modelling",
"analytics",
"application_launcher",
"artificial_intelligence",
"boot_loader",
"browser",
"browser_extension",
"cli",
"code_editor",
"desktop_environment",
"development",
"discussion_forum",
"document_viewer",
"education",
"email_client",
"entertainment",
"file_manager",
"game",
"game_development",
"health_and_fitness",
"library",
"music",
"note_taking",
"notification_daemon",
"photo_and_video",
"productivity",
"search_engine",
"self_hosted",
"social_networking",
"system",
"terminal",
"translation_tool",
"userstyle",
"wiki",
"window_manager"
]
}
}
}
+40 -32
View File
@@ -1,6 +1,10 @@
import type { PortsSchema, UserstylesSchema } from "@/types/mod.ts";
import type { CategoriesSchema, UserstylesSchema } from "@/types/mod.ts";
import type { SetRequired } from "type-fest/source/set-required.d.ts";
import { PORTS_SCHEMA, REPO_ROOT, USERSTYLES_SCHEMA } from "@/constants.ts";
import {
CATEGORIES_SCHEMA,
REPO_ROOT,
USERSTYLES_SCHEMA,
} from "@/constants.ts";
import * as yaml from "@std/yaml";
import * as path from "@std/path";
@@ -19,23 +23,26 @@ export function validateYaml<T>(
content: string,
schema: Schema,
file: string,
options?: Ajv.Options,
): T {
const ajv = new Ajv.default();
const ajv = new Ajv.default(options);
const validate = ajv.compile<T>(schema);
const data = yaml.parse(content);
if (!validate(data)) {
log.error(
validate.errors!.map((err) =>
sprintf(
"%s %s%s",
err.instancePath.slice(1).replaceAll("/", "."),
err.message,
err.params.allowedValues
? ` (${JSON.stringify(err.params.allowedValues, undefined)})`
: "",
validate
.errors!.map((err) =>
sprintf(
"%s %s%s",
err.instancePath.slice(1).replaceAll("/", "."),
err.message,
err.params.allowedValues
? ` (${JSON.stringify(err.params.allowedValues, undefined)})`
: "",
)
)
).join(" and "),
.join(" and "),
{
file,
},
@@ -60,6 +67,7 @@ export function getUserstylesData(): Userstyles {
content,
USERSTYLES_SCHEMA,
"scripts/userstyles.yml",
{ schemas: [CATEGORIES_SCHEMA] },
);
for (const field of ["userstyles", "collaborators"] as const) {
@@ -76,15 +84,14 @@ export function getUserstylesData(): Userstyles {
if (err instanceof Error && err.name === "SyntaxError") {
const groups =
/(?<message>.*) at line (?<line>\d+), column (?<column>\d+):[\S\s]*/
.exec(err.message)?.groups;
log.error(
groups!.message,
{
file: "scripts/userstyles.yml",
startLine: Number(groups!.line),
content: content,
},
);
.exec(
err.message,
)?.groups;
log.error(groups!.message, {
file: "scripts/userstyles.yml",
startLine: Number(groups!.line),
content: content,
});
} else {
throw err;
}
@@ -97,15 +104,17 @@ export function getUserstylesData(): Userstyles {
* Utility function that calls {@link validateYaml} on the ports.yml file.
* Fails when data.userstyles is undefined.
*/
export async function getPortsData(): Promise<PortsSchema.PortsSchema> {
export async function getCategoriesData(): Promise<
CategoriesSchema.CategoryDefinitions
> {
const content = await fetch(
"https://raw.githubusercontent.com/catppuccin/catppuccin/main/resources/ports.yml",
"https://raw.githubusercontent.com/catppuccin/catppuccin/de9d2cd963059753c8fd66fbb6f807be95c6cc1e/resources/categories.yml",
).then((res) => res.text());
const data = validateYaml<PortsSchema.PortsSchema>(
const data = validateYaml<CategoriesSchema.CategoryDefinitions>(
content,
PORTS_SCHEMA,
"ports.yml",
CATEGORIES_SCHEMA,
"categories.yml",
);
return data;
@@ -160,12 +169,11 @@ export async function getUserstylesTeamMembers(
octokit: Octokit,
team: UserstylesTeam,
): Promise<string[]> {
const members = await octokit.teams
.listMembersInOrg({
org: "catppuccin",
team_slug: team,
per_page: 100,
});
const members = await octokit.teams.listMembersInOrg({
org: "catppuccin",
team_slug: team,
per_page: 100,
});
return members.data.map(({ login }) => login.toLowerCase());
}