Skip to content

Commit 5bb6f6d

Browse files
ci(lint): validate name metadata (catppuccin#402)
Co-authored-by: winston <hey@winston.sh>
1 parent 8da437f commit 5bb6f6d

14 files changed

Lines changed: 95 additions & 66 deletions

File tree

deno.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"@actions/core": "npm:@actions/core@1.10.1",
77
"@octokit/rest": "npm:@octokit/rest@20.0.2",
88
"ajv": "npm:ajv@8.12.0",
9+
"type-fest/": "https://esm.sh/v135/type-fest@4.8.1/",
910
"handlebars": "npm:handlebars@4.7.8",
1011
"less": "npm:less@4.2.0",
1112
"usercss-meta": "npm:usercss-meta@0.12.0"

scripts/lint/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ for await (const entry of stylesheets) {
2828
const content = await Deno.readTextFile(entry.path);
2929

3030
// verify the usercss metadata
31-
const { globalVars, isLess } = verifyMetadata(entry, content, repo);
31+
const { globalVars, isLess } = await verifyMetadata(entry, content, repo);
3232
// don't attempt to compile or lint non-less files
3333
if (!isLess) continue;
3434

scripts/lint/metadata.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
// @deno-types="@/types/usercss-meta.d.ts";
22
import usercssMeta from "usercss-meta";
3-
import { log } from "@/lint/logger.ts";
43
import * as color from "std/fmt/colors.ts";
54
import { sprintf } from "std/fmt/printf.ts";
65
import type { WalkEntry } from "std/fs/walk.ts";
76
import { relative } from "std/path/mod.ts";
7+
88
import { REPO_ROOT } from "@/deps.ts";
9+
import { log } from "@/lint/logger.ts";
10+
import { getUserstylesData } from "@/utils.ts";
911

10-
export const verifyMetadata = (
12+
export const verifyMetadata = async (
1113
entry: WalkEntry,
1214
content: string,
1315
repo: string,
1416
) => {
15-
const assert = assertions(repo);
17+
const assert = await assertions(repo);
1618
const file = relative(REPO_ROOT, entry.path);
1719

1820
const { metadata, errors: parsingErrors } = usercssMeta.parse(content, {
@@ -67,9 +69,20 @@ export const verifyMetadata = (
6769
};
6870
};
6971

70-
const assertions = (repo: string) => {
72+
const assertions = async (repo: string) => {
7173
const prefix = "https://github.com/catppuccin/userstyles";
74+
75+
const { userstyles } = await getUserstylesData().catch((err) => {
76+
console.error(err);
77+
Deno.exit(1);
78+
});
79+
7280
return {
81+
name: `${
82+
Array.isArray(userstyles[repo].name)
83+
? (userstyles[repo].name as string[]).join("/")
84+
: userstyles[repo].name
85+
} Catppuccin`,
7386
namespace: `github.com/catppuccin/userstyles/styles/${repo}`,
7487
author: "Catppuccin",
7588
license: "MIT",

scripts/sync-maintainers/main.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
#!/usr/bin/env -S deno run -A
22
import * as assert from "std/assert/mod.ts";
3-
import * as path from "std/path/mod.ts";
43
import { Octokit } from "@octokit/rest";
54

6-
import { REPO_ROOT, userStylesSchema } from "@/deps.ts";
75
import type { UserStylesSchema } from "@/types/mod.ts";
8-
import { validateYaml } from "@/utils.ts";
9-
import { UserstylesSchema } from "@/types/userstyles.d.ts";
6+
import { getUserstylesData } from "@/utils.ts";
107

118
const octokit = new Octokit({ auth: Deno.env.get("GITHUB_TOKEN") });
129
const team = { org: "catppuccin", team_slug: "userstyles-maintainers" };
1310

14-
const userstylesData = await validateYaml<UserstylesSchema>(
15-
Deno.readTextFileSync(path.join(REPO_ROOT, "scripts/userstyles.yml")),
16-
userStylesSchema,
17-
);
18-
if (userstylesData.userstyles === undefined) {
11+
const userstylesData = await getUserstylesData().catch((err) => {
12+
console.error(err);
1913
Deno.exit(1);
20-
}
14+
});
2115

2216
// lowercase usernames of all the "current-maintainers" in the file
2317
const maintainers = [

scripts/utils.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import Ajv, { Schema } from "ajv";
22
import { parse } from "std/yaml/parse.ts";
3+
import { join } from "std/path/join.ts";
4+
import { SetRequired } from "type-fest/source/set-required.d.ts";
5+
6+
import { REPO_ROOT, userStylesSchema } from "@/deps.ts";
7+
import { UserstylesSchema } from "@/types/userstyles.d.ts";
38

49
/**
510
* @param content A string of YAML content
@@ -20,3 +25,23 @@ export const validateYaml = <T>(
2025
return resolve(data);
2126
});
2227
};
28+
29+
/**
30+
* Utility function that calls {@link validateYaml} on the userstyles.yml file.
31+
* Fails when data.userstyles is undefined.
32+
*/
33+
export const getUserstylesData = (): Promise<Userstyles> => {
34+
return new Promise((resolve, reject) => {
35+
validateYaml<UserstylesSchema>(
36+
Deno.readTextFileSync(join(REPO_ROOT, "scripts/userstyles.yml")),
37+
userStylesSchema,
38+
).then((data) => {
39+
if (data.userstyles === undefined || data.collaborators === undefined) {
40+
return reject("userstyles.yml is missing required fields");
41+
}
42+
return resolve(data as Userstyles);
43+
});
44+
});
45+
};
46+
47+
type Userstyles = SetRequired<UserstylesSchema, "userstyles" | "collaborators">;

styles/anilist/catppuccin.user.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* ==UserStyle==
2-
@name AniList Catppuccin
2+
@name AniList/AniChart Catppuccin
33
@namespace github.com/catppuccin/userstyles/styles/anilist
44
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/anilist
55
@version 2.1.1

styles/chess.com/catppuccin.user.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@name Chess.com Catppuccin
33
@namespace github.com/catppuccin/userstyles/styles/chess.com
44
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/chess.com
5-
@version 0.1.2
5+
@version 0.1.3
66
@updateURL https://github.com/catppuccin/userstyles/raw/main/styles/chess.com/catppuccin.user.css
77
@supportURL https://github.com/catppuccin/userstyles/issues?q=is%3Aopen+is%3Aissue+label%3Achess.com
88
@description Soothing pastel theme for Chess.com
@@ -62,8 +62,8 @@
6262
@crust: @catppuccin[@@lookup][@crust];
6363
@accent-color: @catppuccin[@@lookup][@@accent];
6464

65-
#piece(@name) {
66-
@url: url("https://media.githubusercontent.com/media/catppuccin/userstyles/main/styles/chess.com/assets/@{lookup}/@{name}.png");
65+
#piece(@piece) {
66+
@url: url("https://media.githubusercontent.com/media/catppuccin/userstyles/main/styles/chess.com/assets/@{lookup}/@{piece}.png");
6767
}
6868

6969
@bb: #piece("b/bb") [];

styles/github/catppuccin.user.css

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* ==UserStyle==
2-
@name Github Catppuccin
3-
@namespace github.com/catppuccin/userstyles/styles/github
4-
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/github
5-
@version 1.3.2
6-
@description Soothing pastel theme for GitHub
7-
@author Catppuccin
8-
@updateURL https://github.com/catppuccin/userstyles/raw/main/styles/github/catppuccin.user.css
9-
@supportURL https://github.com/catppuccin/userstyles/issues?q=is%3Aopen+is%3Aissue+label%3Agithub
10-
@license MIT
2+
@name GitHub Catppuccin
3+
@namespace github.com/catppuccin/userstyles/styles/github
4+
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/github
5+
@version 1.3.3
6+
@description Soothing pastel theme for GitHub
7+
@author Catppuccin
8+
@updateURL https://github.com/catppuccin/userstyles/raw/main/styles/github/catppuccin.user.css
9+
@supportURL https://github.com/catppuccin/userstyles/issues?q=is%3Aopen+is%3Aissue+label%3Agithub
10+
@license MIT
1111
1212
@preprocessor less
1313
@var select lightFlavor "Light Flavor" ["latte:Latte*", "frappe:Frappé", "macchiato:Macchiato", "mocha:Mocha"]
@@ -58,49 +58,49 @@
5858
z-index: 9999;
5959
}
6060

61-
#coloredButton(@name, @color, @flat) {
61+
#coloredButton(@item, @color, @flat) {
6262
& when (@flat) {
63-
--color-btn-@{name}-text: @color;
64-
--color-btn-@{name}-bg: @base;
65-
--color-btn-@{name}-icon: @color;
63+
--color-btn-@{item}-text: @color;
64+
--color-btn-@{item}-bg: @base;
65+
--color-btn-@{item}-icon: @color;
6666

67-
--color-btn-@{name}-hover-text: @base;
68-
--color-btn-@{name}-hover-bg: @color;
69-
--color-btn-@{name}-hover-border: @color;
67+
--color-btn-@{item}-hover-text: @base;
68+
--color-btn-@{item}-hover-bg: @color;
69+
--color-btn-@{item}-hover-border: @color;
7070

71-
--color-btn-@{name}-selected-text: @base;
72-
--color-btn-@{name}-selected-bg: @color;
73-
--color-btn-@{name}-selected-border: @color;
71+
--color-btn-@{item}-selected-text: @base;
72+
--color-btn-@{item}-selected-bg: @color;
73+
--color-btn-@{item}-selected-border: @color;
7474

75-
--color-btn-@{name}-disabled-text: fadeout(@color, 60%);
76-
--color-btn-@{name}-disabled-bg: @mantle;
75+
--color-btn-@{item}-disabled-text: fadeout(@color, 60%);
76+
--color-btn-@{item}-disabled-bg: @mantle;
7777
}
7878

7979
& when not (@flat) {
80-
--color-btn-@{name}-text: @base;
81-
--color-btn-@{name}-bg: @color;
82-
--color-btn-@{name}-icon: @base;
80+
--color-btn-@{item}-text: @base;
81+
--color-btn-@{item}-bg: @color;
82+
--color-btn-@{item}-icon: @base;
8383

84-
--color-btn-@{name}-hover-text: @base;
85-
--color-btn-@{name}-hover-bg: lighten(@color, 10%);
86-
--color-btn-@{name}-hover-border: lighten(@color, 10%);
84+
--color-btn-@{item}-hover-text: @base;
85+
--color-btn-@{item}-hover-bg: lighten(@color, 10%);
86+
--color-btn-@{item}-hover-border: lighten(@color, 10%);
8787

88-
--color-btn-@{name}-selected-text: @base;
89-
--color-btn-@{name}-selected-bg: lighten(@color, 10%);
90-
--color-btn-@{name}-selected-border: lighten(@color, 10%);
88+
--color-btn-@{item}-selected-text: @base;
89+
--color-btn-@{item}-selected-bg: lighten(@color, 10%);
90+
--color-btn-@{item}-selected-border: lighten(@color, 10%);
9191

92-
--color-btn-@{name}-disabled-text: @crust;
93-
--color-btn-@{name}-disabled-bg: fadeout(@color, 60%);
92+
--color-btn-@{item}-disabled-text: @crust;
93+
--color-btn-@{item}-disabled-bg: fadeout(@color, 60%);
9494
}
9595

96-
--color-btn-@{name}-hover-icon: @base;
96+
--color-btn-@{item}-hover-icon: @base;
9797

9898
/* set these to transparent for the looks */
99-
--color-btn-@{name}-border: transparent;
100-
--color-btn-@{name}-shadow: 0 0 transparent;
101-
--color-btn-@{name}-inset-shadow: 0 0 transparent;
102-
--color-btn-@{name}-selected-shadow: 0 0 transparent;
103-
--color-btn-@{name}-disabled-border: transparent;
99+
--color-btn-@{item}-border: transparent;
100+
--color-btn-@{item}-shadow: 0 0 transparent;
101+
--color-btn-@{item}-inset-shadow: 0 0 transparent;
102+
--color-btn-@{item}-selected-shadow: 0 0 transparent;
103+
--color-btn-@{item}-disabled-border: transparent;
104104
}
105105

106106
#catppuccin(@lookup, @accent) {

styles/hacker-news/catppuccin.user.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* ==UserStyle==
2-
@name HackerNews Catppuccin
2+
@name Hacker News Catppuccin
33
@namespace github.com/catppuccin/userstyles/styles/hacker-news
44
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/hacker-news
55
@version 0.1.1

styles/hoppscotch/catppuccin.user.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* ==UserStyle==
2-
@name Hoppscotch.io Catppuccin
2+
@name Hoppscotch Catppuccin
33
@namespace github.com/catppuccin/userstyles/styles/hoppscotch
44
@homepageURL https://github.com/catppuccin/userstyles/tree/main/styles/hoppscotch
55
@version 1.0.0

0 commit comments

Comments
 (0)