Files
thermcool/find_buttons.py
T

44 lines
1.6 KiB
Python

import os
import re
from collections import Counter
dirs_to_search = ['app', 'components']
button_classes = []
class_regex = re.compile(r'className=["\']([^"\']+)["\']')
dynamic_class_regex = re.compile(r'className=\{`([^`]+)`\}')
for d in dirs_to_search:
for root, _, files in os.walk(d):
for file in files:
if file.endswith(('.tsx', '.jsx', '.ts', '.js')):
filepath = os.path.join(root, file)
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
# Find all classNames
matches = class_regex.findall(content) + dynamic_class_regex.findall(content)
for m in matches:
# Check if it looks like a button
if 'btn' in m or ('px-' in m and 'py-' in m and 'rounded' in m):
# Normalize spacing
normalized = ' '.join(m.split())
button_classes.append((normalized, filepath))
# Count frequencies
counts = Counter([c[0] for c in button_classes])
most_common = counts.most_common(10)
print("Top variants:")
for variant, count in most_common:
print(f"\nVariant ({count} times): {variant}")
# Find up to 3 files where it appears
files_seen = set()
for c, fpath in button_classes:
if c == variant and fpath not in files_seen:
files_seen.add(fpath)
print(f" - {fpath}")
if len(files_seen) >= 3:
break