Last active
September 4, 2020 15:44
-
-
Save beardedtim/149930be21ad1d0c3617b963fda8dce6 to your computer and use it in GitHub Desktop.
Bash Functions for JS Dev
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
is_npm_project() { | |
PACKAGE_LOCK=package-lock.json | |
if test -f "$PACKAGE_LOCK"; then | |
echo "true" | |
else | |
echo "false" | |
fi | |
} | |
install_exact() { | |
if [ $(is_npm_project) = "true" ]; then | |
add_js_dep --save-exact $@ | |
else | |
add_js_dep --exact $@ | |
fi | |
} | |
add_js_dep() { | |
if [ $(is_npm_project) = "true" ]; then | |
npm i $@ | |
else | |
yarn add $@ | |
fi | |
} | |
run_pkg() { | |
if [ $(is_npm_project) = "true" ]; then | |
npx $@ | |
else | |
yarn $@ | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment