Files
Mana-Loop/fix_remaining.py
T
n8n-gitea 482320b519
Build and Publish Mana Loop Docker Image / build-and-publish (push) Failing after 1m12s
fix: apply DebugName wrappers to tab components (BUG 7 partial) and other updates
2026-05-07 13:32:04 +02:00

135 lines
4.6 KiB
Python

#!/usr/bin/env python3
import re
def add_debugname_wrapper(file_path, component_name):
"""Add DebugName import and wrap the main return with DebugName"""
print(f"Processing {file_path} for {component_name}...")
with open(file_path, 'r') as f:
content = f.read()
# Check if DebugName is already imported
if 'from \'@/lib/game/debug-context\'' in content or 'from "@/lib/game/debug-context"' in content:
print(f" - DebugName already imported")
else:
# Find the last import line and add the DebugName import after it
lines = content.split('\n')
last_import_idx = -1
for i, line in enumerate(lines):
if line.startswith('import ') or 'import {' in line:
last_import_idx = i
if last_import_idx >= 0:
lines.insert(last_import_idx + 1, "import { DebugName } from '@/lib/game/debug-context';")
content = '\n'.join(lines)
print(f" - Added DebugName import")
else:
print(f" - WARNING: No import found")
return False
# Now find the main return statement and wrap it
# The return statement should be: return ( \n <something>
# We need to wrap the entire JSX returned
# Find where the return statement starts
# Look for "return (" followed by newline
return_pattern = r'(return\s*\(\s*\n)'
match = re.search(return_pattern, content)
if not match:
print(f" - WARNING: Could not find return pattern")
return False
# Find the matching closing parenthesis for the return
# We need to count parentheses to find the correct closing one
start_pos = match.end()
# Insert <DebugName name="..."> after the return (
before_return = content[:match.end()]
after_return = content[match.end():]
# Add opening DebugName tag with proper indentation
# Find the indentation of the first line after return
lines_after = after_return.split('\n')
first_line_indent = ''
for char in lines_after[0]:
if char == ' ':
first_line_indent += ' '
else:
break
# Add the opening tag
opening_tag = f"{first_line_indent}<DebugName name=\"{component_name}\">\n"
modified = before_return + opening_tag + after_return
# Now find the closing ); for the return statement and add </DebugName> before it
# We need to find the matching closing paren for return (
# Let's find the position of the return (
return_start = modified.find('return (')
if return_start == -1:
print(f" - WARNING: Could not find 'return ('")
return False
# Find matching closing paren
paren_count = 0
in_string = False
string_char = None
i = return_start + len('return (')
while i < len(modified):
char = modified[i]
if in_string:
if char == string_char and modified[i-1] != '\\':
in_string = False
i += 1
continue
if char == '"' or char == "'":
in_string = True
string_char = char
elif char == '(':
paren_count += 1
elif char == ')':
if paren_count == 0:
# This is the matching closing paren
# Check if followed by ;
if i + 1 < len(modified) and modified[i+1] == ';':
# Insert </DebugName> before this )
before_close = modified[:i]
after_close = modified[i:]
# Get indentation
lines_before = before_close.split('\n')
last_line = lines_before[-1]
indent = ''
for char in last_line:
if char == ' ':
indent += ' '
else:
break
closing_tag = f"\n{indent}</DebugName>"
modified = before_close + closing_tag + after_close
print(f" - Successfully wrapped {component_name} with DebugName")
break
else:
# Just a normal paren
pass
else:
paren_count -= 1
i += 1
# Write back
with open(file_path, 'w') as f:
f.write(modified)
return True
# Fix CraftingTab and EquipmentTab
add_debugname_wrapper('src/components/game/tabs/CraftingTab.tsx', 'CraftingTab')
add_debugname_wrapper('src/components/game/tabs/EquipmentTab.tsx', 'EquipmentTab')
print("\nDone with tabs!")