Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions postinstall.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Script to copy tinymce to public folder. Read more: https://www.tiny.cloud/docs/tinymce/latest/react-pm-host/
const fse = require('fs-extra');
const path = require('path');
const path = require('node:path');

const topDir = __dirname;
// const topDir = import.meta.dirname;
fse.emptyDirSync(path.join(topDir, 'public', 'tinymce'));
fse.copySync(path.join(topDir, 'node_modules', 'tinymce'), path.join(topDir, 'public', 'tinymce'), {
overwrite: true,
Expand Down
4 changes: 2 additions & 2 deletions public/emailFormat.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<title>Hello, World</title>
</head>
<body>
<h1>Hello, World</h1>
</body>
</html>
</html>
12 changes: 0 additions & 12 deletions public/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,12 @@
/* THEME ROOT (BODY / ROOT) */
/* ========================= */

body.dark-mode:not(.no-global-theme),
body.bm-dashboard-dark:not(.no-global-theme) {
background-color: #1b2a41 !important;
color: #ffffff !important;
}

body.dark-mode:not(.no-global-theme) #root,
body.bm-dashboard-dark:not(.no-global-theme) #root {
background-color: #1b2a41 !important;
color: #ffffff !important;
}

/* SAFE BASE (dark mode) */
body.dark-mode:not(.no-global-theme),
body.bm-dashboard-dark:not(.no-global-theme) {
color: #ffffff;
}

/* ========================= */
/* TYPOGRAPHY (DARK MODE) */
/* ========================= */
Expand Down
30 changes: 11 additions & 19 deletions refactor-css-classes.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// updated on june 11
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable no-console */
const fs = require('fs');
const path = require('path');
const fs = require('node:fs');
const path = require('node:path');
const postcss = require('postcss');
const safeParser = require('postcss-safe-parser');

// Helper to convert kebab-case, snake_case, pascalcase to camelCase
const toCamelCase = str => {
const formatted = str.replace(/[-_](\w)/g, (_, char) => char.toUpperCase());
const formatted = str.replaceAll(/[-_](\w)/gu, (_, char) => char.toUpperCase());
return formatted.charAt(0).toLowerCase() + formatted.slice(1);
};

Expand All @@ -21,7 +21,7 @@ const convertCSSFile = filePath => {

root.walkRules(rule => {
const updated = rule.selectors.map(selector => {
return selector.replace(/\.(\w[\w-]*)/g, (_, className) => {
return selector.replaceAll(/\.(\w[\w-]*)/gu, (_, className) => {
const camel = toCamelCase(className);
classMap[className] = camel;
return `.${camel}`;
Expand All @@ -32,15 +32,12 @@ const convertCSSFile = filePath => {
});

fs.writeFileSync(filePath, root.toString());
// eslint-disable-next-line no-console
console.log(`✅ Updated CSS: ${filePath}`);
// eslint-disable-next-line no-console
// console.log('classMap after CSS processing:', classMap);
};

// Step 2: Replace import statement for CSS module in JSX
const replaceImportStatement = code => {
const importRegex = /import\s+['"](.+\/)?([a-zA-Z0-9_-]+)\.css['"];/;
const importRegex = /import\s+['"](.+\/)?([a-zA-Z0-9_-]+)\.css['"];/u;
// eslint-disable-next-line default-param-last
return code.replace(importRegex, (_, pathPrefix = '', cssFileName) => {
return `import styles from '${pathPrefix}${cssFileName}.module.css';`;
Expand All @@ -64,8 +61,8 @@ const replaceInCodeFile = filePath => {
}

// Step 2: Replace className="text-light input-file-upload" → className={styles.textLight + " " + styles.inputFileUpload}
code = code.replace(/className\s*=\s*["']([^"']+)["']/g, (_, classStr) => {
const classList = classStr.trim().split(/\s+/);
code = code.replaceAll(/className\s*=\s*["']([^"']+)["']/gu, (_, classStr) => {
const classList = classStr.trim().split(/\s+/u);

// Skip transforming if no class in classList exists in classMap
if (classList.every(cls => !classMap[cls])) {
Expand Down Expand Up @@ -98,36 +95,31 @@ const walkDir = dir => {
if (stats.isDirectory()) {
walkDir(fullPath);
} else if (file.endsWith('.css')) {
cssFiles.push(fullPath); // Add CSS file path to the array
cssFiles.push(fullPath);
} else if (
file.endsWith('.js') ||
file.endsWith('.jsx') ||
file.endsWith('.ts') ||
file.endsWith('.tsx') ||
file.endsWith('.html')
) {
codeFiles.push(fullPath); // Add JS/JSX file path to the array
codeFiles.push(fullPath);
}
});

// Now process CSS files first
cssFiles.forEach(cssFile => {
console.log('Processing CSS file:', cssFile);
convertCSSFile(cssFile); // Process CSS files
convertCSSFile(cssFile);
});

// Then process code files (JS/JSX, etc.)
codeFiles.forEach(codeFile => {
console.log('Processing code file:', codeFile);
replaceInCodeFile(codeFile); // Process JS/JSX files
replaceInCodeFile(codeFile);
});
};

// 🚀 Start here: Replace with your actual project folder path
const rootDir = 'src/components/HGNForm';
walkDir(rootDir);

// const mapPath = path.join(__dirname, 'class-map.json');
// fs.writeFileSync(mapPath, JSON.stringify(classMap, null, 2));
// // eslint-disable-next-line no-console
// console.log(`🗺️ Class map written to ${mapPath}`);
Loading