Skip to content

Instantly share code, notes, and snippets.

@amcdnl
Last active August 2, 2018 17:23
Show Gist options
  • Save amcdnl/b31b5febc4e64420736c33579a65dfe1 to your computer and use it in GitHub Desktop.
Save amcdnl/b31b5febc4e64420736c33579a65dfe1 to your computer and use it in GitHub Desktop.
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