Skip to content

Commit

Permalink
fjern ubrukte verdier
Browse files Browse the repository at this point in the history
  • Loading branch information
dagfrode committed Jan 15, 2025
1 parent 982dcd0 commit 8b62d09
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/ffe-core/scripts/generate-semantic-colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const fs = require('fs');
const path = require('path');
const writeToFile = require('./lib/writeToFile');

const usedPrimitive = {};
const usedSemantic = {};

const files = {
primitive: '01 Primitive.value.json',
semanticLight: '02 Semantic.Light.json',
Expand All @@ -23,7 +26,9 @@ const convertPrimitivesJsonToCss = jsonFile => {
.replace(/ø/g, 'oe')
.replace(/æ/g, 'ae')
.replace(/å/g, 'aa');
cssLines.push(`${cssVarName}: ${value.$value};`);
if (usedPrimitive[`var(${cssVarName})`]) {
cssLines.push(`${cssVarName}: ${value.$value};`);
}
} else if (typeof value === 'object') {
processColorTokens(value, `${prefix}${key}-`);
}
Expand Down Expand Up @@ -58,6 +63,7 @@ const convertContextJsonToCss = jsonFile => {
.replace(/å/g, 'aa')})`
: value.$value;
cssLines.push(`${cssVarName}: ${cssVarValue};`);
usedSemantic[cssVarValue] = true;
} else if (typeof value === 'object') {
processColorTokens(value, `${prefix}${key}-`);
}
Expand Down Expand Up @@ -98,7 +104,10 @@ const convertSemanticJsonToCss = (
.replace(/æ/g, 'ae')
.replace(/å/g, 'aa')})`
: value.$value;
cssLines.push(`${cssVarName}: ${cssVarValue};`);
if (usedSemantic[`var(${cssVarName})`]) {
cssLines.push(`${cssVarName}: ${cssVarValue};`);
usedPrimitive[cssVarValue] = true;
}
} else if (typeof value === 'object') {
processColorTokens(value, `${prefix}${key}-`);
}
Expand Down Expand Up @@ -135,11 +144,11 @@ function filePath(filename) {

function generateSemanticColors() {
let cssContent = '// Generated from Figma tokens';
cssContent += `\n\n${convertPrimitivesJsonToCss(filePath(files.primitive))}`;
cssContent += `\n\n${convertSemanticJsonToCss(filePath(files.semanticLight))}`;
cssContent += `\n\n${convertSemanticJsonToCss(filePath(files.semanticDark), filePath(files.context), filePath(files.contextAccent))}`;
cssContent += `\n\n// Context accent \n.accent {\n${convertContextJsonToCss(filePath(files.contextAccent)).join('\n')}}\n`;
cssContent += `\n\n// Context \n:root,\n:host {\n${convertContextJsonToCss(filePath(files.context)).join('\n')}}\n`;
cssContent += `\n\n${convertSemanticJsonToCss(filePath(files.semanticLight))}`;
cssContent += `\n\n${convertSemanticJsonToCss(filePath(files.semanticDark), filePath(files.context), filePath(files.contextAccent))}`;
cssContent += `\n\n${convertPrimitivesJsonToCss(filePath(files.primitive))}`;

writeToFile('less/colors-semantic.less')(cssContent);
writeToFile('css/colors-semantic.css')(cssContent);
Expand Down

0 comments on commit 8b62d09

Please sign in to comment.