Fixes for Node aliases

This commit is contained in:
Alicia Sykes 2024-07-22 14:36:39 +01:00
parent cbb3feb4bd
commit 00a1be6545

View File

@ -1,5 +1,3 @@
###################################################################### ######################################################################
# ZSH aliases and helper functions for Node.js / web development # # ZSH aliases and helper functions for Node.js / web development #
# Includes aliases for yarn, npn, nvm, npx, node, react, etc # # Includes aliases for yarn, npn, nvm, npx, node, react, etc #
@ -53,11 +51,11 @@ alias nvmlatest='nvm install node --latest-npm && nvm use node'
alias nvmsetup='install_nvm' alias nvmsetup='install_nvm'
# Special Node commands # Special Node commands
alias npmscripts='cat package.json | jq .scripts' # Print availible scripts for the current project alias npmscripts='cat package.json | jq .scripts' # Print available scripts for the current project
alias docker-node='docker run -it --rm -v "$(pwd)":/usr/src/app -w /usr/src/app node' # Run Node using Docker alias docker-node='docker run -it --rm -v "$(pwd)":/usr/src/app -w /usr/src/app node' # Run Node using Docker
alias nodesize='du -sh node_modules' # Print size of node_modules folder alias nodesize='du -sh node_modules' # Print size of node_modules folder
# Shortcuts for helpfer functions defined below # Shortcuts for helper functions defined below
alias yv='print_node_versions' # Print versions of Node.js and related packages alias yv='print_node_versions' # Print versions of Node.js and related packages
alias yarn-nuke='reinstall_modules' # Fully remove and reinstall node_modules alias yarn-nuke='reinstall_modules' # Fully remove and reinstall node_modules
alias repo='open_repo' # Opens the current remote Git repository in the browser alias repo='open_repo' # Opens the current remote Git repository in the browser
@ -82,7 +80,7 @@ reinstall_modules () {
# Check file exists, remove it and print message # Check file exists, remove it and print message
check-and-remove() { check-and-remove() {
if [ -d "$project_dir/$1" ]; then if [ -d "$project_dir/$1" ]; then
echo -e "\e[35mRemoveing $1...\e[0m" echo -e "\e[35mRemoving $1...\e[0m"
rm -rf "$project_dir/$1" rm -rf "$project_dir/$1"
fi fi
} }
@ -100,7 +98,7 @@ reinstall_modules () {
echo -e "\e[35mReinstalling with NPM...\e[0m" echo -e "\e[35mReinstalling with NPM...\e[0m"
npm install npm install
else else
echo -e "🚫\033[0;91m Unable to proceed, yarn/ npm not installed\e[0m" echo -e "🚫\033[0;91m Unable to proceed, yarn/npm not installed\e[0m"
fi fi
else else
# Cancelled by user # Cancelled by user
@ -141,12 +139,12 @@ print_node_versions () {
} }
# Location of NVM, will inherit from .zshenv if set # Location of NVM, will inherit from .zshenv if set
NVM_DIR=${NVM_DIR:-$XDG_DATA_HOME/nvm} NVM_DIR=${NVM_DIR:-$HOME/.nvm}
# On first time using Node command, import NVM if present and not yet sourced # On first time using Node command, import NVM if present and not yet sourced
function source_nvm node npm yarn $NVM_LAZY_CMD { function source_nvm node npm yarn $NVM_LAZY_CMD {
if [ -f "$NVM_DIR/nvm.sh" ] && ! which nvm &> /dev/null; then if [ -f "$NVM_DIR/nvm.sh" ] && ! which nvm &> /dev/null; then
echo -e "\033[1;93mInitialising NVM...\033[0m" echo -e "\033[1;93mInitializing NVM...\033[0m"
source "${NVM_DIR}/nvm.sh" source "${NVM_DIR}/nvm.sh"
nvm use default nvm use default
fi fi
@ -180,11 +178,11 @@ install_nvm () {
nvm_repo='https://github.com/nvm-sh/nvm.git' nvm_repo='https://github.com/nvm-sh/nvm.git'
if [ -d "$NVM_DIR" ]; then # Already installed, update if [ -d "$NVM_DIR" ]; then # Already installed, update
cd $NVM_DIR && git pull cd $NVM_DIR && git pull
else # Not yet installed, promt user to confirm before proceeding else # Not yet installed, prompt user to confirm before proceeding
if read -q "choice?Install NVM now? (y/N)"; then if read -q "choice?Install NVM now? (y/N)"; then
echo -e "\nInstalling..." echo -e "\nInstalling..."
git clone $nvm_repo $NVM_DIR git clone $nvm_repo $NVM_DIR
cd $NVM_DIR && git checkout v0.39.1 cd $NVM_DIR && git checkout v0.39.3
else else
echo -e "\nAborting..." echo -e "\nAborting..."
return return
@ -193,7 +191,7 @@ install_nvm () {
# All done, import / re-import NVM script # All done, import / re-import NVM script
source "${NVM_DIR}/nvm.sh" source "${NVM_DIR}/nvm.sh"
# Then install Node LTS # Then install Node LTS
nvm install v16.16.0 nvm install --lts
} }
# Helper function that gets supported open method for system # Helper function that gets supported open method for system