From 6990b9d2c6caf5583b461186706fe24e3cd3f1bf Mon Sep 17 00:00:00 2001 From: Brooke Kuhlmann Date: Mon, 15 Mar 2021 20:13:48 -0600 Subject: [PATCH] Added Node packages script Necessary to provide a single source of truth for installing Node dependencies. This used to be managed by the Yarn Setup project but that project is being deprecated in favor of this project. --- bin/install_node_packages | 17 +++++++++++++++++ bin/run | 1 + lib/options.sh | 4 ++++ lib/utilities.sh | 10 ++++++++++ lib/verifiers.sh | 17 +++++++++++++++++ 5 files changed, 49 insertions(+) create mode 100755 bin/install_node_packages diff --git a/bin/install_node_packages b/bin/install_node_packages new file mode 100755 index 0000000..3c30a96 --- /dev/null +++ b/bin/install_node_packages @@ -0,0 +1,17 @@ +#! /usr/bin/env bash + +# Installs Node packages. + +set -o nounset +set -o errexit +set -o pipefail +IFS=$'\n\t' + +SCRIPT_PATH="$MAC_OS_CONFIG_PATH/bin/install_node_packages" + +if [[ -x "$SCRIPT_PATH" ]]; then + check_yarn_install + "$SCRIPT_PATH" +else + printf "WARNING: Node packages install script does not exist or is not executable.\n" +fi diff --git a/bin/run b/bin/run index 074a14a..0542d78 100755 --- a/bin/run +++ b/bin/run @@ -39,6 +39,7 @@ while true; do printf " m: Install Mac App Store software.\n" printf " a: Install application software.\n" printf " x: Install application software extensions.\n" + printf " np: Install Node packages.\n" printf " rg: Install Ruby gems.\n" printf " rc: Install Rust crates.\n" printf " d: Apply default settings.\n" diff --git a/lib/options.sh b/lib/options.sh index 37062ca..52182ff 100644 --- a/lib/options.sh +++ b/lib/options.sh @@ -22,6 +22,8 @@ process_option() { bin/install_applications;; 'x') bin/install_extensions;; + 'np') + bin/install_node_packages;; 'rg') bin/install_ruby_gems;; 'rc') @@ -39,6 +41,7 @@ process_option() { bin/install_app_store bin/install_applications bin/install_extensions + bin/install_node_packages bin/install_ruby_gems bin/install_rust_crates bin/apply_default_settings @@ -53,6 +56,7 @@ process_option() { verify_app_store_applications verify_applications verify_extensions + verify_node_packages verify_ruby_gems verify_rust_crates;; 'C') diff --git a/lib/utilities.sh b/lib/utilities.sh index bbfbae3..dba1949 100644 --- a/lib/utilities.sh +++ b/lib/utilities.sh @@ -101,6 +101,16 @@ get_install_root() { } export -f get_install_root +# Checks Yarn has been installed and exits if otherwise. +# Parameters: None. +check_yarn_install() { + if ! command -v yarn > /dev/null; then + printf "%s\n" "ERROR: Yarn can't be found. Please ensure Homebrew and Yarn have been installed." + exit 1 + fi +} +export -f check_yarn_install + # Checks Mac App Store (mas) CLI has been installed and exits if otherwise. # Parameters: None. check_mas_install() { diff --git a/lib/verifiers.sh b/lib/verifiers.sh index 687ac3a..71f42c6 100644 --- a/lib/verifiers.sh +++ b/lib/verifiers.sh @@ -127,6 +127,23 @@ verify_path() { } export -f verify_path +# Checks for missing Node packages. +verify_node_packages() { + local packages=$(yarn global list --json | grep '"type":"info"') + + printf "\nChecking Node packages...\n" + + while read line; do + if [[ "$line" == "yarn global add"* ]]; then + local package=$(printf "$line" | awk '{print $4}') + verify_listed_application "$package" "${packages[*]}" + fi + done < "$MAC_OS_CONFIG_PATH/bin/install_node_packages" + + printf "Node packages check complete.\n" +} +export -f verify_node_packages + # Checks for missing Ruby gems. verify_ruby_gems() { local gems="$(gem list --no-versions)"