66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
import os
|
|
import re
|
|
|
|
TARGET_DIR = "resources/js"
|
|
|
|
REPLACEMENTS = {
|
|
'bg-slate-950': 'bg-slate-50',
|
|
'bg-slate-900': 'bg-white',
|
|
'bg-slate-800': 'bg-slate-100',
|
|
'border-slate-800': 'border-slate-200',
|
|
'border-slate-700': 'border-slate-300',
|
|
'text-slate-400': 'text-slate-500',
|
|
'text-slate-300': 'text-slate-600',
|
|
'bg-slate-700': 'bg-slate-200',
|
|
}
|
|
|
|
PROTECTED_BACKGROUNDS = [
|
|
'bg-blue-', 'from-blue-', 'to-blue-',
|
|
'bg-red-', 'bg-emerald-', 'bg-amber-',
|
|
'bg-black', 'bg-slate-500'
|
|
]
|
|
|
|
def main():
|
|
count = 0
|
|
for root, dirs, files in os.walk(TARGET_DIR):
|
|
for file in files:
|
|
if file.endswith('.tsx') or file.endswith('.ts'):
|
|
filepath = os.path.join(root, file)
|
|
|
|
with open(filepath, 'r') as f:
|
|
content = f.read()
|
|
|
|
original_content = content
|
|
|
|
# Apply direct string replacements
|
|
for dark, light in REPLACEMENTS.items():
|
|
content = content.replace(dark, light)
|
|
|
|
# Apply text-white specifically, shielding rows with strong explicit backgrounds
|
|
lines = content.split('\n')
|
|
new_lines = []
|
|
for line in lines:
|
|
if 'text-white' in line:
|
|
if any(bg in line for bg in PROTECTED_BACKGROUNDS):
|
|
# Skip this line to protect button text
|
|
new_lines.append(line)
|
|
else:
|
|
# Verify if there is a multi-line format where text-white is isolated.
|
|
# If so, just swap it.
|
|
new_lines.append(line.replace('text-white', 'text-slate-900'))
|
|
else:
|
|
new_lines.append(line)
|
|
|
|
content = '\n'.join(new_lines)
|
|
|
|
if original_content != content:
|
|
with open(filepath, 'w') as f:
|
|
f.write(content)
|
|
print(f"Updated {filepath}")
|
|
count += 1
|
|
|
|
print(f"\nMigration complete. Modifed {count} files.")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|