The rws (Remove White Spaces) script is a utility that removes extra white spaces from className attributes in JSX and other supported file types. It recursively traverses through directories, processes files, and updates class names to remove extra white spaces while maintaining a single space between class names.
To use the rws script, follow these steps:
-
Create a file named
rws.jsin your project's root directory. -
Copy and paste the contents of the
rws.jsscript into the newly created file.
-
Open a terminal and navigate to your project's root directory.
-
Run the
rwsscript using the following command:node rws.js [rootDirectory]
Replace
[rootDirectory]with the path to the directory you want to process. If no directory is provided, the script will default to using./.Example 1: Process files in the current directory (
./):node rws.js
Example 2: Process files in a specific directory:
node rws.js /path/to/your/root/directory
This will execute the script, which will recursively traverse through directories, process supported files, and remove extra white spaces from
classNameattributes.
The script allows you to configure certain directories that should be ignored during processing. To customize this setting, open the rws.js file and locate the directoriesToIgnore array at the top of the script. You can add directory names to this array that you want the script to skip processing.
const directoriesToIgnore = ["node_modules", ".git", ".next"]; // Add or remove more directories as neededYou can also configure the list of accepted file types that the script should process. Open the rws.js file and locate the acceptedFileExtensions array at the top of the script. Add or remove file extensions as needed.
const acceptedFileExtensions = [".js", ".jsx", ".ts", ".tsx"]; // Add or remove more extensions as needed-
Before using the script, make sure to back up your files or work on a subset of files to ensure the desired outcome.
-
This script modifies files directly. Make sure you're using version control (such as Git) to track changes and revert them if necessary.