All files / packages/sds-metadata/src/generators color-styling-hooks.ts

0% Statements 0/8
0% Branches 0/2
0% Functions 0/1
0% Lines 0/8

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                                           
import chroma from "chroma-js";
import { COLOR_STYLING_HOOKS_METADATA_FILENAME, PALLET_COLORS_RAW_JSON } from "../constants.js";
import { readJSON, writeData} from "../services/file-service.js";
import { SupportedFileFormat } from "../types.js";
 
export async function generateColorStylingHooks(outputDir: string = process.cwd(), format: SupportedFileFormat = 'csv') {
    try {
        const colorStylingHooks: Record<string, string> = await readJSON(PALLET_COLORS_RAW_JSON);
        const colorStylingHooksMetadata: Record<string, string> = {};
        Object.entries(colorStylingHooks).forEach(([key, value]) => {
            const hookName = `--slds-g-${key}`;
            colorStylingHooksMetadata[hookName] = chroma(value).hex();
        });
 
        await writeData(COLOR_STYLING_HOOKS_METADATA_FILENAME, colorStylingHooksMetadata, outputDir, format);        
    } catch (error) {
        console.error('Error generating color styling hooks:', error);
        throw error;
    }
}