Skip to content
Snippets Groups Projects
Commit 00858802 authored by Brandon Rodriguez's avatar Brandon Rodriguez
Browse files

Add npm setup script

parent 66596198
Branches
No related merge requests found
...@@ -65,6 +65,15 @@ function main () { ...@@ -65,6 +65,15 @@ function main () {
echo -e "${text_blue}This may ask for your system password.${text_reset}" echo -e "${text_blue}This may ask for your system password.${text_reset}"
get_user_confirmation "${text_blue}This will also trigger a general system update. Is this okay?${text_reset}" get_user_confirmation "${text_blue}This will also trigger a general system update. Is this okay?${text_reset}"
if [[ ${return_value} == true ]]
then
sudo ./setup_npm.sh
else
echo ""
echo -e "${text_blue}Cancelling Npm/NodeJs setup."
echo ""
fi
elif [[ "${user_input}" == "0" ]] elif [[ "${user_input}" == "0" ]]
then then
# Exit program. # Exit program.
...@@ -76,6 +85,7 @@ function main () { ...@@ -76,6 +85,7 @@ function main () {
# Handle unrecognized input. # Handle unrecognized input.
echo "" echo ""
echo -e "${text_red}Unrecognized selection.${text_reset}" echo -e "${text_red}Unrecognized selection.${text_reset}"
echo ""
fi fi
......
#!/usr/bin/env bash
###
# Fully install + update npm.
# Because the commands are annoying to remember if you don't use them regularly.
# Also as of 2020/2021-ish, it seems like certain machine/installation setups are
# buggy to update without this exact command ordering.
##
# Abort on error
set -e
# Import utility script.
source $(dirname $0)/utils.sh
###
# Program main.
##
function main () {
echo ""
echo -e "${text_blue}Installing/updating Npm & NodeJs.${text_reset}"
echo -e "${text_blue}This will make sure your system has the latest LTS version.${text_reset}"
echo -e "${text_blue}This may take a few minutes, depending on your system and connection...${text_reset}"
echo ""
# Make sure we are root.
check_is_user "root"
# Install base node/npm packages.
curl -fsSL https://deb.nodesource.com/setup_lts.x -y > /dev/null 2>&1 | sudo -E bash -
apt-get update -y > /dev/null 2>&1
apt-get upgrade -y > /dev/null 2>&1
apt-get install nodejs -y > /dev/null 2>&1
apt-get install npm -y > /dev/null 2>&1
# Note that at this point, depending on the system, this might provide an old/outdated version.
# So it's installed, but we have to do additional commands to get the proper latest version.
# Basically, we want to use npm's built-in version manager. So as long as we get ANY version of
# npm, then we can get to the proper version with said built-in version manager.
# Install NodeJs "version manager".
npm install -g n > /dev/null 2>&1
# Verify we have the latest stable major version of npm.
n stable > /dev/null 2>&1
# Try again to update to latest version of npm.
# This is usually unecessary, but required in some systems with certain configurations,
# Otherwise, it doesn't seem to *actually* get to the proper version until running commands again.
# Aka, this is a workaround for an obscure update bug in some systems.
npm install -g npm@latest > /dev/null 2>&1
# Install update checker for npm.
npm install -g npm-check-updates > /dev/null 2>&1
echo -e "${text_blue}NodeJs, Npm, and React dependencies installed.${text_reset}"
echo -e " ${text_purple}NodeJs Version${text_reset}: $(node -v)"
echo -e " ${text_purple}Npm Version${text_reset}: $(npm -v)"
echo -e " ${text_purple}React Version${text_reset}: $(npm view react version)"
echo ""
echo -e "${text_blue}The npm-check-updates package has also been installed.${text_reset}"
echo -e "${text_blue}This allows for quick package updating per-project.${text_reset}"
echo -e "${text_blue}Run ${text_cyan}ncu${text_blue} to see what can upgrade.${text_reset}"
echo -e "${text_blue}Run ${text_cyan}ncu -u${text_blue} to commit upgrades to project package.json file.${text_reset}"
echo -e "${text_blue}Run ${text_cyan}ncu <package_name>${text_blue} to upgrade only a single package.${text_reset}"
echo ""
}
main
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment