Files
whynot-design/scripts/sync-shared-styles.mjs
tegwick 80252baf53
Some checks failed
ci / check (push) Has been cancelled
ci / release (push) Has been cancelled
version 0.2.0 replaces fromer version!
2026-05-25 19:32:22 +02:00

30 lines
1.0 KiB
JavaScript

#!/usr/bin/env node
// Regenerate src/elements/_styles.js from src/styles/components.css.
// Run after every edit to components.css.
//
// node scripts/sync-shared-styles.mjs
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 css = readFileSync(resolve(here, "../src/styles/components.css"), "utf8");
const js = `/* Auto-generated from src/styles/components.css by scripts/sync-shared-styles.mjs.
* Do NOT edit by hand. Edit components.css and re-run the script.
*/
export const SHARED_CSS = String.raw\`${css.replace(/\\/g, "\\\\").replace(/\`/g, "\\\`")}\`;
let _sheet = null;
export function getSharedSheet() {
if (!_sheet) {
_sheet = new CSSStyleSheet();
_sheet.replaceSync(SHARED_CSS);
}
return _sheet;
}
`;
writeFileSync(resolve(here, "../src/elements/_styles.js"), js);
console.log("Wrote src/elements/_styles.js (" + js.length + " chars).");