Skip to content

Commit

Permalink
fix(ThemeTable): refactor to write file contents all at once
Browse files Browse the repository at this point in the history
  • Loading branch information
ImCoolNowRight committed Oct 31, 2023
1 parent 77ccf44 commit 1fd1562
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export function writeMarkdownFiles(
const roleFile =
mdFile === `${folderPath}/color.md` ||
mdFile === `${folderPath}/typography.md`;
const content = roleFile
let content = roleFile
? `${themeProperty} Value | Components | Role \n`
: `${themeProperty} Value | Components \n`;
//ensure folder exists
Expand All @@ -240,12 +240,11 @@ export function writeMarkdownFiles(
}
}
);
fs.writeFileSync(mdFile, content, { encoding: 'utf8', flag: 'w' });
// needed for a markdown file below the header
const header = roleFile
? '--------|--------|--------\n'
: '--------|-------- \n';
fs.appendFileSync(mdFile, header);
content += header;
for (const key in dict) {
let modifiedKey = `theme.${themeProperty}.`;
modifiedKey = modifiedKey.concat(key);
Expand All @@ -261,8 +260,7 @@ export function writeMarkdownFiles(
valuesAndComponents = valuesAndComponents.concat(role);
}
//everything is appended to the file
fs.appendFileSync(mdFile, valuesAndComponents);
fs.appendFileSync(mdFile, '\n');
content += valuesAndComponents + '\n';
const duplicates = themeValueArray.some(val => modifiedKey.includes(val));
if (duplicates === true) {
themeValueArray.splice(themeValueArray.indexOf(modifiedKey), 1);
Expand All @@ -278,9 +276,9 @@ export function writeMarkdownFiles(
mdFile
)}`
: `${temporary} | No components are using this value`;
fs.appendFileSync(mdFile, unusedThemeValue);
fs.appendFileSync(mdFile, '\n');
content += unusedThemeValue + '\n';
}
fs.writeFileSync(mdFile, content, { encoding: 'utf8', flag: 'w' });
}

/**
Expand Down

0 comments on commit 1fd1562

Please sign in to comment.