Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778#!/usr/bin/env node// The skill cannot drift from what ships. Three checks, run with `npm run check`:// 1. every token and class the skill mentions exists in the CSS (any file// under css/, palettes included);// 2. every palette file defines the whole role vocabulary the base, the// components and the role utilities read;// 3. every per-hue class a palette file defines is named in the skill, so// the skill's list of each palette's hues is complete.
import { readFileSync, readdirSync } from "node:fs";import { join, resolve } from "node:path";
const root = resolve(new URL("..", import.meta.url).pathname);const skill = readFileSync(join(root, "skills", "supram", "SKILL.md"), "utf8");const cssDir = join(root, "css");const paletteDir = join(cssDir, "palettes");const read = (f) => readFileSync(f, "utf8");const paletteFiles = readdirSync(paletteDir).filter((f) => f.endsWith(".css") && f !== "all.css").sort();const css = [ ...readdirSync(cssDir).filter((f) => f.endsWith(".css")).map((f) => read(join(cssDir, f))), ...paletteFiles.map((f) => read(join(paletteDir, f))),].join("\n");
// Names inside code only; prose can say "glass" without meaning a token.// Fenced blocks first, then inline backticks in what remains.const fences = [...skill.matchAll(/```[a-z]*\n([\s\S]*?)```/g)].map((m) => m[1]);const inline = [...skill.replace(/```[a-z]*\n[\s\S]*?```/g, "").matchAll(/`([^`\n]+)`/g)].map((m) => m[1]);const code = [...fences, ...inline];
const tokens = new Set();const classes = new Set();for (const snippet of code) { // A token starts with -- that is not the tail of a class name like grid--auto. for (const t of snippet.matchAll(/(?<![a-z0-9-])--[a-z][a-z0-9-]*/g)) tokens.add(t[0]); // A class is `.name` at the start of a snippet or after a space or comma. for (const c of snippet.matchAll(/(?:^|[\s,])\.([a-z][a-z0-9-]*)/g)) classes.add(c[1]); // Class lists inside class="…" attributes in the recipes. for (const attr of snippet.matchAll(/class="([^"]+)"/g)) { for (const c of attr[1].split(/\s+/)) if (c) classes.add(c); }}
const escape = (s) => s.replace(/[-]/g, "\\-");// Tokens set by the user rather than defined by the CSS are still valid if// the CSS reads them.const defined = (t, src = css) => new RegExp(`${escape(t)}\\s*:`).test(src);const read_ = (t) => css.includes(`var(${t}`);const missingTokens = [...tokens].filter((t) => !defined(t) && !read_(t)).sort();
const hasClass = (c) => new RegExp(`\\.${escape(c)}(?![a-z0-9-])`).test(css);const missingClasses = [...classes].filter((c) => !hasClass(c)).sort();
// 2. The role vocabulary every palette must define.const roles = [ "--bg", "--surface", "--fg", "--muted", "--subtle", "--hairline", "--rule", "--on-glass", "--on-ink", "--accent", "--on-accent", "--accent-text", "--accent-wash", "--link", "--link-hover", "--focus", "--selection", "--on-selection", "--selection-wash", "--ok", "--on-ok", "--ok-wash", "--warn", "--on-warn", "--warn-wash",];const roleGaps = [];// 3. Every per-hue class a palette defines must be named in the skill.const unlisted = [];for (const f of paletteFiles) { const src = read(join(paletteDir, f)); for (const r of roles) if (!defined(r, src)) roleGaps.push(`${f}: ${r}`); for (const m of src.matchAll(/^\s*\.([a-z][a-z0-9-]*)\s*\{/gm)) if (!classes.has(m[1])) unlisted.push(`${f}: .${m[1]}`);}
console.log(`skill mentions ${tokens.size} tokens and ${classes.size} classes; ${paletteFiles.length} palettes: ${paletteFiles.map((f) => f.replace(".css", "")).join(", ")}`);if (missingTokens.length) console.log(`missing tokens:\n ${missingTokens.join("\n ")}`);if (missingClasses.length) console.log(`missing classes:\n ${missingClasses.join("\n ")}`);if (roleGaps.length) console.log(`palettes missing roles:\n ${roleGaps.join("\n ")}`);if (unlisted.length) console.log(`palette classes the skill does not list:\n ${unlisted.join("\n ")}`);if (missingTokens.length || missingClasses.length || roleGaps.length || unlisted.length) process.exit(1);console.log("all present");