All files / infrastructure/scripts/src/brand/adapters files.ts

0% Statements 0/13
0% Branches 0/14
0% Functions 0/2
0% Lines 0/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25                                                 
import { readFileSync } from "node:fs";
import postcss from "postcss";
import { at } from "../../shared/adapters/git.ts";
 
const readText = (path: string): string => readFileSync(at(path), "utf8");
 
/** Every `--*` declared in a top-level `@theme` or `:root`; a later declaration wins. */
export const readCustomProperties = (path: string): Map<string, string> => {
    const properties = new Map<string, string>();
 
    for (const node of postcss.parse(readText(path)).nodes) {
        const isTheme = node.type === "atrule" && node.name === "theme";
        const isRoot = node.type === "rule" && node.selector === ":root";
        if (!isTheme && !isRoot) continue;
 
        for (const child of node.nodes ?? []) {
            if (child.type === "decl" && child.prop.startsWith("--")) {
                properties.set(child.prop, child.value);
            }
        }
    }
 
    return properties;
};