Skip to content

Commit 3d5b501

Browse files
codegen-botkopekC
authored andcommitted
update git ignore
Add remove_default_exports directory and contents Remove accidentally added submodule . setup input repo adds README.md adds README.md
1 parent dee4c5f commit 3d5b501

File tree

23 files changed

+223
-0
lines changed

23 files changed

+223
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,9 @@ cython_debug/
169169

170170
# PyPI configuration file
171171
.pypirc
172+
/.idea/vcs.xml
173+
/.idea/codegen-examples.iml
174+
/.idea/misc.xml
175+
/.idea/modules.xml
176+
/.idea/inspectionProfiles/profiles_settings.xml
177+
/.idea/inspectionProfiles/Project_Default.xml

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ By contributing to Codegen Examples, you agree that:
1818
4. Submit a pull request to the `main` branch.
1919
5. Include a clear description of your changes in the PR.
2020

21+

remove_default_exports/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Remove Default Exports in TypeScript
2+
3+
This codemod demonstrates how to automatically convert default exports to named exports in your TypeScript codebase. The migration script makes this process simple by handling all the tedious manual updates automatically.
4+
5+
## How the Migration Script Works
6+
7+
The script automates the entire migration process in a few key steps:
8+
9+
1. **File Detection and Analysis**
10+
```python
11+
codebase = Codebase("./")
12+
for file in codebase.files:
13+
if "/shared/" not in file.filepath:
14+
continue
15+
```
16+
- Automatically identifies shared TypeScript files
17+
- Analyzes export structures
18+
- Determines necessary export modifications
19+
20+
2. **Export Conversion**
21+
```python
22+
for export in file.exports:
23+
if export.is_default_export():
24+
export.make_non_default()
25+
```
26+
- Converts default exports to named exports
27+
- Ensures corresponding non-shared files are updated
28+
- Preserves existing export configurations
29+
30+
## Common Migration Patterns
31+
32+
### Default Export Conversion
33+
```typescript
34+
// Before
35+
export default function myFunction() {}
36+
37+
// After
38+
export function myFunction() {}
39+
```
40+
41+
### Re-export Conversion
42+
```typescript
43+
// Before
44+
export { default } from './module';
45+
46+
// After
47+
export { myFunction } from './module';
48+
```
49+
50+
## Running the Migration
51+
52+
```bash
53+
# Install Codegen
54+
pip install codegen
55+
# Run the migration
56+
python run.py
57+
```
58+
59+
## Learn More
60+
61+
- [TypeScript Documentation](https://www.typescriptlang.org/docs/)
62+
- [Codegen Documentation](https://docs.codegen.com)
63+
64+
## Contributing
65+
66+
Feel free to submit issues and enhancement requests!
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "default-exports-test",
3+
"version": "1.0.0",
4+
"description": "Test codebase for converting default exports",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"devDependencies": {
13+
"typescript": "^5.0.0"
14+
}
15+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Original file keeps default export
2+
export default class Authenticator {
3+
authenticate(token: string): boolean {
4+
return token.length > 0;
5+
}
6+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Should be converted to named export
2+
export { default } from '../services/authenticator';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Should be converted to named export
2+
export { default as generateToken } from '../utils/token-generator';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Original file keeps default export
2+
export default function generateToken(): string {
3+
return Math.random().toString(36);
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Original file keeps default export
2+
export default interface Comment {
3+
id: string;
4+
postId: string;
5+
text: string;
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Original file keeps default export
2+
import Comment from '../models/comment';
3+
4+
export default class CommentService {
5+
getComment(id: string): Comment {
6+
return { id, postId: '123', text: 'Great post!' };
7+
}
8+
}

0 commit comments

Comments
 (0)