From d93bbcb4a50475e0c02edb49ed79e0a8f9a47a73 Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Sun, 23 Jun 2019 23:32:54 +1000 Subject: [PATCH 1/3] Allow to skip NVM installation in setup-local-env.sh --- bin/bootstrap-env.sh | 13 ++++ bin/install-node-nvm.sh | 88 ++++++++++++++-------------- docs/contributors/getting-started.md | 2 + 3 files changed, 60 insertions(+), 43 deletions(-) diff --git a/bin/bootstrap-env.sh b/bin/bootstrap-env.sh index 3055a49b5138ec..13232a317e27b9 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 +shift $((OPTIND - 1)) 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 ed84cb6e81376b..208ef576168b5e 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. From bdef06312fce890830a2b8da2828321059e6cfa2 Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Mon, 24 Jun 2019 23:45:19 +1000 Subject: [PATCH 2/3] Remove the bash command to shift processed flags in setup script. This was not needed, as each script is sourced explicitly in the current shell. So it will take its own arguments. This will also fix the Travis CI timeout. --- bin/bootstrap-env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/bootstrap-env.sh b/bin/bootstrap-env.sh index 13232a317e27b9..7170990338080b 100755 --- a/bin/bootstrap-env.sh +++ b/bin/bootstrap-env.sh @@ -22,4 +22,4 @@ while getopts ":-:" opt; do esac;; esac done -shift $((OPTIND - 1)) + From 081c7581609baa57403365a8c0cfcbe6b11804dc Mon Sep 17 00:00:00 2001 From: Udit Desai Date: Tue, 25 Jun 2019 14:33:19 +1000 Subject: [PATCH 3/3] Trigger Travis