diff --git a/bin/bootstrap-env.sh b/bin/bootstrap-env.sh index 3055a49b5138ec..7170990338080b 100755 --- a/bin/bootstrap-env.sh +++ b/bin/bootstrap-env.sh @@ -10,3 +10,16 @@ DOCKER_COMPOSE_FILE_OPTIONS="-f docker-compose.yml" if [ "$DOCKER_ENV" == "localwpdev" ]; then DOCKER_COMPOSE_FILE_OPTIONS="${DOCKER_COMPOSE_FILE_OPTIONS} -f docker-compose-localdev.yml" fi + +# Check for skip-nvm-setup flag. Used in install-node-nvm.sh +while getopts ":-:" opt; do + case "${opt}" in + -) + case "${OPTARG}" in + skip-nvm-setup) + SKIP_NVM_SETUP=true + ;; + esac;; + esac +done + diff --git a/bin/install-node-nvm.sh b/bin/install-node-nvm.sh index 9edc083833dc1d..8c0ac15395c69c 100755 --- a/bin/install-node-nvm.sh +++ b/bin/install-node-nvm.sh @@ -7,62 +7,64 @@ set -e # Include useful functions . "$(dirname "$0")/includes.sh" -# Load NVM -if [ -n "$NVM_DIR" ]; then - # The --no-use option ensures loading NVM doesn't switch the current version. - if [ -f "$NVM_DIR/nvm.sh" ]; then - . "$NVM_DIR/nvm.sh" --no-use - elif command_exists "brew" && [ -f "$(brew --prefix nvm)/nvm.sh" ]; then - # use homebrew if that's how nvm was installed - . "$(brew --prefix nvm)/nvm.sh" --no-use +if [ "$SKIP_NVM_SETUP" != "true" ]; then + # Load NVM + if [ -n "$NVM_DIR" ]; then + # The --no-use option ensures loading NVM doesn't switch the current version. + if [ -f "$NVM_DIR/nvm.sh" ]; then + . "$NVM_DIR/nvm.sh" --no-use + elif command_exists "brew" && [ -f "$(brew --prefix nvm)/nvm.sh" ]; then + # use homebrew if that's how nvm was installed + . "$(brew --prefix nvm)/nvm.sh" --no-use + fi fi -fi -# Change to the expected directory -cd "$(dirname "$0")/.." + # Change to the expected directory + cd "$(dirname "$0")/.." + + # Check if nvm is installed + if [ "$TRAVIS" != "true" ] && ! command_exists "nvm"; then + if ask "$(error_message "NVM isn't installed, would you like to download and install it automatically?")" Y; then + # The .bash_profile file needs to exist for NVM to install + if [ ! -e ~/.bash_profile ]; then + touch ~/.bash_profile + fi + + echo -en $(status_message "Installing NVM..." ) + download "https://raw.githubusercontent.com/creationix/nvm/$NVM_VERSION/install.sh" | bash >/dev/null 2>&1 + echo ' done!' -# Check if nvm is installed -if [ "$TRAVIS" != "true" ] && ! command_exists "nvm"; then - if ask "$(error_message "NVM isn't installed, would you like to download and install it automatically?")" Y; then - # The .bash_profile file needs to exist for NVM to install - if [ ! -e ~/.bash_profile ]; then - touch ~/.bash_profile + echo -e $(warning_message "NVM was updated, please run this command to reload it:" ) + echo -e $(warning_message "$(action_format ". \$HOME/.nvm/nvm.sh")" ) + echo -e $(warning_message "After that, re-run the setup script to continue." ) + else + echo -e $(error_message "") + echo -e $(error_message "Please install NVM manually, then re-run the setup script to continue.") + echo -e $(error_message "NVM installation instructions can be found here: $(action_format "https://github.com/creationix/nvm")") fi - echo -en $(status_message "Installing NVM..." ) + exit 1 + fi + + # Check if the current nvm version is up to date. + if [ "$TRAVIS" != "true" ] && [ $NVM_VERSION != "v$(nvm --version)" ]; then + echo -en $(status_message "Updating NVM..." ) download "https://raw.githubusercontent.com/creationix/nvm/$NVM_VERSION/install.sh" | bash >/dev/null 2>&1 echo ' done!' echo -e $(warning_message "NVM was updated, please run this command to reload it:" ) echo -e $(warning_message "$(action_format ". \$HOME/.nvm/nvm.sh")" ) echo -e $(warning_message "After that, re-run the setup script to continue." ) - else - echo -e $(error_message "") - echo -e $(error_message "Please install NVM manually, then re-run the setup script to continue.") - echo -e $(error_message "NVM installation instructions can be found here: $(action_format "https://github.com/creationix/nvm")") + exit 1 fi - exit 1 -fi - -# Check if the current nvm version is up to date. -if [ "$TRAVIS" != "true" ] && [ $NVM_VERSION != "v$(nvm --version)" ]; then - echo -en $(status_message "Updating NVM..." ) - download "https://raw.githubusercontent.com/creationix/nvm/$NVM_VERSION/install.sh" | bash >/dev/null 2>&1 - echo ' done!' - - echo -e $(warning_message "NVM was updated, please run this command to reload it:" ) - echo -e $(warning_message "$(action_format ". \$HOME/.nvm/nvm.sh")" ) - echo -e $(warning_message "After that, re-run the setup script to continue." ) - exit 1 -fi - -# Check if the current node version is up to date. -if [ "$TRAVIS" != "true" ] && [ "$(nvm current)" != "$(nvm version-remote --lts)" ]; then - echo -e $(warning_message "Node version does not match the latest long term support version. Please run this command to install and use it:" ) - echo -e $(warning_message "$(action_format "nvm install")" ) - echo -e $(warning_message "After that, re-run the setup script to continue." ) - exit 1 + # Check if the current node version is up to date. + if [ "$TRAVIS" != "true" ] && [ "$(nvm current)" != "$(nvm version-remote --lts)" ]; then + echo -e $(warning_message "Node version does not match the latest long term support version. Please run this command to install and use it:" ) + echo -e $(warning_message "$(action_format "nvm install")" ) + echo -e $(warning_message "After that, re-run the setup script to continue." ) + exit 1 + fi fi # Install/update packages diff --git a/docs/contributors/getting-started.md b/docs/contributors/getting-started.md index 9fbe2b10c182ee..27b6da31ec469b 100644 --- a/docs/contributors/getting-started.md +++ b/docs/contributors/getting-started.md @@ -13,6 +13,8 @@ nvm install nvm use ``` +**If you want to skip the setup and installation for NVM**, you can pass `--skip-nvm-setup` flag to the script, `./bin/setup-local-env.sh --skip-nvm-setup`. This can be needed, if you already have Node installed manually or via any other version manager like [nodenv](https://github.com/nodenv/nodenv/) or [asdf](https://github.com/asdf-vm/asdf-nodejs). + You also should have the latest release of [npm installed][npm]. npm is a separate project from Node.js and is updated frequently. If you've just installed Node.js which includes a version of npm within the installation you most likely will need also to update your npm installation. To update npm, type this into your terminal: `npm install npm@latest -g` To test the plugin, or to contribute to it, you can clone this repository and build the plugin files using Node. How you do that depends on whether you're developing locally or uploading the plugin to a remote host.