Last active
January 3, 2019 20:50
-
-
Save Kirill89/982411f5b4e3dd169e78610a34a9960b to your computer and use it in GitHub Desktop.
Convert JavaScript 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
#!/usr/bin/env bash | |
if ! [[ -x "$(command -v lebab)" ]]; then | |
echo 'Error: lebab is not installed.' >&2 | |
echo 'Please run: npm install -g lebab tslint' >&2 | |
exit 1 | |
fi | |
if ! [[ -x "$(command -v tslint)" ]]; then | |
echo 'Error: tslint is not installed.' >&2 | |
echo 'Please run: npm install -g lebab tslint' >&2 | |
exit 1 | |
fi | |
if [[ -z "$1" ]]; then | |
echo 'Usage: ./jsts.sh full/path/to/project relative/path/to/file.js' >&1 | |
exit 0 | |
fi | |
if [[ -z "$2" ]]; then | |
echo 'Usage: ./jsts.sh full/path/to/project relative/path/to/file.js' >&1 | |
exit 0 | |
fi | |
cd "$1" | |
TARGET="$2" | |
TARGET=${TARGET%???} | |
echo "New file is $TARGET.ts" | |
mv "$TARGET.js" "$TARGET.ts" | |
lebab --replace "$TARGET.ts" --transform arrow | |
lebab --replace "$TARGET.ts" --transform no-strict | |
lebab --replace "$TARGET.ts" --transform let | |
lebab --replace "$TARGET.ts" --transform template | |
lebab --replace "$TARGET.ts" --transform commonjs | |
tslint --fix --project . "$TARGET.ts" | |
# Yep, twice. I have no ideas why it works only this way. | |
tslint --fix --project . "$TARGET.ts" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment