From a207c7d45dec3a1eb00175982251b50db197f3b4 Mon Sep 17 00:00:00 2001 From: Sojon Date: Thu, 15 Jun 2023 16:00:32 +0600 Subject: [PATCH] added remove-dark-script for themes-folder --- exampleSite/scripts/removeDarkmode.js | 52 +++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 exampleSite/scripts/removeDarkmode.js diff --git a/exampleSite/scripts/removeDarkmode.js b/exampleSite/scripts/removeDarkmode.js new file mode 100644 index 0000000..9d4b52f --- /dev/null +++ b/exampleSite/scripts/removeDarkmode.js @@ -0,0 +1,52 @@ +const fs = require("fs"); +const path = require("path"); + +const rootDirs = [ + "themes/iot-hub-docs/assets/scss", + "themes/iot-hub-docs/layouts", +]; +const configFiles = [ + { + filePath: "tailwind.config.js", + patterns: ["darkmode:\\s*{[^}]*},", 'darkMode:\\s*"class",'], + }, + { + filePath: "config.toml", + patterns: ["\\S*\\.darkmode[^\\]]*\\]\\n*([\\s\\S]*?)(?=\\[|$)"], + }, +]; + +rootDirs.forEach(removeDarkModeFromPages); +configFiles.forEach(removeDarkMode); + +function removeDarkModeFromFiles(filePath, regexPatterns) { + const fileContent = fs.readFileSync(filePath, "utf8"); + let updatedContent = fileContent; + regexPatterns.forEach((pattern) => { + const regex = new RegExp(pattern, "g"); + updatedContent = updatedContent.replace(regex, ""); + }); + fs.writeFileSync(filePath, updatedContent, "utf8"); +} + +function removeDarkModeFromPages(directoryPath) { + const files = fs.readdirSync(directoryPath); + + files.forEach((file) => { + const filePath = path.join(directoryPath, file); + const stats = fs.statSync(filePath); + if (stats.isDirectory()) { + removeDarkModeFromPages(filePath); + } else if (stats.isFile()) { + removeDarkModeFromFiles(filePath, [ + '(?:(?!["])\\S)*dark:(?:(?![,;"])\\S)*', + "@apply?(\\s)*;", + ]); + } + }); +} + +function removeDarkMode(configFile) { + const { filePath, patterns } = configFile; + removeDarkModeFromFiles(filePath, patterns); +}