Skip to content

Commit

Permalink
Make linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
borulday committed Jun 10, 2024
1 parent 3b6517b commit fee0773
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 32 deletions.
6 changes: 2 additions & 4 deletions packages/base-extension/codeGenerators/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ export const colorCodeGenerator = ({
const colorDetailsByModeName = generateColorDetailsByModeName(variableCollections);

let colorVariablesCode = "";
for (const [modeName, colorDetails] of Object.entries(colorDetailsByModeName ?? {})) {

for (const [modeName, colorDetails] of Object.entries(colorDetailsByModeName || {})) {
let variables = [];
let colorSectionName;
for (const { color, shouldDisplayDefaultValue } of colorDetails) {
const adjustedColorSectionName = color.originalName.replace(/\/[^\/]*$/, "").replace(/\//g, " / ");
const adjustedColorSectionName = color.originalName.replace(/\/[^/]*$/, "").replace(/\//g, " / ");

if (colorSectionName !== adjustedColorSectionName) {
variables.push(
Expand All @@ -72,7 +71,6 @@ export const colorCodeGenerator = ({
colorVariablesCode += `${MODE_SEPARATOR}${prefixForMode}${variableName}${variableSuffix}`;
}


const code = `${prefix}${colorsCode}${suffix}${colorVariablesCode}`;

return {
Expand Down
56 changes: 28 additions & 28 deletions packages/zeplin-extension-style-kit/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ function getVariableBySourceId(variableCollections) {
.flatMap(variable => {
variable.remote = remote;

return variable
return variable;
})))
.reduce((acc, variable) => {
acc[variable.sourceId] = variable;
Expand All @@ -266,7 +266,7 @@ function getModeByModeId(variableCollections) {
acc[mode.id] = mode;

return acc;
}, {})
}, {});
}

function getColorDetailsFromVariableValue(variableValue, variableBySourceId, modeByModeId) {
Expand Down Expand Up @@ -301,6 +301,28 @@ function getColorDetailsFromVariableValue(variableValue, variableBySourceId, mod
return { colorValue: colorValue || fallbackColorValue, isRemote: nestedVariable.remote };
}

function setColorObjectsForVariable(variable, variableBySourceId, modeByModeId, colorDetailsByModeName) {
for (const value of variable.values) {
const { colorValue, isRemote } = getColorDetailsFromVariableValue(
value, variableBySourceId, modeByModeId
);

const colorObject = value.generateColorObject(variable, colorValue);
if (colorObject) {
const mode = modeByModeId[value.modeId];
if (colorDetailsByModeName[mode.name]) {
colorDetailsByModeName[mode.name].push({
color: colorObject, shouldDisplayDefaultValue: isRemote
});
} else {
colorDetailsByModeName[mode.name] = [{
color: colorObject, shouldDisplayDefaultValue: isRemote
}];
}
}
}
}

function generateColorDetailsByModeName(variableCollections) {
if (!variableCollections) {
return;
Expand All @@ -311,32 +333,10 @@ function generateColorDetailsByModeName(variableCollections) {
const modeByModeId = getModeByModeId(variableCollections);

for (const variableCollection of variableCollections) {
if (variableCollection.remote) {
continue;
}

for (const group of variableCollection.groups) {
for (const variable of group.variables) {
for (const value of variable.values) {
const { colorValue, isRemote } = getColorDetailsFromVariableValue(
value, variableBySourceId, modeByModeId
);

const colorObject = value.generateColorObject(variable, colorValue);
if (!colorObject) {
continue;
}

const mode = modeByModeId[value.modeId];
if (colorDetailsByModeName[mode.name]) {
colorDetailsByModeName[mode.name].push({
color: colorObject, shouldDisplayDefaultValue: isRemote
});
} else {
colorDetailsByModeName[mode.name] = [{
color: colorObject, shouldDisplayDefaultValue: isRemote
}];
}
if (!variableCollection.remote) {
for (const group of variableCollection.groups) {
for (const variable of group.variables) {
setColorObjectsForVariable(variable, variableBySourceId, modeByModeId, colorDetailsByModeName);
}
}
}
Expand Down

0 comments on commit fee0773

Please sign in to comment.