find . -type f \( -name "*.js" -and -not -name "*.styles.js" -and -not -name "index.js" -and -not -name "*.test.js" \) -exec sh -c 'mv "$1" "${1%.js}.tsx"' _ {} ;
find . -type f \( -name "*.js" -and -not -name "*.test.js" \) -exec sh -c 'mv "$1" "${1%.js}.ts"' _ {} ;
find . -type f \( -name "*.js" \) -exec grep -l "import React" {} ; -exec sh -c 'mv "$1" "${1%.js}.tsx"' _ {} ;
find . -type f \( -name "*.js" \) -exec grep -l "import \* as React" {} ; -exec sh -c 'mv "$1" "${1%.js}.tsx"' _ {} ;
If you used Flow you can covert flow files to typescript with the help of flow2ts library: https://github.com/bcherny/flow-to-typescript To convert files that use flow issue following command:
- At first rename all js files that cointains @flow pragma to
flow
extensionfind . -type f \( -name "*.js" \) -exec grep -l "\@flow" {} ; -exec sh -c 'mv "$1" "${1%.js}.flw"' _ {} ;
- Now convert all flow files to typescript:
find . -type f \( -name "*.flow" \) -exec sh -c 'flow2ts "$1" "$1".tsx' _ {} ;
Note: All commands were tested on windows, for linux users you should probably use \;
insted of ;
at the end of all commands