/*** NATIVE ------------------------------------------- ***/ import { mkdir, writeFile } from "node:fs/promises"; /*** UTILITY ------------------------------------------ ***/ import { palette, raw, yang, yin } from "../src/colors"; import { reduced } from "../src/index"; const buildScss = (): string => { const lines: string[] = ["// Generated from src/colors.ts — do not edit by hand", ""]; for (const hue of Object.keys(palette).sort()) { const shades = palette[hue as keyof typeof palette]; for (const shade of Object.keys(shades).sort()) { const value = shades[Number(shade) as 1]; lines.push(`$uchu-${hue}-${shade}-raw: ${raw[hue][shade]};`); lines.push(`$uchu-${hue}-${shade}: ${value};`); } lines.push(""); } lines.push(`$uchu-yang: ${yang};`); lines.push(`$uchu-yin: ${yin};`); lines.push(""); lines.push(":root {"); for (const hue of Object.keys(palette).sort()) { const shades = palette[hue as keyof typeof palette]; for (const shade of Object.keys(shades).sort()) { lines.push(` --uchu-${hue}-${shade}-raw: #{$uchu-${hue}-${shade}-raw};`); lines.push(` --uchu-${hue}-${shade}: #{$uchu-${hue}-${shade}};`); } } lines.push(` --uchu-yang: #{$uchu-yang};`); lines.push(` --uchu-yin: #{$uchu-yin};`); lines.push("}", ""); return lines.join("\n"); }; const buildCss = (): string => { const lines: string[] = ["/* Generated from src/colors.ts — do not edit by hand */", "", ":root {"]; for (const hue of Object.keys(palette).sort()) { const shades = palette[hue as keyof typeof palette]; for (const shade of Object.keys(shades).sort()) { const value = shades[Number(shade) as 1]; lines.push(` --uchu-${hue}-${shade}-raw: ${raw[hue][shade]};`); lines.push(` --uchu-${hue}-${shade}: ${value};`); } } lines.push(` --uchu-yang: ${yang};`); lines.push(` --uchu-yin: ${yin};`); lines.push("}", ""); return lines.join("\n"); }; const buildCssReduced = (): string => { const lines: string[] = ["/* Generated from src/index.ts — do not edit by hand */", "", ":root {"]; for (const hue of Object.keys(reduced).sort()) { const shades = reduced[hue as keyof typeof reduced]; for (const shade of Object.keys(shades).sort()) { const value = shades[Number(shade) as 1]; switch(Number(shade)) { case 1: { lines.push(` --uchu-light-${hue}-raw: ${raw[hue][shade]};`); lines.push(` --uchu-light-${hue}: ${value};`); break; } case 2: { lines.push(` --uchu-${hue}-raw: ${raw[hue][shade]};`); lines.push(` --uchu-${hue}: ${value};`); break; } case 3: { lines.push(` --uchu-dark-${hue}-raw: ${raw[hue][shade]};`); lines.push(` --uchu-dark-${hue}: ${value};`); break; } } } } lines.push(` --uchu-yang: ${yang};`); lines.push(` --uchu-yin: ${yin};`); lines.push("}", ""); return lines.join("\n"); }; /*** RUNTIME ------------------------------------------ ***/ await mkdir("dist", { recursive: true }); await writeFile("dist/_palette.scss", buildScss()); await writeFile("dist/uchu.css", buildCss()); await writeFile("dist/uchu-reduced.css", buildCssReduced()); await writeFile("demo/asset/style/uchu.css", buildCss()); await writeFile("demo/asset/style/uchu-reduced.css", buildCssReduced()); console.log("Generated dist/_palette.scss and dist/uchu.css");