mirror of
https://github.com/catppuccin/gitea.git
synced 2026-02-02 18:09:02 +08:00
feat!: support auto mode (#42)
* feat!: support auto mode * chore: try to fix formatting * docs: restructure
This commit is contained in:
104
build.ts
104
build.ts
@@ -3,39 +3,24 @@
|
||||
import * as path from "std/path";
|
||||
import * as sass from "sass";
|
||||
import ctp from "npm:@catppuccin/palette";
|
||||
import { updateReadme } from "@catppuccin/deno-lib";
|
||||
|
||||
const builder = (flavor: string, accent: string) => `
|
||||
const __dirname = path.dirname(path.fromFileUrl(import.meta.url));
|
||||
const flavors = Object.keys(ctp.variants);
|
||||
const accents = Object.keys(ctp.labels).slice(0, 14);
|
||||
|
||||
Deno.mkdirSync(path.join(__dirname, "dist"), { recursive: true });
|
||||
|
||||
const sassBuilder = (flavor: string, accent: string) => `
|
||||
@import "@catppuccin/palette/scss/${flavor}";
|
||||
$accent: $${accent};
|
||||
$isDark: ${flavor !== "latte"};
|
||||
@import "theme";
|
||||
`;
|
||||
|
||||
const __dirname = path.dirname(path.fromFileUrl(import.meta.url));
|
||||
|
||||
const accents = [
|
||||
"rosewater",
|
||||
"flamingo",
|
||||
"pink",
|
||||
"mauve",
|
||||
"red",
|
||||
"maroon",
|
||||
"peach",
|
||||
"yellow",
|
||||
"green",
|
||||
"teal",
|
||||
"sky",
|
||||
"sapphire",
|
||||
"blue",
|
||||
"lavender",
|
||||
];
|
||||
|
||||
Deno.mkdirSync(path.join(__dirname, "dist"), { recursive: true });
|
||||
|
||||
const flavors = Object.keys(ctp.variants);
|
||||
for (const flavor of flavors) {
|
||||
for (const accent of accents) {
|
||||
const input = builder(flavor, accent);
|
||||
const input = sassBuilder(flavor, accent);
|
||||
const result = sass.compileString(input, {
|
||||
loadPaths: [
|
||||
path.join(__dirname, "src"),
|
||||
@@ -50,50 +35,35 @@ for (const flavor of flavors) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// refactor this part out to a common import, since ctp/ctp & ctp/userstyles
|
||||
// are both using the same base function
|
||||
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}`;
|
||||
for (const accent of accents) {
|
||||
Deno.writeTextFileSync(
|
||||
path.join(__dirname, "dist", `theme-catppuccin-${accent}-auto.css`),
|
||||
`@import "./theme-catppuccin-latte-${accent}.css" (prefers-color-scheme: light);
|
||||
@import "./theme-catppuccin-mocha-${accent}.css" (prefers-color-scheme: dark);`,
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
const readme = Deno.readTextFileSync(path.join(__dirname, "README.md"));
|
||||
const newcontent = updateReadme({
|
||||
readme,
|
||||
section: "ini",
|
||||
newContent: `
|
||||
\`\`\`
|
||||
const flavorAccentIni = `
|
||||
\`\`\`ini
|
||||
[ui]
|
||||
THEMES = ${
|
||||
flavors
|
||||
.map((f) =>
|
||||
accents
|
||||
.map((a) => `catppuccin-${f}-${a}`)
|
||||
.join(",")
|
||||
).join(",")
|
||||
}
|
||||
THEMES = ${flavors
|
||||
.map((f) => accents.map((a) => `catppuccin-${f}-${a}`).join(","))
|
||||
.join(",")}
|
||||
\`\`\`
|
||||
`,
|
||||
});
|
||||
`;
|
||||
|
||||
Deno.writeTextFileSync(path.join(__dirname, "README.md"), newcontent);
|
||||
const themeAutoIni = `
|
||||
\`\`\`ini
|
||||
[ui]
|
||||
THEMES = ${accents.map((a) => `catppuccin-${a}-auto`).join(",")}
|
||||
\`\`\`
|
||||
`;
|
||||
|
||||
const oldReadme = Deno.readTextFileSync(path.join(__dirname, "README.md"));
|
||||
let newReadme = updateReadme(oldReadme, flavorAccentIni, {
|
||||
section: "ini",
|
||||
});
|
||||
newReadme = updateReadme(newReadme, themeAutoIni, {
|
||||
section: "ini-auto",
|
||||
});
|
||||
Deno.writeTextFileSync(path.join(__dirname, "README.md"), newReadme);
|
||||
|
||||
Reference in New Issue
Block a user