Last active
September 5, 2018 14:51
-
-
Save jtmthf/2b9e5e935581e1722461b524c4234067 to your computer and use it in GitHub Desktop.
This file contains 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
# 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