Last active
June 27, 2024 13:39
-
-
Save polaroidkidd/e7c5dda36f477de0d8fe7a7160d6ebe1 to your computer and use it in GitHub Desktop.
Helper scripts for wiping yarn, npm & pnpm node_modules and reinstalling
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
# Function to delete node_modules directory, clean package | |
# manager's global cache and install dependencies based on lock file | |
# Usage: __nodeWipeInstall | |
function __nodeWipeInstall(){ | |
RED=`tput setaf 1` | |
GREEN=`tput setaf 2` | |
RESET=`tput sgr0` | |
BOLD=$(tput bold) | |
echo -e "${BOLD}${GREEN}*************** DELETING NODE_MODULES *******************${RESET}" | |
find . -name "node_modules" -type d -prune -print -exec rm -rf "{}" \; | |
wait | |
if [[ -f "${PWD}/package-lock.json" ]]; then | |
echo -e "${BOLD}${GREEN}*********************************************************${RESET}" | |
echo -e "${BOLD}${GREEN}************** clearning global npm cache' **************${RESET}" | |
echo -e "${BOLD}${GREEN}*********************************************************${RESET}" | |
npm cache clean --force | |
echo -e "${BOLD}${GREEN}*********************************************************${RESET}" | |
echo -e "${BOLD}${GREEN}*************** installing using 'npm ci' ***************${RESET}" | |
echo -e "${BOLD}${GREEN}*********************************************************${RESET}" | |
npm ci | |
elif [[ -f "${PWD}/yarn.lock" ]]; then | |
echo -e "${BOLD}${GREEN}*********************************************************${RESET}" | |
echo -e "${BOLD}${GREEN}************* clearning global yarn cache' **************${RESET}" | |
echo -e "${BOLD}${GREEN}*********************************************************${RESET}" | |
yarn cache clean | |
echo -e "${BOLD}${GREEN}*********************************************************${RESET}" | |
echo -e "${BOLD}${GREEN}*** installing using 'yarn install --frozen-lockfile' ***${RESET}" | |
echo -e "${BOLD}${GREEN}*********************************************************${RESET}" | |
yarn install --frozen-lockfile | |
elif [[ -f "${PWD}/pnpm-lock.yaml" ]]; then | |
echo -e "${BOLD}${GREEN}*********************************************************${RESET}" | |
echo -e "${BOLD}${GREEN}************* clearning global pnpm cache' **************${RESET}" | |
echo -e "${BOLD}${GREEN}*********************************************************${RESET}" | |
pnpm store prune | |
echo -e "${BOLD}${GREEN}*********************************************************${RESET}" | |
echo -e "${BOLD}${GREEN}*** installing using 'pnpm install --frozen-lockfile' ***${RESET}" | |
echo -e "${BOLD}${GREEN}*********************************************************${RESET}" | |
pnpm i --frozen-lockfile | |
else | |
echo -e "${BOLD}${RED}***********************************************************${RESET}" | |
echo -e "${BOLD}${RED}****************** no lock file found *********************${RESET}" | |
echo -e "${BOLD}${RED}*********** please run pnpm/npm/yarn install **************${RESET}" | |
echo -e "${BOLD}${RED}***********************************************************${RESET}" | |
fi | |
} | |
# Function to delete node_modules directory and install dependencies based on lock file | |
# Usage: __nodeWipeInstall | |
function __nodeWipeInstall(){ | |
RED=`tput setaf 1` | |
GREEN=`tput setaf 2` | |
BLUE=`tput setaf 5` | |
RESET=`tput sgr0` | |
BOLD=$(tput bold) | |
echo -e "${BOLD}${GREEN}*************** DELETING NODE_MODULES *******************${RESET}" | |
find . -name "node_modules" -type d -prune -print -exec rm -rf "{}" \; | |
wait | |
if [[ -f "${PWD}/package-lock.json" ]]; then | |
echo -e "${BOLD}${GREEN}*********************************************************${RESET}" | |
echo -e "${BOLD}${GREEN}*************** installing using 'npm ci' ***************${RESET}" | |
echo -e "${BOLD}${GREEN}*********************************************************${RESET}" | |
npm ci | |
elif [[ -f "${PWD}/yarn.lock" ]]; then | |
echo -e "${BOLD}${GREEN}*********************************************************${RESET}" | |
echo -e "${BOLD}${GREEN}*** installing using 'yarn install --frozen-lockfile' ***${RESET}" | |
echo -e "${BOLD}${GREEN}*********************************************************${RESET}" | |
yarn install --frozen-lockfile | |
elif [[ -f "${PWD}/pnpm-lock.yaml" ]]; then | |
echo -e "${BOLD}${GREEN}*********************************************************${RESET}" | |
echo -e "${BOLD}${GREEN}*** installing using 'pnpm install --frozen-lockfile' ***${RESET}" | |
echo -e "${BOLD}${GREEN}*********************************************************${RESET}" | |
pnpm i --frozen-lockfile | |
else | |
echo -e "${BOLD}${RED}***********************************************************${RESET}" | |
echo -e "${BOLD}${RED}****************** no lock file found *********************${RESET}" | |
echo -e "${BOLD}${RED}*********** please run pnpm/npm/yarn install **************${RESET}" | |
echo -e "${BOLD}${RED}***********************************************************${RESET}" | |
fi | |
} | |
alias nci="__nodeCleanInstall" | |
alias nwi="__nodeWipeInstall" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment