Skip to content

Commit

Permalink
fix(theme/color): put static colors in seperate object hast to preven…
Browse files Browse the repository at this point in the history
…t zombie theme file generation
  • Loading branch information
nuke-ellington committed Aug 9, 2022
1 parent 5b20beb commit 0eab266
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions packages/core/scripts/generate-theme.ts
Expand Up @@ -27,14 +27,15 @@ if (process.argv.length !== 3) {
console.error('Error: Call script with a color file');
}

const staticTheme = {};
const colorFilePath = process.argv[2];
const colorFile = readFileSync(colorFilePath).toString();

function extractZeplinColorExport(file: string): Themes {
const themes: Themes = {};

const colors = file.match(/--\w\w_theme.*/g);
colors.forEach(rawColor => {
colors.forEach((rawColor) => {
const color = rawColor.replace(';', '');

let [alias, name] = color.split('_theme');
Expand Down Expand Up @@ -85,18 +86,14 @@ function extractZeplinColorExport(file: string): Themes {
'--plot2Darkstd-text',
];

if (!themes['static']) {
themes['static'] = {};
}

staticColors.forEach(rawColor => {
staticColors.forEach((rawColor) => {
const color = rawColor.trim().replace(';', '');
let [variableName, value] = color.split(':');
if (colorZombies.indexOf(variableName) >= 0) {
return;
}

themes['static'][variableName] = value;
staticTheme[variableName] = value;
});

return themes;
Expand All @@ -106,14 +103,14 @@ const aliasedThemes = extractZeplinColorExport(colorFile);
const themes: Themes = {};

function formatVariableOutputs(themeVariables: ThemeVariables) {
const s = Object.keys(themeVariables).map(k => {
const s = Object.keys(themeVariables).map((k) => {
return ` ${k}: ${themeVariables[k]},\n`;
});

return s.join('');
}

Object.keys(aliasedThemes).forEach(theme => {
Object.keys(aliasedThemes).forEach((theme) => {
const themeName = alias[theme];
themes[themeName] = aliasedThemes[theme];

Expand Down Expand Up @@ -143,8 +140,8 @@ let data = `${copyrightHeader}
body {
`;

Object.keys(aliasedThemes['static']).forEach(color => {
data += `${color}: ${aliasedThemes.static[color]};
Object.keys(staticTheme).forEach((color) => {
data += `${color}: ${staticTheme[color]};
`;
});

Expand Down

0 comments on commit 0eab266

Please sign in to comment.