Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
AI-powered design system generator that produces complete, tailored design systems from project requirements.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/embed-tokens.cjs
1#!/usr/bin/env node2/**3* embed-tokens.cjs4* Reads design-tokens.css and outputs embeddable inline CSS.5* Use when generating standalone HTML files (infographics, slides, etc.)6*7* Usage:8* node embed-tokens.cjs # Output full CSS9* node embed-tokens.cjs --minimal # Output only commonly used tokens10* node embed-tokens.cjs --style # Wrap in <style> tags11*/1213const fs = require('fs');14const path = require('path');1516// Find project root (look for assets/design-tokens.css)17function findProjectRoot(startDir) {18let dir = startDir;19while (dir !== '/') {20if (fs.existsSync(path.join(dir, 'assets', 'design-tokens.css'))) {21return dir;22}23dir = path.dirname(dir);24}25return null;26}2728const projectRoot = findProjectRoot(process.cwd());29if (!projectRoot) {30console.error('Error: Could not find assets/design-tokens.css');31process.exit(1);32}3334const tokensPath = path.join(projectRoot, 'assets', 'design-tokens.css');3536// Minimal tokens commonly used in infographics/slides37const MINIMAL_TOKENS = [38'--primitive-spacing-',39'--primitive-fontSize-',40'--primitive-fontWeight-',41'--primitive-lineHeight-',42'--primitive-radius-',43'--primitive-shadow-glow-',44'--primitive-gradient-',45'--primitive-duration-',46'--color-primary',47'--color-secondary',48'--color-accent',49'--color-background',50'--color-surface',51'--color-foreground',52'--color-border',53'--typography-font-',54'--card-',55];5657function extractTokens(css, minimal = false) {58// Extract :root block59const rootMatch = css.match(/:root\s*\{([^}]+)\}/g);60if (!rootMatch) return '';6162let allVars = [];63for (const block of rootMatch) {64const vars = block.match(/--[\w-]+:\s*[^;]+;/g) || [];65allVars = allVars.concat(vars);66}6768if (minimal) {69allVars = allVars.filter(v =>70MINIMAL_TOKENS.some(token => v.includes(token))71);72}7374// Dedupe75allVars = [...new Set(allVars)];7677return `:root {\n ${allVars.join('\n ')}\n}`;78}7980// Parse args81const args = process.argv.slice(2);82const minimal = args.includes('--minimal');83const wrapStyle = args.includes('--style');8485try {86const css = fs.readFileSync(tokensPath, 'utf-8');87let output = extractTokens(css, minimal);8889if (wrapStyle) {90output = `<style>\n/* Design Tokens (embedded for standalone HTML) */\n${output}\n</style>`;91} else {92output = `/* Design Tokens (embedded for standalone HTML) */\n${output}`;93}9495console.log(output);96} catch (err) {97console.error(`Error reading tokens: ${err.message}`);98process.exit(1);99}100