Skip to content

Instantly share code, notes, and snippets.

@mickdekkers
Last active December 14, 2019 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mickdekkers/026ce307d485b9587a51073308ae6bdf to your computer and use it in GitHub Desktop.
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
#!/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