From 1fd1562499add9451ae5223e29d0721ba2f6eb5e Mon Sep 17 00:00:00 2001 From: "David Richards, Jr" Date: Tue, 31 Oct 2023 14:51:31 -0400 Subject: [PATCH] fix(ThemeTable): refactor to write file contents all at once --- .../scripts/generate-theme-props-table.mjs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/apps/lightning-ui-docs/scripts/generate-theme-props-table.mjs b/packages/apps/lightning-ui-docs/scripts/generate-theme-props-table.mjs index 00f9bd3fa..3e31a49f6 100644 --- a/packages/apps/lightning-ui-docs/scripts/generate-theme-props-table.mjs +++ b/packages/apps/lightning-ui-docs/scripts/generate-theme-props-table.mjs @@ -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 @@ -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); @@ -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); @@ -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' }); } /**