Skip to content

Commit 86bd186

Browse files
fix: prevent duplicate variable in tailwind
1 parent 9c92c12 commit 86bd186

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

apps/studio/electron/main/assets/styles.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,16 @@ async function createTailwindColorVariable(
141141

142142
const newCssVarName = parentName?.length ? `${parentName}-${camelCaseName}` : camelCaseName;
143143

144-
// Update CSS file
145-
const updatedCssContent = await addTailwindCssVariable(cssContent, newCssVarName, newColor);
146-
fs.writeFileSync(cssPath, updatedCssContent);
144+
// Check if CSS variable already exists
145+
const cssVariables = extractTailwindCssVariables(cssContent);
146+
147+
if (cssVariables.root[newCssVarName] || cssVariables.dark[newCssVarName]) {
148+
return { success: false, error: `CSS variable --${newCssVarName} already exists` };
149+
} else {
150+
// Variable doesn't exist, add it
151+
const updatedCssContent = await addTailwindCssVariable(cssContent, newCssVarName, newColor);
152+
fs.writeFileSync(cssPath, updatedCssContent);
153+
}
147154

148155
// Update config file
149156
const updateAst = parse(configContent, {

0 commit comments

Comments
 (0)