build: refactor & use handlebars for generate templating (#343)
This commit is contained in:
1 parent
b1f864c1c8
commit
f48eba6354
23 files changed
+681
-408
No files matched your search
+7
-3
@@ -1,11 +1,15 @@
|
||||
import schema from "./userstyles.schema.json" assert { type: "json" };
|
||||
import portsSchema from "catppuccin-repo/resources/ports.schema.json" assert {
|
||||
type: "json",
|
||||
};
|
||||
import userStylesSchema from "@/userstyles.schema.json" assert {
|
||||
type: "json",
|
||||
};
|
||||
|
||||
import { join } from "std/path/mod.ts";
|
||||
const ROOT = new URL(".", import.meta.url).pathname;
|
||||
/** absolute path to the repository */
|
||||
/**
|
||||
* absolute path to the repository
|
||||
*/
|
||||
export const REPO_ROOT = join(ROOT, "..");
|
||||
|
||||
export { portsSchema, schema };
|
||||
export { portsSchema, userStylesSchema };
|
||||
@@ -0,0 +1,76 @@
|
||||
import { join } from "std/path/mod.ts";
|
||||
|
||||
import { REPO_ROOT } from "@/deps.ts";
|
||||
import { updateFile } from "@/generate/utils.ts";
|
||||
import { UserStylesSchema } from "@/types/mod.d.ts";
|
||||
import { stringify } from "std/yaml/stringify.ts";
|
||||
import palette from "https://raw.githubusercontent.com/catppuccin/palette/v0.2.0/palette-porcelain.json" assert {
|
||||
type: "json",
|
||||
};
|
||||
|
||||
/**
|
||||
* Macchiato color definitions as hex values.
|
||||
*/
|
||||
const macchiatoHex = Object.entries(palette.macchiato)
|
||||
.reduce((acc, [k, v]) => {
|
||||
acc[k] = `#${v.hex}`;
|
||||
return acc;
|
||||
}, {} as Record<keyof typeof palette.macchiato, string>);
|
||||
|
||||
const toIssueLabel = (slug: string | number) => `lbl:${slug}`;
|
||||
|
||||
export const syncIssueLabels = async (
|
||||
userstyles: UserStylesSchema.Userstyles,
|
||||
) => {
|
||||
updateFile(
|
||||
join(REPO_ROOT, ".github/issue-labeler.yml"),
|
||||
stringify(
|
||||
Object.entries(userstyles)
|
||||
.reduce((acc, [key]) => {
|
||||
acc[key.toString()] = [`(${toIssueLabel(key)})`];
|
||||
return acc;
|
||||
}, {} as Record<string, string[]>),
|
||||
),
|
||||
);
|
||||
|
||||
const userstyleIssueContent = Deno.readTextFileSync(join(
|
||||
REPO_ROOT,
|
||||
"scripts/generate/templates/userstyle-issue.yml",
|
||||
));
|
||||
Deno.writeTextFileSync(
|
||||
join(REPO_ROOT, ".github/ISSUE_TEMPLATE/userstyle.yml"),
|
||||
userstyleIssueContent.replace(
|
||||
`"$LABELS"`,
|
||||
`${
|
||||
Object.entries(userstyles)
|
||||
.map(([key]) => `"${toIssueLabel(key)}"`)
|
||||
.join(", ")
|
||||
}`,
|
||||
),
|
||||
);
|
||||
|
||||
// .github/pr-labeler.yml
|
||||
updateFile(
|
||||
join(REPO_ROOT, ".github/pr-labeler.yml"),
|
||||
stringify(
|
||||
Object.entries(userstyles)
|
||||
.reduce((acc, [key]) => {
|
||||
acc[`${key}`] = `styles/${key}/**/*`;
|
||||
return acc;
|
||||
}, {} as Record<string, string>),
|
||||
),
|
||||
);
|
||||
|
||||
// .github/labels.yml
|
||||
const syncLabelsContent = Object.entries(userstyles)
|
||||
.map(([slug, style]) => {
|
||||
return {
|
||||
name: slug,
|
||||
description: [style.name].flat().join(", "),
|
||||
color: style.color ? macchiatoHex[style.color] : macchiatoHex.blue,
|
||||
};
|
||||
});
|
||||
const syncLabels = join(REPO_ROOT, ".github/labels.yml");
|
||||
// deno-lint-ignore no-explicit-any
|
||||
await updateFile(syncLabels, stringify(syncLabelsContent as any));
|
||||
};
|
||||
+54
-275
@@ -1,287 +1,66 @@
|
||||
#!/usr/bin/env -S deno run --allow-env --allow-read --allow-write --allow-net
|
||||
#!/usr/bin/env -S deno run -A
|
||||
import { join } from "std/path/mod.ts";
|
||||
|
||||
import * as path from "std/path/mod.ts";
|
||||
import { parse as parseYaml } from "std/yaml/mod.ts";
|
||||
import Ajv from "ajv";
|
||||
import { portsSchema, REPO_ROOT, userStylesSchema } from "@/deps.ts";
|
||||
import type { PortsSchema, UserStylesSchema } from "@/types/mod.d.ts";
|
||||
|
||||
import { portsSchema, REPO_ROOT, schema } from "@/deps.ts";
|
||||
|
||||
import {
|
||||
ApplicationLink,
|
||||
CurrentMaintainers,
|
||||
FAQ,
|
||||
Name,
|
||||
PastMaintainers,
|
||||
PortCategories,
|
||||
Usage,
|
||||
Userstyle,
|
||||
Userstyles,
|
||||
} from "@/types.d.ts";
|
||||
|
||||
const ROOT = new URL(".", import.meta.url).pathname;
|
||||
const ISSUE_PREFIX = "lbl:";
|
||||
|
||||
type Metadata = {
|
||||
userstyles: Userstyles;
|
||||
};
|
||||
|
||||
type PortMetadata = {
|
||||
categories: PortCategories;
|
||||
};
|
||||
|
||||
type CollaboratorsData = {
|
||||
collaborators: CurrentMaintainers | PastMaintainers | undefined;
|
||||
heading: string;
|
||||
};
|
||||
|
||||
export type MappedPort = Userstyle & { path: string };
|
||||
|
||||
const ajv = new (Ajv as unknown as (typeof Ajv)["default"])();
|
||||
const validate = ajv.compile<Metadata>(schema);
|
||||
const validatePorts = ajv.compile<PortMetadata>(portsSchema);
|
||||
import { syncIssueLabels } from "@/generate/labels.ts";
|
||||
import { generateMainReadme } from "@/generate/readme-repo.ts";
|
||||
import { generateStyleReadmes } from "@/generate/readme-styles.ts";
|
||||
import { updateFile } from "@/generate/utils.ts";
|
||||
import { validateYaml } from "@/utils.ts";
|
||||
|
||||
const userstylesYaml = Deno.readTextFileSync(
|
||||
path.join(REPO_ROOT, "scripts/userstyles.yml"),
|
||||
join(REPO_ROOT, "scripts/userstyles.yml"),
|
||||
);
|
||||
const userstylesData = parseYaml(userstylesYaml);
|
||||
if (!validate(userstylesData)) {
|
||||
console.log(validate.errors);
|
||||
Deno.exit(1);
|
||||
}
|
||||
|
||||
const portsYaml = await fetch(
|
||||
"https://raw.githubusercontent.com/catppuccin/catppuccin/main/resources/ports.yml",
|
||||
);
|
||||
const portsData = parseYaml(await portsYaml.text());
|
||||
if (!validatePorts(portsData)) {
|
||||
console.log(validate.errors);
|
||||
).then((res) => res.text());
|
||||
|
||||
const [portsData, userstylesData] = await Promise.all([
|
||||
await validateYaml<PortsSchema.PortsSchema>(
|
||||
portsYaml,
|
||||
portsSchema,
|
||||
),
|
||||
await validateYaml<UserStylesSchema.UserstylesSchema>(
|
||||
userstylesYaml,
|
||||
userStylesSchema,
|
||||
),
|
||||
]);
|
||||
|
||||
if (!userstylesData.userstyles) {
|
||||
console.error("No userstyles found");
|
||||
Deno.exit(1);
|
||||
}
|
||||
|
||||
const categorized = Object.entries(userstylesData.userstyles).reduce(
|
||||
(acc, [slug, { category, ...port }]) => {
|
||||
acc[category] ??= [];
|
||||
acc[category].push({ path: `styles/${slug}`, category, ...port });
|
||||
acc[category].sort((a, b) => {
|
||||
const aName = typeof a.name === "string" ? a.name : a.name.join(", ");
|
||||
const bName = typeof b.name === "string" ? b.name : b.name.join(", ");
|
||||
return aName.localeCompare(bName);
|
||||
});
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, MappedPort[]>,
|
||||
);
|
||||
/**
|
||||
* Generate the main README.md, listing all ports as a table of contents
|
||||
*/
|
||||
await generateMainReadme(userstylesData.userstyles, portsData);
|
||||
/**
|
||||
* Generate README.md files for each style
|
||||
*/
|
||||
generateStyleReadmes(userstylesData.userstyles);
|
||||
/**
|
||||
* Keep
|
||||
* - `.github/issue-labeler.yml`
|
||||
* - `.github/labels.yml`
|
||||
* - `.github/pr-labeler.yml`
|
||||
* in sync with the userstyle metadata.
|
||||
*/
|
||||
await syncIssueLabels(userstylesData.userstyles);
|
||||
|
||||
const portListData = portsData.categories
|
||||
.filter((category) => categorized[category.key] !== undefined)
|
||||
.map((category) => {
|
||||
return {
|
||||
meta: category,
|
||||
ports: categorized[category.key],
|
||||
};
|
||||
});
|
||||
|
||||
const portContent = portListData
|
||||
.map(
|
||||
(data) =>
|
||||
`<details open>
|
||||
<summary>${data.meta.emoji} ${data.meta.name}</summary>
|
||||
|
||||
${
|
||||
data.ports
|
||||
.map((port) => {
|
||||
const name = Array.isArray(port.name)
|
||||
? port.name.join(", ")
|
||||
: port.name;
|
||||
return `- [${name}](${port.path})`;
|
||||
})
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
</details>`,
|
||||
)
|
||||
.join("\n");
|
||||
|
||||
const updateReadme = ({
|
||||
readme,
|
||||
section,
|
||||
newContent,
|
||||
}: {
|
||||
readme: string;
|
||||
section: string;
|
||||
newContent: string;
|
||||
}): string => {
|
||||
const preamble =
|
||||
"<!-- the following section is auto-generated, do not edit -->";
|
||||
const startMarker = `<!-- AUTOGEN:${section.toUpperCase()} START -->`;
|
||||
const endMarker = `<!-- AUTOGEN:${section.toUpperCase()} END -->`;
|
||||
const wrapped = `${startMarker}\n${preamble}\n${newContent}\n${endMarker}`;
|
||||
|
||||
if (
|
||||
!(readmeContent.includes(startMarker) && readmeContent.includes(endMarker))
|
||||
) {
|
||||
throw new Error("Markers not found in README.md");
|
||||
}
|
||||
|
||||
const pre = readme.split(startMarker)[0];
|
||||
const end = readme.split(endMarker)[1];
|
||||
return pre + wrapped + end;
|
||||
};
|
||||
|
||||
const updateFile = (filePath: string, fileContent: string, comment = true) => {
|
||||
const preamble = comment
|
||||
? "# THIS FILE IS AUTOGENERATED. DO NOT EDIT IT BY HAND.\n"
|
||||
: "";
|
||||
Deno.writeTextFileSync(filePath, preamble + fileContent);
|
||||
};
|
||||
|
||||
const readmePath = path.join(REPO_ROOT, "README.md");
|
||||
let readmeContent = Deno.readTextFileSync(readmePath);
|
||||
try {
|
||||
readmeContent = updateReadme({
|
||||
readme: readmeContent,
|
||||
section: "userstyles",
|
||||
newContent: portContent,
|
||||
});
|
||||
updateFile(readmePath, readmeContent, false);
|
||||
} catch (e) {
|
||||
console.log("Failed to update the README:", e);
|
||||
}
|
||||
|
||||
const pullRequestLabelerPath = path.join(REPO_ROOT, ".github/pr-labeler.yml");
|
||||
const pullRequestLabelerContent = Object.entries(userstylesData.userstyles)
|
||||
.map(([key]) => `${key}: styles/${key}/**/*`)
|
||||
.join("\n");
|
||||
updateFile(pullRequestLabelerPath, pullRequestLabelerContent);
|
||||
|
||||
const syncLabels = path.join(REPO_ROOT, ".github/labels.yml");
|
||||
const syncLabelsContent = Object.entries(userstylesData.userstyles)
|
||||
.map(
|
||||
([key, style]) =>
|
||||
`- name: ${key}
|
||||
description: ${style.name}
|
||||
color: "#8aadf4"`,
|
||||
)
|
||||
.join("\n");
|
||||
updateFile(syncLabels, syncLabelsContent);
|
||||
|
||||
const issuesLabelerPath = path.join(REPO_ROOT, ".github/issue-labeler.yml");
|
||||
const issuesLabelerContent = Object.entries(userstylesData.userstyles)
|
||||
.map(([key]) => `${key}: ['(${ISSUE_PREFIX + key})']`)
|
||||
.join("\n");
|
||||
updateFile(issuesLabelerPath, issuesLabelerContent);
|
||||
|
||||
const ownersPath = path.join(REPO_ROOT, ".github/CODEOWNERS");
|
||||
const ownersContent = Object.entries(userstylesData.userstyles)
|
||||
.map(([key, style]) => {
|
||||
const currentMaintainers = style.readme["current-maintainers"]
|
||||
.map((maintainer) => `@${maintainer.url.split("/").pop()}`)
|
||||
.join(" ");
|
||||
return `/styles/${key} ${currentMaintainers}`;
|
||||
})
|
||||
.join("\n");
|
||||
updateFile(ownersPath, ownersContent);
|
||||
|
||||
const userstyleIssuePath = path.join(ROOT, "templates/userstyle-issue.yml");
|
||||
const userstyleIssueContent = Deno.readTextFileSync(userstyleIssuePath);
|
||||
const replacedUserstyleIssueContent = userstyleIssueContent.replace(
|
||||
"$PORTS",
|
||||
`${
|
||||
Object.entries(userstylesData.userstyles)
|
||||
.map(([key]) => `'${ISSUE_PREFIX + key}'`)
|
||||
.join(", ")
|
||||
}`,
|
||||
);
|
||||
Deno.writeTextFileSync(
|
||||
path.join(REPO_ROOT, ".github/ISSUE_TEMPLATE/userstyle.yml"),
|
||||
replacedUserstyleIssueContent,
|
||||
);
|
||||
|
||||
const heading = (name: Name, link: ApplicationLink) => {
|
||||
const nameArray = Array.isArray(name) ? name : [name];
|
||||
const linkArray = Array.isArray(link) ? link : [link];
|
||||
|
||||
if (nameArray.length !== linkArray.length) {
|
||||
throw new Error(
|
||||
'The "name" and "app-link" arrays must have the same length',
|
||||
);
|
||||
}
|
||||
|
||||
return `Catppuccin for ${
|
||||
nameArray
|
||||
.map((name, index) => `<a href="${linkArray[index]}">${name}</a>`)
|
||||
.join(", ")
|
||||
}`;
|
||||
};
|
||||
|
||||
const usageContent = (usage?: Usage) => {
|
||||
return !usage ? "" : `## Usage \n${usage}`;
|
||||
};
|
||||
|
||||
const faqContent = (faq?: FAQ) => {
|
||||
if (!faq) {
|
||||
return "";
|
||||
}
|
||||
return `## 🙋 FAQ
|
||||
${
|
||||
faq
|
||||
.map(({ question, answer }) => `- Q: ${question} \n\tA: ${answer}`)
|
||||
.join("\n")
|
||||
}`;
|
||||
};
|
||||
|
||||
const collaboratorsContent = (allCollaborators: CollaboratorsData[]) => {
|
||||
return allCollaborators
|
||||
.filter(({ collaborators }) => collaborators !== undefined)
|
||||
.map(({ collaborators, heading }) => {
|
||||
const collaboratorBody = collaborators
|
||||
?.map(({ name, url }) => `- [${name ?? url.split("/").pop()}](${url})`)
|
||||
.join("\n");
|
||||
return `${heading}\n${collaboratorBody}`;
|
||||
/**
|
||||
* Keep `.github/CODEOWNERS` in sync with the userstyle metadata.
|
||||
*/
|
||||
await updateFile(
|
||||
join(REPO_ROOT, ".github/CODEOWNERS"),
|
||||
Object.entries(userstylesData.userstyles)
|
||||
.map(([slug, { readme }]) => {
|
||||
const currentMaintainers = readme["current-maintainers"]
|
||||
.map((maintainer) => `@${maintainer.url.split("/").pop()}`)
|
||||
.join(" ");
|
||||
return `/styles/${slug} ${currentMaintainers}`;
|
||||
})
|
||||
.join("\n\n");
|
||||
};
|
||||
|
||||
const updateStylesReadmeContent = (
|
||||
readme: string,
|
||||
key: string,
|
||||
userstyle: Userstyle,
|
||||
) => {
|
||||
return readme
|
||||
.replace("$TITLE", heading(userstyle.name, userstyle.readme["app-link"]))
|
||||
.replaceAll("$LOWERCASE-PORT", key)
|
||||
.replace("$USAGE", usageContent(userstyle.readme.usage))
|
||||
.replace("$FAQ", faqContent(userstyle.readme.faq))
|
||||
.replace(
|
||||
"$COLLABORATORS",
|
||||
collaboratorsContent([
|
||||
{
|
||||
collaborators: userstyle.readme["current-maintainers"],
|
||||
heading: "## 💝 Current Maintainer(s)",
|
||||
},
|
||||
{
|
||||
collaborators: userstyle.readme["past-maintainers"],
|
||||
heading: "## 💖 Past Maintainer(s)",
|
||||
},
|
||||
]),
|
||||
);
|
||||
};
|
||||
|
||||
const stylesReadmePath = path.join(ROOT, "templates/userstyle.md");
|
||||
const stylesReadmeContent = Deno.readTextFileSync(stylesReadmePath);
|
||||
for (const [key, userstyle] of Object.entries(userstylesData.userstyles)) {
|
||||
try {
|
||||
console.log(`Generating README for ${key}`);
|
||||
readmeContent = updateStylesReadmeContent(
|
||||
stylesReadmeContent,
|
||||
key,
|
||||
userstyle,
|
||||
);
|
||||
Deno.writeTextFileSync(
|
||||
path.join(REPO_ROOT, "styles", key, "README.md"),
|
||||
readmeContent,
|
||||
);
|
||||
} catch (e) {
|
||||
console.log(`Failed to update ${userstyle} README:`, e);
|
||||
}
|
||||
}
|
||||
.join("\n"),
|
||||
);
|
||||
@@ -0,0 +1,74 @@
|
||||
import { join } from "std/path/mod.ts";
|
||||
import Handlebars from "handlebars";
|
||||
|
||||
import { REPO_ROOT } from "@/deps.ts";
|
||||
import { PortsSchema, UserStylesSchema } from "@/types/mod.d.ts";
|
||||
import { updateFile, updateReadme } from "@/generate/utils.ts";
|
||||
|
||||
type MappedPorts = {
|
||||
[k: string]: (
|
||||
UserStylesSchema.Userstyle & { path: string }
|
||||
)[];
|
||||
};
|
||||
|
||||
export const generateMainReadme = async (
|
||||
userstyles: UserStylesSchema.Userstyles,
|
||||
portsData: PortsSchema.PortsSchema,
|
||||
) => {
|
||||
if (!portsData.categories) throw ("Ports data is missing categories");
|
||||
|
||||
const categorized = Object.entries(userstyles)
|
||||
.reduce((acc, [slug, { category, ...port }]) => {
|
||||
// initialize category array if it doesn't exist
|
||||
acc[category] ??= [];
|
||||
|
||||
acc[category].push({ path: `styles/${slug}`, category, ...port });
|
||||
|
||||
// Sort by name, first array entry if necessary
|
||||
acc[category].sort((a, b) =>
|
||||
[a.name].flat()[0].localeCompare([b.name].flat()[0])
|
||||
);
|
||||
return acc;
|
||||
}, {} as MappedPorts);
|
||||
|
||||
const portListData = portsData.categories
|
||||
.filter((category) => categorized[category.key] !== undefined)
|
||||
.map((category) => {
|
||||
return { meta: category, ports: categorized[category.key] };
|
||||
});
|
||||
|
||||
const portContent = Handlebars.compile(`{{#each category}}
|
||||
<details open>
|
||||
<summary>{{emoji}} {{name}}</summary>
|
||||
|
||||
{{#each ports}}
|
||||
- [{{#each name}}{{ this }}{{#unless @last}}, {{/unless}}{{/each}}]({{ path }})
|
||||
{{/each}}
|
||||
|
||||
</details>
|
||||
{{/each}}`)({
|
||||
category: portListData.map(({ meta, ports }) => {
|
||||
return {
|
||||
emoji: meta.emoji,
|
||||
name: meta.name,
|
||||
ports: ports.map(({ name, path }) => {
|
||||
return {
|
||||
name: [name].flat(),
|
||||
path,
|
||||
};
|
||||
}),
|
||||
};
|
||||
}),
|
||||
});
|
||||
|
||||
const readmePath = join(REPO_ROOT, "README.md");
|
||||
await updateFile(
|
||||
readmePath,
|
||||
updateReadme({
|
||||
readme: Deno.readTextFileSync(readmePath),
|
||||
section: "userstyles",
|
||||
newContent: portContent,
|
||||
}),
|
||||
false,
|
||||
).catch((e) => console.error(e));
|
||||
};
|
||||
@@ -0,0 +1,63 @@
|
||||
import { UserStylesSchema } from "@/types/mod.d.ts";
|
||||
import { join } from "std/path/mod.ts";
|
||||
import { REPO_ROOT } from "@/deps.ts";
|
||||
import Handlebars from "handlebars";
|
||||
|
||||
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] };
|
||||
});
|
||||
};
|
||||
|
||||
const 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 const generateStyleReadmes = (
|
||||
userstyles: UserStylesSchema.Userstyles,
|
||||
) => {
|
||||
const stylesReadmePath = join(
|
||||
REPO_ROOT,
|
||||
"scripts/generate/templates/userstyle.md",
|
||||
);
|
||||
const stylesReadmeContent = Deno.readTextFileSync(stylesReadmePath);
|
||||
|
||||
Object.entries(userstyles).map(([slug, { name, readme }]) => {
|
||||
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(readme["current-maintainers"]),
|
||||
pastMaintainers: extractName(readme["past-maintainers"]),
|
||||
},
|
||||
});
|
||||
Deno.writeTextFile(
|
||||
join(REPO_ROOT, "styles", slug.toString(), "README.md"),
|
||||
readmeContent,
|
||||
).catch((e) => console.error(e));
|
||||
});
|
||||
};
|
||||
@@ -14,7 +14,7 @@ body:
|
||||
label: What userstyles are you seeing the problem on?
|
||||
description: "Don't worry about the `lbl:` prefix, it allows issues to be automatically labeled!"
|
||||
multiple: true
|
||||
options: [$PORTS]
|
||||
options: ["$LABELS"]
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
@@ -38,4 +38,5 @@ body:
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Any additional comments?
|
||||
description: Add any information that hasn't been covered in the previous sections!
|
||||
description: Add any information that hasn't been covered in the previous sections!
|
||||
# yaml-language-server: $schema=https://json.schemastore.org/github-issue-forms.json
|
||||
@@ -4,13 +4,13 @@
|
||||
<h3 align="center">
|
||||
<img src="https://raw.githubusercontent.com/catppuccin/catppuccin/main/assets/logos/exports/1544x1544_circle.png" width="100" alt="Logo"/><br/>
|
||||
<img src="https://raw.githubusercontent.com/catppuccin/catppuccin/main/assets/misc/transparent.png" height="30" width="0px"/>
|
||||
$TITLE
|
||||
Catppuccin for {{#each heading}}<a href="{{ this.url }}">{{ this.title }}</a>{{#unless @last}}, {{/unless}}{{/each}}
|
||||
<img src="https://raw.githubusercontent.com/catppuccin/catppuccin/main/assets/misc/transparent.png" height="30" width="0px"/>
|
||||
</h3>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/catppuccin/userstyles/issues?q=is%3Aissue+is%3Aopen+label%3A$LOWERCASE-PORT"><img src="https://img.shields.io/github/issues/catppuccin/userstyles/$LOWERCASE-PORT?colorA=363a4f&colorB=f5a97f&style=for-the-badge"></a>
|
||||
<a href="https://raw.githubusercontent.com/catppuccin/userstyles/main/styles/$LOWERCASE-PORT/catppuccin.user.css"><img src="https://img.shields.io/badge/stylus-install-cba6f7?colorA=363a4f&style=for-the-badge"></a>
|
||||
<a href="https://github.com/catppuccin/userstyles/issues?q=is%3Aissue+is%3Aopen+label%3A{{ slug }}"><img src="https://img.shields.io/github/issues/catppuccin/userstyles/{{ slug }}?colorA=363a4f&colorB=f5a97f&style=for-the-badge"></a>
|
||||
<a href="https://raw.githubusercontent.com/catppuccin/userstyles/main/styles/{{ slug }}/catppuccin.user.css"><img src="https://img.shields.io/badge/stylus-install-cba6f7?colorA=363a4f&style=for-the-badge"></a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
@@ -36,11 +36,30 @@
|
||||
<img src="assets/mocha.webp"/>
|
||||
</details>
|
||||
|
||||
$USAGE
|
||||
{{#if usage}}
|
||||
## Usage
|
||||
{{{ usage }}}
|
||||
{{/if}}
|
||||
|
||||
$FAQ
|
||||
{{#if faq}}
|
||||
## 🙋 FAQ
|
||||
{{#each faq}}
|
||||
- Q: {{{ question }}}\
|
||||
A: {{{ answer }}}
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
|
||||
$COLLABORATORS
|
||||
## 💝 Current Maintainer(s)
|
||||
{{#each collaborators.currentMaintainers}}
|
||||
- [{{name}}]({{url}})
|
||||
{{/each}}
|
||||
|
||||
{{#if collaborators.pastMaintainers}}
|
||||
## 💝 Past Maintainer(s)
|
||||
{{#each collaborators.pastMaintainers}}
|
||||
- [{{name}}]({{url}})
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
export const updateFile = (
|
||||
filePath: string,
|
||||
fileContent: string,
|
||||
comment = true,
|
||||
) => {
|
||||
const preamble = comment
|
||||
? "# THIS FILE IS AUTOGENERATED. DO NOT EDIT IT BY HAND.\n"
|
||||
: "";
|
||||
return Deno.writeTextFile(filePath, preamble + fileContent);
|
||||
};
|
||||
|
||||
export const updateReadme = ({
|
||||
readme,
|
||||
section,
|
||||
newContent,
|
||||
}: {
|
||||
readme: string;
|
||||
section: string;
|
||||
newContent: string;
|
||||
}): string => {
|
||||
const preamble =
|
||||
"<!-- the following section is auto-generated, do not edit -->";
|
||||
const startMarker = `<!-- AUTOGEN:${section.toUpperCase()} START -->`;
|
||||
const endMarker = `<!-- AUTOGEN:${section.toUpperCase()} END -->`;
|
||||
const wrapped = `${startMarker}\n${preamble}\n${newContent}\n${endMarker}`;
|
||||
|
||||
if (
|
||||
!(readme.includes(startMarker) && readme.includes(endMarker))
|
||||
) {
|
||||
throw new Error("Markers not found in README.md");
|
||||
}
|
||||
|
||||
const pre = readme.split(startMarker)[0];
|
||||
const end = readme.split(endMarker)[1];
|
||||
return pre + wrapped + end;
|
||||
};
|
||||
@@ -1,10 +1,10 @@
|
||||
import { exists } from "std/fs/mod.ts";
|
||||
import { exists } from "std/fs/exists.ts";
|
||||
import { join, relative } from "std/path/mod.ts";
|
||||
import core from "@actions/core";
|
||||
|
||||
import { REPO_ROOT } from "@/deps.ts";
|
||||
import { log } from "./logger.ts";
|
||||
import chalk from "chalk";
|
||||
import * as color from "std/fmt/colors.ts";
|
||||
|
||||
const requiredFiles = [
|
||||
"catppuccin.user.css",
|
||||
@@ -39,7 +39,7 @@ export const checkForMissingFiles = async () => {
|
||||
.write();
|
||||
} else {
|
||||
missingFiles.map((f) => {
|
||||
log(chalk.red(`Missing file:`) + ` ${f}`, { file: f }, "error");
|
||||
log(color.red(`Missing file:`) + ` ${f}`, { file: f }, "error");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { sprintf } from "std/fmt/printf.ts";
|
||||
import chalk from "chalk";
|
||||
import * as color from "std/fmt/colors.ts";
|
||||
import core from "@actions/core";
|
||||
|
||||
export type LoggerProps = core.AnnotationProperties & { content?: string };
|
||||
@@ -15,7 +15,7 @@ const pretty_print = (
|
||||
const lines = (props.content ?? "").split("\n");
|
||||
|
||||
const error = [
|
||||
chalk[severity === "error" ? "red" : "yellow"](severity),
|
||||
color[severity === "error" ? "red" : "yellow"](severity),
|
||||
message,
|
||||
].join(" ");
|
||||
|
||||
@@ -24,7 +24,7 @@ const pretty_print = (
|
||||
const endCol = (props.endColumn ?? Infinity) - 1;
|
||||
|
||||
if (i >= startCol && i <= endCol) {
|
||||
return chalk[severity === "error" ? "red" : "yellow"](char);
|
||||
return color[severity === "error" ? "red" : "yellow"](char);
|
||||
} else {
|
||||
return char;
|
||||
}
|
||||
@@ -33,7 +33,7 @@ const pretty_print = (
|
||||
const pad = startLine.toString().length;
|
||||
console.log(
|
||||
[
|
||||
chalk.underline(
|
||||
color.underline(
|
||||
sprintf(
|
||||
"%s%s%d%s%d",
|
||||
file,
|
||||
@@ -46,15 +46,15 @@ const pretty_print = (
|
||||
sprintf(
|
||||
"%*s│ %s",
|
||||
pad,
|
||||
chalk.dim(startLine - 1),
|
||||
chalk.dim(lines[startLine - 2]),
|
||||
color.dim(String(startLine - 1)),
|
||||
color.dim(lines[startLine - 2]),
|
||||
),
|
||||
sprintf("%*s│ %s", pad, chalk.bold(startLine), line),
|
||||
sprintf("%*s│ %s", pad, color.bold(String(startLine)), line),
|
||||
sprintf(
|
||||
"%*s│ %s",
|
||||
pad,
|
||||
chalk.dim(startLine + 1),
|
||||
chalk.dim(lines[startLine]),
|
||||
color.dim(String(startLine + 1)),
|
||||
color.dim(lines[startLine]),
|
||||
),
|
||||
sprintf("%*s╰─► %s", pad, "", error),
|
||||
undefined,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env -S deno run -A
|
||||
|
||||
import { walk } from "std/fs/mod.ts";
|
||||
import { walk } from "std/fs/walk.ts";
|
||||
import { parse as parseFlags } from "std/flags/mod.ts";
|
||||
import { basename, dirname, join, relative } from "std/path/mod.ts";
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import chalk from "chalk";
|
||||
// @deno-types="../usercss-meta.d.ts";
|
||||
// @deno-types="@/types/usercss-meta.d.ts";
|
||||
import usercssMeta from "usercss-meta";
|
||||
import { log } from "./logger.ts";
|
||||
import * as color from "std/fmt/colors.ts";
|
||||
import { sprintf } from "std/fmt/printf.ts";
|
||||
import type { WalkEntry } from "std/fs/mod.ts";
|
||||
import type { WalkEntry } from "std/fs/walk.ts";
|
||||
import { relative } from "std/path/mod.ts";
|
||||
import { REPO_ROOT } from "@/deps.ts";
|
||||
|
||||
@@ -39,9 +39,9 @@ export const verifyMetadata = (
|
||||
|
||||
const message = sprintf(
|
||||
"Metadata %s should be %s but is %s",
|
||||
chalk.bold(k),
|
||||
chalk.green(v),
|
||||
chalk.red(defacto),
|
||||
color.bold(k),
|
||||
color.green(v),
|
||||
color.red(String(defacto)),
|
||||
);
|
||||
|
||||
log(message, {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { deepMerge } from "std/collections/mod.ts";
|
||||
import { deepMerge } from "std/collections/deep_merge.ts";
|
||||
|
||||
import chalk from "chalk";
|
||||
import * as color from "std/fmt/colors.ts";
|
||||
import stylelint from "npm:stylelint";
|
||||
import stylelintConfigStandard from "npm:stylelint-config-standard";
|
||||
import stylelintConfigRecommended from "npm:stylelint-config-recommended";
|
||||
@@ -184,7 +184,7 @@ export const lint = (entry: WalkEntry, content: string, fix: boolean) => {
|
||||
// some cleanup for fancier logging, dims the rule name
|
||||
const message = warning.text?.replace(
|
||||
new RegExp(`\\(?${warning.rule}\\)?`),
|
||||
chalk.dim(`(${warning.rule})`),
|
||||
color.dim(`(${warning.rule})`),
|
||||
) ?? "unspecified stylelint error";
|
||||
|
||||
log(message, {
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
#!/usr/bin/env -S deno run --allow-read --allow-net --allow-env
|
||||
#!/usr/bin/env -S deno run -A
|
||||
|
||||
import * as assert from "std/assert/mod.ts";
|
||||
import * as path from "std/path/mod.ts";
|
||||
import { parse as parseYaml } from "std/yaml/mod.ts";
|
||||
import Ajv from "ajv";
|
||||
import { Octokit } from "@octokit/rest";
|
||||
|
||||
import { REPO_ROOT, schema } from "@/deps.ts";
|
||||
import { Userstyle, UserstylesSchema } from "@/types.d.ts";
|
||||
import { REPO_ROOT, userStylesSchema } from "@/deps.ts";
|
||||
import type { UserStylesSchema } from "../types/mod.d.ts";
|
||||
import { validateYaml } from "@/utils.ts";
|
||||
import { UserstylesSchema } from "@/types/userstyles.d.ts";
|
||||
|
||||
const octokit = new Octokit({ auth: Deno.env.get("GITHUB_TOKEN") });
|
||||
const team = { org: "catppuccin", team_slug: "userstyles-maintainers" };
|
||||
|
||||
const ajv = new Ajv.default();
|
||||
const validate = ajv.compile<UserstylesSchema>(schema);
|
||||
|
||||
const userstylesYaml = Deno.readTextFileSync(
|
||||
path.join(REPO_ROOT, "scripts/userstyles.yml"),
|
||||
const userstylesData = await validateYaml<UserstylesSchema>(
|
||||
Deno.readTextFileSync(path.join(REPO_ROOT, "scripts/userstyles.yml")),
|
||||
userStylesSchema,
|
||||
);
|
||||
const userstylesData = parseYaml(userstylesYaml);
|
||||
if (!validate(userstylesData)) {
|
||||
console.error(validate.errors);
|
||||
Deno.exit(1);
|
||||
}
|
||||
if (userstylesData.userstyles === undefined) {
|
||||
Deno.exit(1);
|
||||
}
|
||||
@@ -30,7 +23,9 @@ if (userstylesData.userstyles === undefined) {
|
||||
// lowercase usernames of all the "current-maintainers" in the file
|
||||
const maintainers = [
|
||||
...new Set(
|
||||
Object.values(userstylesData.userstyles).flatMap((style: Userstyle) =>
|
||||
Object.values(userstylesData.userstyles).flatMap((
|
||||
style: UserStylesSchema.Userstyle,
|
||||
) =>
|
||||
style.readme["current-maintainers"].map((m) => {
|
||||
const username = m.url.split("github.com/")?.pop();
|
||||
// check that they follow github.com/username pattern
|
||||
|
||||
Vendored
-2
@@ -1,2 +0,0 @@
|
||||
export * from "./types/userstyles.d.ts";
|
||||
export type { Categories as PortCategories } from "catppuccin-repo/resources/generate/types.d.ts";
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
export * as UserStylesSchema from "./userstyles.d.ts";
|
||||
export * as PortsSchema from "catppuccin-repo/resources/generate/types.d.ts";
|
||||
|
||||
import { Entries } from "https://esm.sh/[email protected]";
|
||||
declare global {
|
||||
interface ObjectConstructor {
|
||||
entries<T extends object>(o: T): Entries<T>;
|
||||
}
|
||||
}
|
||||
File renamed without changes.
Vendored
+5
-10
@@ -1,9 +1,4 @@
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* This file was automatically generated by json-schema-to-typescript.
|
||||
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
||||
* and run json-schema-to-typescript to regenerate this file.
|
||||
*/
|
||||
// deno-fmt-ignore-file
|
||||
|
||||
/**
|
||||
* The name of the userstyle(s).
|
||||
@@ -74,7 +69,7 @@ export type FAQ = [
|
||||
question: Question;
|
||||
answer: Answer;
|
||||
[k: string]: unknown;
|
||||
}[],
|
||||
}[]
|
||||
];
|
||||
/**
|
||||
* A question that a user may have about the userstyle.
|
||||
@@ -99,7 +94,7 @@ export type CurrentMaintainers = [
|
||||
name?: DisplayName;
|
||||
url: GitHubProfile;
|
||||
[k: string]: unknown;
|
||||
}[],
|
||||
}[]
|
||||
];
|
||||
/**
|
||||
* The display name of the collaborator to show in the userstyle README.
|
||||
@@ -124,7 +119,7 @@ export type PastMaintainers = [
|
||||
name?: DisplayName;
|
||||
url: GitHubProfile;
|
||||
[k: string]: unknown;
|
||||
}[],
|
||||
}[]
|
||||
];
|
||||
/**
|
||||
* Represents all maintainers and contributors to all userstyles.
|
||||
@@ -141,7 +136,7 @@ export type AllCollaborators = [
|
||||
name?: DisplayName;
|
||||
url: GitHubProfile;
|
||||
[k: string]: unknown;
|
||||
}[],
|
||||
}[]
|
||||
];
|
||||
|
||||
export interface UserstylesSchema {
|
||||
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env -S deno run -A
|
||||
// deno-lint-ignore-file no-explicit-any
|
||||
import { join } from "std/path/mod.ts";
|
||||
import { compile, Options } from "npm:json-schema-to-typescript";
|
||||
import { REPO_ROOT, userStylesSchema } from "@/deps.ts";
|
||||
|
||||
const options = {
|
||||
bannerComment: "// deno-fmt-ignore-file",
|
||||
} satisfies Partial<Options>;
|
||||
|
||||
const TYPES_ROOT = join(REPO_ROOT, "scripts/types");
|
||||
|
||||
compile(userStylesSchema as any, "UserstylesSchema", options)
|
||||
.then((ts) =>
|
||||
Deno.writeTextFileSync(join(TYPES_ROOT, "userstyles.d.ts"), ts)
|
||||
);
|
||||
@@ -0,0 +1,22 @@
|
||||
import Ajv, { Schema } from "ajv";
|
||||
import { parse } from "std/yaml/parse.ts";
|
||||
|
||||
/**
|
||||
* @param content A string of YAML content
|
||||
* @param schema A JSON schema
|
||||
* @returns A promise that resolves to the parsed YAML content, verified against the schema. Rejects if the content is invalid.
|
||||
*/
|
||||
export const validateYaml = <T>(
|
||||
content: string,
|
||||
schema: Schema,
|
||||
): Promise<T> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const ajv = new Ajv.default();
|
||||
const validate = ajv.compile<T>(schema);
|
||||
const data = parse(content);
|
||||
|
||||
if (!validate(data)) return reject(validate.errors);
|
||||
|
||||
return resolve(data);
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user