ea22807a3f
The Flutter client (#356) needs to consume the same FabledSword tokens the web SPA uses. Move the data into a structured tokens.json file and generate tokens.generated.css from it on every Vite build. The Flutter side gets its own generator pointed at the same JSON. No visual change — generated CSS matches the previous hand-written file. Also installs @types/node devDependency: tsconfig already declared "types": ["node"] but no Node builtins were referenced in TS until now, so the missing types were latent. The new vite.config.ts plugin imports node:child_process, surfacing the gap.
29 lines
1.3 KiB
JavaScript
29 lines
1.3 KiB
JavaScript
#!/usr/bin/env node
|
|
// Reads ../src/lib/styles/tokens.json and emits tokens.generated.css.
|
|
// Single source of truth for FabledSword tokens shared with the Flutter
|
|
// client. Keep output deterministic — Tailwind reads tokens.json directly,
|
|
// the .css emission is for raw CSS consumers.
|
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { dirname, resolve } from 'node:path';
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const tokensPath = resolve(here, '../src/lib/styles/tokens.json');
|
|
const outPath = resolve(here, '../src/lib/styles/tokens.generated.css');
|
|
const tokens = JSON.parse(readFileSync(tokensPath, 'utf8'));
|
|
|
|
const lines = ['/* GENERATED — do not edit. Source: tokens.json */', ':root {'];
|
|
for (const [name, value] of Object.entries(tokens.colors)) {
|
|
lines.push(` --fs-${name}: ${value};`);
|
|
}
|
|
for (const [name, value] of Object.entries(tokens.radii)) {
|
|
lines.push(` --fs-radius-${name}: ${value};`);
|
|
}
|
|
lines.push(` --fs-font-display: ${tokens.fontStacks.display};`);
|
|
lines.push(` --fs-font-body: ${tokens.fontStacks.body};`);
|
|
lines.push(` --fs-font-mono: ${tokens.fontStacks.mono};`);
|
|
lines.push('}', '[data-fs-app="minstrel"] {', ` --fs-accent: ${tokens.colors.accent};`, '}', '');
|
|
|
|
writeFileSync(outPath, lines.join('\n'));
|
|
console.log(`wrote ${outPath}`);
|