|
| 1 | +import codegen |
1 | 2 | from codegen import Codebase |
2 | 3 | from codegen.sdk.typescript.file import TSFile |
3 | 4 |
|
4 | | -codebase = Codebase("./") |
| 5 | +@codegen.function("remove-default-exports") |
| 6 | +def run(codebase: Codebase): |
| 7 | + """Convert default exports to named exports in TypeScript files. |
5 | 8 |
|
6 | | -for file in codebase.files: |
7 | | - target_file = file.filepath |
8 | | - if not target_file: |
9 | | - print(f"⚠️ Target file not found: {target_file} in codebase") |
10 | | - continue |
| 9 | + This script: |
| 10 | + 1. Identifies shared TypeScript files with default exports. |
| 11 | + 2. Converts default exports to named exports. |
| 12 | + 3. Ensures corresponding non-shared files are updated. |
| 13 | + """ |
| 14 | + for file in codebase.files: |
| 15 | + target_file = file.filepath |
| 16 | + if not target_file: |
| 17 | + print(f"⚠️ Target file not found: {target_file} in codebase") |
| 18 | + continue |
11 | 19 |
|
12 | | - # Get corresponding non-shared file |
13 | | - non_shared_path = file.filepath.replace('/shared/', '/') |
14 | | - if not codebase.has_file(non_shared_path): |
15 | | - print(f"⚠️ No matching non-shared file for: {non_shared_path}") |
16 | | - continue |
| 20 | + # Get corresponding non-shared file |
| 21 | + non_shared_path = file.filepath.replace('/shared/', '/') |
| 22 | + if not codebase.has_file(non_shared_path): |
| 23 | + print(f"⚠️ No matching non-shared file for: {non_shared_path}") |
| 24 | + continue |
17 | 25 |
|
18 | | - non_shared_file = codebase.get_file(non_shared_path) |
19 | | - |
20 | | - # Process individual exports |
21 | | - if isinstance(file, TSFile): |
| 26 | + non_shared_file = codebase.get_file(non_shared_path) |
22 | 27 | print(f"📄 Processing {file.filepath}") |
23 | 28 |
|
24 | | - for export in file.exports: |
25 | | - # Handle default exports |
26 | | - if export.is_reexport() and export.is_default_export(): |
27 | | - print(f" 🔄 Converting default export '{export.name}'") |
28 | | - default_export = next((e for e in non_shared_file.default_exports), None) |
29 | | - if default_export: |
30 | | - default_export.make_non_default() |
| 29 | + # Process individual exports |
| 30 | + if isinstance(file, TSFile): |
| 31 | + for export in file.exports: |
| 32 | + # Handle default exports |
| 33 | + if export.is_reexport() and export.is_default_export(): |
| 34 | + print(f" 🔄 Converting default export '{export.name}'") |
| 35 | + default_export = next((e for e in non_shared_file.default_exports), None) |
| 36 | + if default_export: |
| 37 | + default_export.make_non_default() |
| 38 | + |
| 39 | + print(f"✨ Fixed exports in {file.filepath}") |
31 | 40 |
|
32 | | - print(f"✨ Fixed exports in {file.filepath}") |
| 41 | +if __name__ == "__main__": |
| 42 | + codebase = Codebase("./") |
| 43 | + run(codebase) |
0 commit comments