All files / packages/sds-metadata/src/generators aura-to-lwc-map.ts

0% Statements 0/7
0% Branches 0/2
0% Functions 0/2
0% Lines 0/7

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 26 27 28                                                       
import { AURA_TO_LWC_TOKENS_MAPPING_FILENAME, AURA_TOKENS_PATH } from "../constants.js";
import { readJSON, writeData } from "../services/file-service.js";
import { SupportedFileFormat } from "../types.js";
 
interface AuraTokenValue {
    auraToken?: string;
}
 
/**
 *  This function makes use of ui.aura-tokens.json file from @salesforce-ux/design-system package
 *  to generate a mapping of aura tokens to lwc tokens.
 * @param outputDir - Custom output directory for generated files. Defaults to current working directory
 */
export async function generateAuraToLwcTokensMapping(outputDir: string = process.cwd(), format: SupportedFileFormat = 'json') {
    const auraTokensJson = await readJSON<Record<string, AuraTokenValue>>(AURA_TOKENS_PATH);
 
    const auraToLwcTokensMapping = Object.entries(auraTokensJson).reduce((acc, [token, valueObj]) => {
        if(valueObj.auraToken) {
            acc[valueObj.auraToken] = `--lwc-${valueObj.auraToken}`;
        }        
        return acc;
    }, {} as Record<string, string>)
    
    const sortedAuraToLwcTokensMapping = Object.fromEntries(
        Object.entries(auraToLwcTokensMapping).sort((a, b) => a[0].localeCompare(b[0]))
    );
    await writeData(AURA_TO_LWC_TOKENS_MAPPING_FILENAME, sortedAuraToLwcTokensMapping, outputDir, format);
}