2023-08-22 11:22:46 +00:00
|
|
|
#!/usr/bin/env -S deno run -A
|
2023-08-23 10:22:00 +00:00
|
|
|
|
2023-08-22 11:22:46 +00:00
|
|
|
import * as path from "std/path";
|
|
|
|
import * as sass from "sass";
|
2023-12-27 21:21:10 +00:00
|
|
|
import * as rp from "npm:@rose-pine/palette";
|
2023-08-22 11:22:46 +00:00
|
|
|
|
2023-12-27 23:22:18 +00:00
|
|
|
type Flavor = "main" | "moon" | "dawn";
|
|
|
|
|
|
|
|
function isUpperCase(str: string) {
|
|
|
|
return str !== str.toLowerCase() && str === str.toUpperCase();
|
|
|
|
}
|
|
|
|
|
|
|
|
const builder = (flavor: Flavor, accent: string) => `
|
|
|
|
${Object.keys(rp.roleColors)
|
|
|
|
.map(
|
|
|
|
(color) =>
|
|
|
|
`$${color
|
|
|
|
.split("")
|
|
|
|
.map((c) => (isUpperCase(c) ? "-" + c.toLowerCase() : c))
|
|
|
|
.join("")}: #${
|
|
|
|
/* @ts-ignore I hate typescript */
|
|
|
|
rp.roleColors[color][flavor].hex
|
|
|
|
};`,
|
|
|
|
)
|
|
|
|
.join("\n")}
|
2023-12-27 21:21:10 +00:00
|
|
|
|
2023-08-22 11:22:46 +00:00
|
|
|
$accent: $${accent};
|
2023-12-27 21:21:10 +00:00
|
|
|
$isDark: ${flavor !== "dawn"};
|
|
|
|
|
2023-08-22 11:22:46 +00:00
|
|
|
@import "theme";
|
|
|
|
`;
|
|
|
|
|
|
|
|
const __dirname = path.dirname(path.fromFileUrl(import.meta.url));
|
|
|
|
|
2023-12-27 21:21:10 +00:00
|
|
|
const accents = ["love", "gold", "rose", "pine", "foam", "iris"];
|
2023-08-22 11:22:46 +00:00
|
|
|
|
|
|
|
Deno.mkdirSync(path.join(__dirname, "dist"), { recursive: true });
|
|
|
|
|
2023-12-27 21:21:10 +00:00
|
|
|
const flavors = Object.keys(rp.variantColors);
|
2023-08-22 11:22:46 +00:00
|
|
|
for (const flavor of flavors) {
|
|
|
|
for (const accent of accents) {
|
2023-12-27 23:22:18 +00:00
|
|
|
const input = builder(flavor as Flavor, accent);
|
2023-08-22 11:22:46 +00:00
|
|
|
const result = sass.compileString(input, {
|
|
|
|
loadPaths: [
|
|
|
|
path.join(__dirname, "src"),
|
|
|
|
path.join(__dirname, "node_modules"),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.writeTextFileSync(
|
2023-12-27 21:21:10 +00:00
|
|
|
path.join(__dirname, "dist", `theme-rose-pine-${flavor}-${accent}.css`),
|
2023-08-22 11:22:46 +00:00
|
|
|
result.css,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-23 10:22:00 +00:00
|
|
|
// TODO:
|
|
|
|
// refactor this part out to a common import, since ctp/ctp & ctp/userstyles
|
|
|
|
// are both using the same base function
|
2023-08-22 11:22:46 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
const readme = Deno.readTextFileSync(path.join(__dirname, "README.md"));
|
|
|
|
const newcontent = updateReadme({
|
|
|
|
readme,
|
|
|
|
section: "ini",
|
|
|
|
newContent: `
|
|
|
|
\`\`\`
|
|
|
|
[ui]
|
2023-12-27 21:21:10 +00:00
|
|
|
THEMES = ${flavors
|
2023-12-27 23:36:39 +00:00
|
|
|
.map((f) => accents.map((a) => `rose-pine-${f}-${a}`).join(","))
|
2023-12-27 21:21:10 +00:00
|
|
|
.join(",")}
|
2023-08-22 11:22:46 +00:00
|
|
|
\`\`\`
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.writeTextFileSync(path.join(__dirname, "README.md"), newcontent);
|