30 lines
1.0 KiB
JavaScript
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).");
|