#!/usr/bin/env -S deno run -A import * as path from "std/path"; import * as sass from "sass"; import * as rp from "npm:@rose-pine/palette"; type Flavor = "main" | "moon" | "dawn"; function isUpperCase(str: string) { return str !== str.toLowerCase() && str === str.toUpperCase(); } console.log(` ${Object.keys(rp.roleColors) .map( (color) => `$${color .split("") .map((c) => (isUpperCase(c) ? "-" + c.toLowerCase() : c)) .join("")}: #${ /* @ts-ignore I hate typescript */ rp.roleColors[color]["main"].hex };`, ) .join("\n")} `); 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")} $accent: $${accent}; $isDark: ${flavor !== "dawn"}; @import "theme"; `; const __dirname = path.dirname(path.fromFileUrl(import.meta.url)); const accents = ["love", "gold", "rose", "pine", "foam", "iris"]; Deno.mkdirSync(path.join(__dirname, "dist"), { recursive: true }); const flavors = Object.keys(rp.variantColors); for (const flavor of flavors) { for (const accent of accents) { const input = builder(flavor as Flavor, accent); const result = sass.compileString(input, { loadPaths: [ path.join(__dirname, "src"), path.join(__dirname, "node_modules"), ], }); Deno.writeTextFileSync( path.join(__dirname, "dist", `theme-rose-pine-${flavor}-${accent}.css`), result.css, ); } } // 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 = ""; const startMarker = ``; const endMarker = ``; 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] THEMES = ${flavors .map((f) => accents.map((a) => `rp-${f}-${a}`).join(",")) .join(",")} \`\`\` `, }); Deno.writeTextFileSync(path.join(__dirname, "README.md"), newcontent);