From 646b084a1288f038e29748f63b4a942d1b7708ae Mon Sep 17 00:00:00 2001 From: Sercan Yemen <117369+srcn@users.noreply.github.com> Date: Tue, 8 Nov 2022 12:47:38 +0300 Subject: [PATCH] Only write the user themes file if the map has been changed. This fixes the issue where watcher being triple triggered on cold starts. --- src/@fuse/tailwind/plugins/theming.js | 28 ++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/@fuse/tailwind/plugins/theming.js b/src/@fuse/tailwind/plugins/theming.js index 8ba0bdab..f2d6bf6c 100644 --- a/src/@fuse/tailwind/plugins/theming.js +++ b/src/@fuse/tailwind/plugins/theming.js @@ -96,14 +96,32 @@ const theming = plugin.withOptions((options) => ({ /* Generate the SASS map using the themes object */ const sassMap = jsonToSassMap(JSON.stringify({'user-themes': themes})); - /* Write the SASS map to the file */ - fs.writeFile(path.resolve(__dirname, ('../../styles/user-themes.scss')), sassMap, (err) => + /* Get the file path */ + const filename = path.resolve(__dirname, ('../../styles/user-themes.scss')); + + /* Read the file and get its data */ + let data; + try { - if ( err ) + data = fs.readFileSync(filename, {encoding: 'utf8'}); + } + catch ( err ) + { + console.error(err); + } + + /* Write the file if the map has been changed */ + if ( data !== sassMap ) + { + try { - return console.log(err); + fs.writeFileSync(filename, sassMap, {encoding: 'utf8'}); } - }); + catch ( err ) + { + console.error(err); + } + } /** * Iterate through the user's themes and build Tailwind components containing