@greensight/gds
Version:
Greensight Design System
35 lines (27 loc) • 961 B
JavaScript
const writeFile = require('./writeFile');
const getVars = (vars, prefix) =>
Object.keys(vars).reduce((acc, key) => {
const name = prefix ? `${prefix}-${key}` : key;
const value = vars[key];
return `${acc}$${name}: ${value};\n`;
}, '');
const DEFAULT_VARIABLES = {
gutterStep: 8,
gutterStepMinor: 4,
};
function serializeVariables(config, tokens) {
const {
colors,
shadows,
layout: { breakpoints },
} = tokens;
const defaultVariables = Object.entries(DEFAULT_VARIABLES)
.map(([key, value]) => `$${key}: ${value}px;`)
.join('\n');
const colorVars = getVars(colors, 'cl');
const shadowsVars = getVars(shadows, 'shadow');
const breakpointVars = getVars(breakpoints);
const fileData = [defaultVariables, colorVars, shadowsVars, breakpointVars].join('\n');
writeFile({ name: 'variables', fileData, config });
}
module.exports = serializeVariables;