Last active
November 3, 2018 01:16
-
-
Save jeffreypriebe/dc278b6ac79c721c0034fe8c193b36f4 to your computer and use it in GitHub Desktop.
Convert from flow to Typescript
This file contains hidden or 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
Show hidden characters
# note: this does not convert anything with jsx - if you use the babel plugin for jsx it works, but rewrites it to react.createElement stuff | |
{ | |
"presets": [], | |
"plugins": [ | |
"flow-to-typescript" | |
] | |
} |
This file contains hidden or 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
# expecting be run with that package.json configured and the .babelrc | |
typeit() { | |
ts=${1%.js} | |
if [ ! -z $2 ]; then | |
echo "copying" | |
nf=$ts.tsx | |
cp $1 $nf | |
else | |
echo "babel" | |
nf=$ts.ts | |
./node_modules/.bin/babel $1 -o $nf | |
fi | |
sed -i '' 's/React\.Node/React\.ReactNode/g' $nf | |
sed -i '' 's/\/\/ @flow//g' $nf | |
sed -i '' 's/\<\*\>/\<T\>/g' $nf | |
sed -i '' 's/import type/import/g' $nf | |
sed -i '' 's/: \?/\?: /g' $nf | |
sed -i '' 's/: any\\)/ as any\\)/g' $nf | |
} |
This file contains hidden or 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
{ | |
"name": "shared", | |
"version": "0.1.0", | |
"private": true, | |
"dependencies": { | |
"@babel/cli": "^7.0.0", | |
"@babel/core": "^7.0.0", | |
"@babel/plugin-proposal-class-properties": "^7.1.0", | |
"@babel/plugin-proposal-object-rest-spread": "^7.0.0", | |
"@babel/preset-env": "^7.1.0", | |
"@babel/preset-es2015": "^7.0.0-beta.53", | |
"@babel/preset-flow": "^7.0.0", | |
"@babel/preset-react": "^7.0.0", | |
"@types/reach__router": "^1.2.1", | |
"@types/react": "^16.4.18", | |
"@types/react-dom": "^16.0.9", | |
"@types/react-relay": "^1.3.9", | |
"@types/relay-runtime": "^1.3.6", | |
"babel-plugin-flow-to-typescript": "^0.2.0", | |
"classnames": "^2.2.6", | |
"react": "^16.6.0", | |
"react-bulma-components": "^2.2.0", | |
"react-dom": "^16.4.2", | |
"react-scripts": "^2.1.1", | |
"typescript": "^3.1.6" | |
}, | |
"scripts": { | |
"start": "react-scripts start", | |
"build": "react-scripts build", | |
"test": "react-scripts test --env=jsdom", | |
"eject": "react-scripts eject", | |
"storybook": "start-storybook -p 9009 -s public", | |
"build-storybook": "build-storybook -s public", | |
"copy-watch": "watchman -j < copy_shared_watch.json", | |
"stop-copy-watch": "watchman trigger-del . watch-web-shared" | |
}, | |
"devDependencies": { | |
"@types/node": "^10.12.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment