import os import glob blocks_dir = "src/blocks" blocks_with_eyebrow = [ "Affiliation", "Eligibility", "FAQTeaser", "FinalCTA", "Process", "ServicesDetailed", "ServicesList", "Stats", "UniqueValue" ] for block in blocks_with_eyebrow: config_path = os.path.join(blocks_dir, block, "config.ts") component_path = os.path.join(blocks_dir, block, "Component.tsx") if os.path.exists(config_path): with open(config_path, "r") as f: content = f.read() if "'eyebrow'" not in content: content = content.replace( "{ name: 'title', type: 'text', required: true, localized: true },", "{ name: 'eyebrow', type: 'text', localized: true },\n { name: 'title', type: 'text', required: true, localized: true }," ) # Handle some variations content = content.replace( "{ name: 'title', type: 'text', localized: true },", "{ name: 'eyebrow', type: 'text', localized: true },\n { name: 'title', type: 'text', localized: true }," ) with open(config_path, "w") as f: f.write(content) if os.path.exists(component_path): with open(component_path, "r") as f: content = f.read() # Add eyebrow to Props destructuring if "eyebrow" not in content: # Add to destructuring, find where title is destructured # E.g. const FAQTeaserBlock: React.FC = ({ title, questions, linkText }) => { # Find the string `({ ` and see if `title` is inside. # Just do a simple regex or string replace. import re content = re.sub(r'({[\s\S]*?title(.*?)\}) =>', r'{ eyebrow, title\2} =>', content, count=1) # Replace the hardcoded string with {eyebrow} # The hardcoded strings are inside
# // Hardcoded #
content = re.sub( r'
\s*//.*?\s*
', r'{eyebrow && (\n
\n // {eyebrow}\n
\n )}', content ) with open(component_path, "w") as f: f.write(content) # Specific fixes for Process and UniqueValue process_config = os.path.join(blocks_dir, "Process", "config.ts") with open(process_config, "r") as f: content = f.read() if "'subtitle'" not in content: content = content.replace( "{ name: 'title', type: 'text', required: true, localized: true },", "{ name: 'title', type: 'text', required: true, localized: true },\n { name: 'subtitle', type: 'textarea', localized: true }," ) with open(process_config, "w") as f: f.write(content) process_component = os.path.join(blocks_dir, "Process", "Component.tsx") with open(process_component, "r") as f: content = f.read() if "subtitle" not in content.split("}) =>")[0] and "ProcessBlock" in content: content = re.sub(r'({.*?eyebrow,\s*title(.*?)\}) =>', r'{ eyebrow, title, subtitle\2} =>', content, count=1) content = re.sub( r'

\s*Prosty.*?\s*

', r'{subtitle && (\n

\n {subtitle}\n

\n )}', content ) with open(process_component, "w") as f: f.write(content) uv_config = os.path.join(blocks_dir, "UniqueValue", "config.ts") with open(uv_config, "r") as f: content = f.read() if "'features'" not in content: content = content.replace( " ],\n}", " {\n name: 'features',\n type: 'array',\n localized: true,\n fields: [\n { name: 'text', type: 'text', required: true },\n ],\n },\n ],\n}" ) with open(uv_config, "w") as f: f.write(content) uv_component = os.path.join(blocks_dir, "UniqueValue", "Component.tsx") with open(uv_component, "r") as f: content = f.read() if "features" not in content.split("}) =>")[0] and "UniqueValueBlock" in content: content = re.sub(r'({.*?eyebrow,\s*title(.*?)\}) =>', r'{ eyebrow, title, features\2} =>', content, count=1) content = re.sub( r'
\s*
\s*\s*Bez barier.*?\s*
\s*
\s*\s*Indywidualne.*?\s*
\s*
', r'''{features && features.length > 0 && (
{features.map((feature: any, index: number) => (
{feature.text}
))}
)}''', content, flags=re.DOTALL ) with open(uv_component, "w") as f: f.write(content)