Last active
August 2, 2018 17:23
-
-
Save amcdnl/b31b5febc4e64420736c33579a65dfe1 to your computer and use it in GitHub Desktop.
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
FILENAME=$1 | |
react-js-to-ts $FILENAME | |
TS_FILENAME=${FILENAME/\.js/\.tsx} | |
perl -0777 -p -i -e 's/(?<=[^\n]\n)((type|let|var|const|class|function|interface|export( default)?) \w+| (static )?\w+( =|\((\w+|\))))/\n$1/g' $TS_FILENAME | |
perl -0777 -p -i -e 's/(\n \w+) = (?:(?<args>\w+)|\((?<args>\w+(?:, \w+)*)\)|\(\)) => {/$1($+{args}) {/g' $TS_FILENAME | |
perl -0777 -p -i -e "s/import React, { (Pure)?Component(, Fragment)? } from 'react';/import * as React from 'react';/g" $TS_FILENAME | |
perl -0777 -p -i -e 's/extends ((Pure)?Component)/extends React.$1/g' $TS_FILENAME | |
perl -0777 -p -i -e 's/<(\/)?Fragment/<$1React.Fragment/g' $TS_FILENAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment