Skip to content

Instantly share code, notes, and snippets.

@beardedtim
Last active September 4, 2020 15:44
Show Gist options
  • Save beardedtim/149930be21ad1d0c3617b963fda8dce6 to your computer and use it in GitHub Desktop.
Save beardedtim/149930be21ad1d0c3617b963fda8dce6 to your computer and use it in GitHub Desktop.
Bash Functions for JS Dev
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