Created
January 17, 2023 12:42
-
-
Save pwndev/8d163e0ec94b13b53c4d54a432cc3682 to your computer and use it in GitHub Desktop.
Simple script to rename React .js files that render jsx to .jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
root_dir = "src" | |
JSX_REGEX = r"<\w+" | |
for dirpath, dirnames, filenames in os.walk(root_dir): | |
for filename in filenames: | |
if filename.endswith(".js"): | |
filepath = os.path.join(dirpath, filename) | |
with open(filepath, "r") as f: | |
file_contents = f.read() | |
if re.search(JSX_REGEX, file_contents): | |
new_filename = filename.replace(".js", ".jsx") | |
new_filepath = os.path.join(dirpath, new_filename) | |
os.rename(filepath, new_filepath) | |
print(f'{filename} has been renamed to {new_filename}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment