A powerful Python tool that scans PHP projects and extracts Tailwind CSS components for easy reuse and reference.
Clone this repository:
git clone https://github.com/guleyc/LocalTailwindExtractor.git cd LocalTailwindExtractor
Install required dependencies:
pip install beautifulsoup4
Basic usage:
python local_tailwind_extractor.py /path/to/your/project
This will scan all PHP and HTML files in your project directory and create a tailwind_components.txt
file containing all found Tailwind components.
python local_tailwind_extractor.py [project_directory] [options]
Option | Description |
---|---|
project_dir |
Path to the project directory (required) |
--output , -o |
Output file name (default: tailwind_components.txt) |
--execute-php , -e |
Enable PHP execution for dynamic content (disabled by default) |
--php-path , -p |
Path to PHP executable (default: "php") |
--threads , -t |
Number of threads for parallel processing (default: 4) |
--quiet , -q |
Suppress detailed output messages |
Extract with PHP execution enabled:
python local_tailwind_extractor.py /path/to/project --execute-php
Specify output file and increase thread count:
python local_tailwind_extractor.py /path/to/project --output=my_components.txt --threads=8
Use specific PHP executable:
python local_tailwind_extractor.py /path/to/project --execute-php --php-path=/usr/bin/php7.4
The tool generates a text file with categorized Tailwind components:
TAILWIND COMPONENTS FROM project_name
Extraction Date: 2025-03-25 23:47:31 Generated by: guleyc
Files scanned: 347 PHP files found: 286 PHP files executed: 42 HTML files found: 12 Total elements found: 1287 Unique elements: 412 Duplicate elements: 875
BUTTONS (42 elements)
Element #1 from includes/components/buttons.php <button class="px-4 py-2 font-bold text-white bg-blue-500 rounded hover:bg-blue-700"> Click me </button>
The extraction process follows these steps:
File Discovery: Scans project directory for PHP and HTML files
HTML Extraction: Uses static analysis and optional PHP execution
Component Identification: Identifies elements with Tailwind classes
Structural Hashing: Eliminates duplicate components
Smart Categorization: Organizes components by type
Output Generation: Creates a comprehensive reference file
The extractor automatically categorizes components into these groups:
For very large projects, you may want to limit thread count and disable PHP execution:
python local_tailwind_extractor.py /path/to/large/project --threads=2 --output=large_project_components.txt
If you encounter issues with PHP execution, you can check the error output:
python local_tailwind_extractor.py /path/to/project --execute-php --php-path=/path/to/php 2> php_errors.log
This project is licensed under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature
)git commit -m 'Add some amazing feature'
)git push origin feature/amazing-feature
)