Last active
December 14, 2019 08:49
-
-
Save mickdekkers/026ce307d485b9587a51073308ae6bdf to your computer and use it in GitHub Desktop.
ts-add bash function: yarn add with typescript types in a single command
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 | |
# Add this function to your .bashrc/.zshrc | |
function ts-add () { | |
if [ "$1" = "--dev" ] || [ "$1" = "-D" ]; then | |
dev=true | |
shift | |
fi | |
packages=("$@") | |
types=() | |
for p in "${packages[@]}"; do | |
types+=("@types/$p") | |
done | |
echo "Adding ${#packages[@]} $(if [ "$dev" = true ]; then echo "dev "; fi)package(s):" | |
echo "${packages[@]}" | |
echo "with types:" | |
echo "${types[@]}" | |
echo | |
if [ "$dev" = true ]; then | |
yarn add --dev "${packages[@]}" || exit $? | |
else | |
yarn add "${packages[@]}" || exit $? | |
fi | |
yarn add --dev "${types[@]}" | |
} | |
ts-add "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment