Last active
February 28, 2020 00:45
-
-
Save IkeyBenz/2047d9d1140b7ca9ff55c9bbf4488eea to your computer and use it in GitHub Desktop.
Convert all files in react directory from javascript to typescript
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
from os import listdir, system | |
from os.path import isdir, join | |
# Source: react-js-to-ts - https://www.npmjs.com/package/react-js-to-ts | |
# Source: js-to-ts-converter - https://www.npmjs.com/package/js-to-ts-converter | |
def get_filepaths(folder_path): | |
filepaths = [] | |
for filepath in listdir(folder_path): | |
complete_path = join(folder_path, filepath) | |
if isdir(complete_path): | |
filepaths.extend(get_filepaths(complete_path)) | |
else: | |
filepaths.append(complete_path) | |
return filepaths | |
def run_react_js_to_ts_conversion_on(folder_path): | |
''' | |
Uses react-js-to-ts npm package to convert all files in a directory from js to tsx. | |
NOTE: react-js-to-ts must be installed globally. `npm i -g react-js-to-ts` | |
''' | |
filepaths = get_filepaths(folder_path) | |
for filepath in filepaths: | |
print(f'converting {filepath} to typescript') | |
system(f'react-js-to-ts {filepath}') | |
if __name__ == '__main__': | |
run_react_js_to_ts_conversion_on('./src/screens') | |
run_react_js_to_ts_conversion_on('./src/components') | |
system('npx js-to-ts-converter ./src/*') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment