Skip to content

Instantly share code, notes, and snippets.

@jtmthf
Last active September 5, 2018 14:51
Show Gist options
  • Save jtmthf/2b9e5e935581e1722461b524c4234067 to your computer and use it in GitHub Desktop.
Save jtmthf/2b9e5e935581e1722461b524c4234067 to your computer and use it in GitHub Desktop.
# Add to your .bashrc or .zshrc
# Use like 'yat react'
# Will install the package and its typings if needed
# requires jq to be installed
# for yarn (yarn add w/ types)
function yat() {
yarn add $1
if ! cat node_modules/$1/package.json | jq -e 'select((.types != null) or .typings != null)' > /dev/null;
then
if [[ $1 == @* ]]
then
TYPE_NAME=$(echo $1 | sed 's/^@//' | sed 's/\//__/')
else
TYPE_NAME=$1
fi
yarn add -D @types/$TYPE_NAME
fi
}
# for npm (npm install w/ types)
function nit() {
npm i $1
if ! cat node_modules/$1/package.json | jq -e 'select((.types != null) or .typings != null)' > /dev/null;
then
if [[ $1 == @* ]]
then
TYPE_NAME=$(echo $1 | sed 's/^@//' | sed 's/\//__/')
else
TYPE_NAME=$1
fi
yarn i -D @types/$TYPE_NAME
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment