ci: move src/ -> scripts/, deno.json to repo root (#332)
This commit is contained in:
1 parent
f977c5a64c
commit
790e7cb83c
21 files changed
+21
-26
No files matched your search
Executable
+287
@@ -0,0 +1,287 @@
|
||||
#!/usr/bin/env -S deno run --allow-env --allow-read --allow-write --allow-net
|
||||
|
||||
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, 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);
|
||||
|
||||
const userstylesYaml = Deno.readTextFileSync(
|
||||
path.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);
|
||||
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[]>,
|
||||
);
|
||||
|
||||
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}`;
|
||||
})
|
||||
.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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
# THIS FILE IS AUTOGENERATED. DO NOT EDIT IT BY HAND.
|
||||
name: Userstyle Issue
|
||||
description: Report your problems with any of the userstyles here!
|
||||
body:
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: Is there an existing issue outlining your problem?
|
||||
description: Please search to see if an issue already exists for your problem.
|
||||
options:
|
||||
- label: I have searched the existing issues and they do not solve my problem.
|
||||
required: true
|
||||
- type: dropdown
|
||||
attributes:
|
||||
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]
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Describe your problem.
|
||||
description: Also tell us, what do you expect to see?
|
||||
placeholder: The navigation bar on the website is highlighted incorrectly...
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Attach screenshots.
|
||||
description: If applicable, attach screenshots which clearly highlight the issue.
|
||||
- type: input
|
||||
attributes:
|
||||
label: What browser(s) are you seeing the problem on?
|
||||
description: "The browser version is also important, you can find out how to get that info [here](https://github.com/catppuccin/userstyles/blob/main/docs/browsers.md)."
|
||||
placeholder: Firefox v112.0.2
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Any additional comments?
|
||||
description: Add any information that hasn't been covered in the previous sections!
|
||||
@@ -0,0 +1,55 @@
|
||||
<!-- AUTOGEN:README START -->
|
||||
<!-- THIS FILE IS AUTOGENERATED. DO NOT EDIT IT BY HAND -->
|
||||
|
||||
<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
|
||||
<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>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<img src="assets/catwalk.webp"/>
|
||||
</p>
|
||||
|
||||
## Previews
|
||||
|
||||
<details>
|
||||
<summary>🌻 Latte</summary>
|
||||
<img src="assets/latte.webp"/>
|
||||
</details>
|
||||
<details>
|
||||
<summary>🪴 Frappé</summary>
|
||||
<img src="assets/frappe.webp"/>
|
||||
</details>
|
||||
<details>
|
||||
<summary>🌺 Macchiato</summary>
|
||||
<img src="assets/macchiato.webp"/>
|
||||
</details>
|
||||
<details>
|
||||
<summary>🌿 Mocha</summary>
|
||||
<img src="assets/mocha.webp"/>
|
||||
</details>
|
||||
|
||||
$USAGE
|
||||
|
||||
$FAQ
|
||||
|
||||
$COLLABORATORS
|
||||
|
||||
|
||||
|
||||
<p align="center">
|
||||
<img src="https://raw.githubusercontent.com/catppuccin/catppuccin/main/assets/footers/gray0_ctp_on_line.svg?sanitize=true" />
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
Copyright © 2021-present <a href="https://github.com/catppuccin" target="_blank">Catppuccin Org</a>
|
||||
</p>
|
||||
|
||||
<!-- AUTOGEN:README END -->
|
||||
Reference in new issue
Block a user