separate dependencies and devDependencies, added removeDarkmode.js

This commit is contained in:
somrat sorkar
2023-05-29 11:36:12 +06:00
parent 517cdd8d1b
commit 55c13589a0
2 changed files with 101 additions and 18 deletions
+28 -18
View File
@@ -1,6 +1,6 @@
{
"name": "astroplate",
"version": "1.2.0",
"version": "1.2.1",
"description": "Astro and Tailwindcss boilerplate",
"author": "zeon.studio",
"license": "MIT",
@@ -8,21 +8,18 @@
"scripts": {
"dev": "astro dev",
"build": "astro build",
"json": "node scripts/jsonGenerator.js",
"format": "prettier -w ./src"
"format": "prettier -w ./src",
"generate-json": "node scripts/jsonGenerator.js",
"remove-darkmode": "node scripts/removeDarkMode.js && yarn format"
},
"dependencies": {
"@astrojs/image": "^0.16.9",
"@astrojs/mdx": "^0.19.2",
"@astrojs/mdx": "^0.19.4",
"@astrojs/react": "^2.2.0",
"@astrojs/rss": "^2.4.2",
"@astrojs/rss": "^2.4.3",
"@astrojs/sitemap": "^1.3.1",
"@astrojs/tailwind": "^3.1.3",
"@tailwindcss/forms": "^0.5.3",
"@tailwindcss/typography": "^0.5.9",
"@types/marked": "^5.0.0",
"@types/react": "^18.2.6",
"astro": "^2.5.1",
"astro": "^2.5.5",
"astro-auto-import": "^0.3.0",
"date-fns": "^2.30.0",
"date-fns-tz": "^2.0.0",
@@ -30,22 +27,35 @@
"fuse.js": "^6.6.2",
"github-slugger": "^2.0.0",
"gray-matter": "^4.0.3",
"marked": "^5.0.2",
"postcss": "^8.4.23",
"prettier": "^2.8.8",
"prettier-plugin-astro": "^0.9.0",
"marked": "^5.0.3",
"prettier-plugin-astro": "^0.9.1",
"prettier-plugin-tailwindcss": "^0.3.0",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.8.0",
"react-icons": "^4.9.0",
"react-lite-youtube-embed": "^2.3.52",
"remark-collapse": "^0.1.2",
"remark-toc": "^8.0.1",
"sass": "^1.62.1",
"sharp": "^0.32.1",
"swiper": "^9.3.2",
"swiper": "^9.3.2"
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.3",
"@tailwindcss/typography": "^0.5.9",
"@types/marked": "^5.0.0",
"@types/node": "20.2.5",
"@types/react": "18.2.7",
"@types/react-dom": "18.2.4",
"autoprefixer": "^10.4.14",
"eslint": "^8.41.0",
"postcss": "^8.4.24",
"prettier": "^2.8.8",
"prettier-plugin-astro": "^0.9.1",
"prettier-plugin-tailwindcss": "^0.3.0",
"sass": "^1.62.1",
"tailwindcss": "^3.3.2",
"tailwind-bootstrap-grid": "^5.0.1",
"tailwindcss": "^3.3.2"
"typescript": "5.0.4"
}
}
+73
View File
@@ -0,0 +1,73 @@
const fs = require("fs");
const path = require("path");
const rootDirs = [
"src/pages",
"src/lib",
"src/hooks",
"src/layouts",
"src/styles",
];
const configFiles = [
{
filePath: "tailwind.config.js",
patterns: ["darkmode:\\s*{[^}]*},", 'darkMode:\\s*"class",'],
},
{ filePath: "src/config/theme.json", patterns: ["colors.darkmode"] },
];
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);
console.log(files);
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)*',
]);
}
});
}
function removeDarkMode(configFile) {
const { filePath, patterns } = configFile;
if (filePath === "tailwind.config.js") {
removeDarkModeFromFiles(filePath, patterns);
} else {
const contentFile = JSON.parse(fs.readFileSync(filePath, "utf8"));
patterns.forEach((pattern) => deleteNestedProperty(contentFile, pattern));
fs.writeFileSync(filePath, JSON.stringify(contentFile));
}
}
function deleteNestedProperty(obj, propertyPath) {
const properties = propertyPath.split(".");
let currentObj = obj;
for (let i = 0; i < properties.length - 1; i++) {
const property = properties[i];
if (currentObj.hasOwnProperty(property)) {
currentObj = currentObj[property];
} else {
return; // Property not found, no need to continue
}
}
delete currentObj[properties[properties.length - 1]];
}