A CLI tool to extract hex colors from Tailwind CSS projects and convert them to CSS variables.
[!IMPORTANT] This tool is not published on npm yet!
npm install -g tailwind-swooosh
# or
pnpm add -g tailwind-swooosh
tailwind-swooosh [options] [folder-path]
-e
, --extract
[folder-path] - Extract colors from files and generate a report-r
, --replace
[folder-path] - Replace hex colors with CSS variables-d
, --dry-run
- Show what would be changed without making actual changes (with --replace
)-t=
, --target=
- Targetted rules (by default: color
)-h
, --help
- Show help informationIf no folder path is provided, the current directory will be used.
# Show help
tailwind-swooosh
# Extract colors from current directory
tailwind-swooosh -e
# Extract colors from specified directory
tailwind-swooosh -e ./my-project
# Replace colors with variables in specified directory
tailwind-swooosh -r ./my-project
# Preview replacements without making changes
tailwind-swooosh -r -d ./my-project
# Preview colors replacements without making changes
tailwind-swooosh -r -d -t=color ./my-project
When using the extract mode (-e
), the tool will detect any tailwind classes based on hex
color (ie: bg-[#xxxxxx]
, text-[#xxxxxx]
, border-[#xxxxxx]
, etc...) and will generate a file called tailwind-swooosh-extract.txt
in the current directory with:
hex
colors found in your projecthex
and oklch
formats[!NOTE] The current version only extract
hex
colors rules frombg|text|border|ring|shadow|outline
tailwind classes.
Tailwind Swooosh extract results for target(s): color
__________________________________________________________________________________________________
Color extract:
#171b26 → used 28 times (20.44%) → suggested: --color-coarse-wool
Found in:
- src/components/footer.tsx
- src/components/ui/dialog.tsx
- ...
#ffce67 → used 18 times (13.14%) → suggested: --color-chickadee
Found in:
- src/components/footer.tsx
- src/components/ui/button.tsx
- ...
...
Color variables (hex format):
--color-coarse-wool: #171b26;
--color-chickadee: #ffce67;
_______________________________
...
Color variables (oklch optimized format):
--color-coarse-wool: oklch(38.84, 13.40, -1.78); /* #171b26 */
--color-chickadee: oklch(92.56, 29.81, 1.87); /* #ffce67 */
...
[!CAUTION] Please be sure to commit every change before running the replace mode. The replace mode is destructive and may overwrite your files.
When using the replace mode (-r
), the tool will scan your project files and replace Tailwind hex color classes with CSS variable classes. This helps maintain consistency and makes it easier to update your color scheme.
[!NOTE] The current version only replaces hex colors with CSS variables.
CSS variables detected must used
oklch
orhex
format (or reference anotheroklch
orhex
variable).The current version also avoids variables inside
.dark { ... }
blocks.
Use the -d or --dry-run option with replace mode to preview what changes would be made without actually modifying any files. This is useful for checking the impact of replacements before applying them:
tailwind-swooosh -r -d .
The output will show:
MIT