| 1 | def update_section_controls(file_path): |
| 2 | start_phrase = "declare class Controls {" |
| 3 | end_phrase = "declare function createControls" |
| 4 | new_start_phrase = "declare class SectionControls {" |
| 5 | |
| 6 | with open(file_path, "r") as file: |
| 7 | lines = file.readlines() |
| 8 | |
| 9 | # Find start and end indices |
| 10 | start_index = end_index = None |
| 11 | for i, line in enumerate(lines): |
| 12 | if start_phrase in line: |
| 13 | start_index = i |
| 14 | elif end_phrase in line and start_index is not None: |
| 15 | end_index = i |
| 16 | break |
| 17 | |
| 18 | # If start and end found, process the block |
| 19 | if start_index is not None and end_index is not None: |
| 20 | # Copy and modify the block |
| 21 | section_controls_block = [new_start_phrase + "\n"] + lines[start_index + 1:end_index] |
| 22 | # Remove the line containing 'section(label: string,' |
| 23 | section_controls_block = [line for line in section_controls_block if 'section(label: string,' not in line] |
| 24 | # Replace the 'type SectionControls' line with the new block |
| 25 | # lines = lines[:start_index] + section_controls_block + lines[end_index + 1:] |
| 26 | # type SectionControls = Omit<Controls, "section">; |
| 27 | # Write the modified content back to the file |
| 28 | |
| 29 | with open(file_path, "r") as file: |
| 30 | x = file.read() |
| 31 | x = x.replace('type SectionControls = Omit<Controls, "section">;', "".join( section_controls_block).strip()) |
| 32 | |
| 33 | with open(file_path, "w") as file: |
| 34 | file.write(x) |
| 35 | |
| 36 | |
| 37 | # Replace 'dist/index.d.ts' with the actual path to your file |