https://github.com/helgesverre/tailwind-size-migrator
A command-line tool that automatically migrates legacy Tailwind CSS height/width utility combinations to the new `size-{n}` utility class.
https://github.com/helgesverre/tailwind-size-migrator
Last synced: 21 days ago
JSON representation
A command-line tool that automatically migrates legacy Tailwind CSS height/width utility combinations to the new `size-{n}` utility class.
- Host: GitHub
- URL: https://github.com/helgesverre/tailwind-size-migrator
- Owner: HelgeSverre
- Created: 2024-11-26T13:22:48.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-11-26T13:53:40.000Z (11 months ago)
- Last Synced: 2025-01-09T02:51:52.775Z (9 months ago)
- Language: Python
- Homepage:
- Size: 1.17 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Tailwind Size Migrator 🎨
[](https://opensource.org/licenses/MIT)
[](https://blog.codinghorror.com/the-works-on-my-machine-certification-program/)
[](https://github.com/helgesverre)
[](https://xkcd.com/1205/)
A command-line tool that automatically migrates legacy Tailwind CSS height/width utility combinations to the new
`size-{n}` utility class where applicable.## What it does
This tool scans your project files, finding instances where you've used `h-{n}` and `w-{n}` together
with the same value (where n is 1-12) and replaces them with the equivalent `size-{n}` utility class. Yes, this is
literally all it does.For example:
```html
......
```## Features
- 🔍 Recursively scans directories for specified file extensions (like find+replace but more complicated)
- 🚫 Configurable directory exclusion (because we learned from that one time we borked node_modules)
- ✨ Only updates files that need changes (revolutionary, I know)
- 📝 Provides detailed console output of processed files (for when you need to know what you broke)
- 🔒 Safe processing with error handling (as safe as modifying files can be)
- 💡 Maintains all other classes and file formatting (we're not monsters)
- 🔄 Dry run mode to preview changes (for the paranoid among us)## Installation
```bash
git clone https://github.com/helgesverre/tailwind-size-migrator.git
cd tailwind-size-migrator
```## Usage
1. Navigate to your project directory
2. Back up your files (you're going to ignore this anyway)
3. Run the script with your desired options:```bash
# Use defaults (current directory, .html and .blade.php files, vendor and node_modules folders are excluded)
python main.py# Specify a different directory (default is current directory, which makes sense if you copy the script to your project)
python main.py -p ./src# Specify custom extensions (for you non-Laravel folks, you know who you are)
python main.py -e .jsx .tsx .html# Exclude specific directories (instead of the defaults vendor and node_modules)
python main.py -x build dist cache# Specify path, extensions and exclusions (for the control freaks)
python main.py -p ./src -e .jsx .tsx -x build dist# Do a dry run to see what would be changed without making changes
python main.py --dry-run# Get help
python main.py --help
```### Command Line Options
| Option | Description |
|------------------------|-----------------------------------------------------------|
| `-p`, `--path` | Directory path to search in (default: current directory) |
| `-e`, `--ext` | File extensions to process (default: .html .blade.php) |
| `-x`, `--exclude-dirs` | Directories to exclude (default: vendor node_modules) |
| `--dry-run` | Show which files would be modified without making changes |## Example Output
```
Starting Tailwind class replacement...
Search path: /path/to/your/project
File extensions: .html, .blade.php
Excluded directories: vendor, node_modules
Searching for files...✓ Updated: ./resources/views/components/icon.blade.php
- Skipped: ./resources/views/layouts/app.blade.php (no changes needed)
✓ Updated: ./resources/views/dashboard.blade.phpSummary:
Files scanned: 3
Files updated: 2
```## Formatting
```shell
pipx run black main.py
```## Requirements
- Python 3.6 or higher (I actually have no clue, figure it out yourself, nobody understands python anyways)