2023-01-09 21:55:47 -08:00
{{- if (ne .host.distro.family "windows") -}}
2022-11-26 19:27:29 -08:00
#!/usr/bin/env bash
2023-04-11 20:57:02 -07:00
# @file Node.js / Volta / ZX Install
# @brief Ensures Node.js, Volta, and ZX are installed prior to Chezmoi applying the dotfile state.
# @description
# This script ensures required dependencies are installed. These dependencies include:
#
# 1. **[Node.js](https://nodejs.org/en)**: JavaScript runtime engine which is installed to ensure any user with Homebrew configured can access Node.js
# 2. **[Volta](https://volta.sh/)**: Node.js version manager that provides the capability of automatically using `package.json` defined Node.js versions
# 3. **[ZX](https://github.com/google/zx)**: Used for the script that installs the software packages on any OS
#
# The Volta setup process will ensure that the user is configured to use the latest Node.js version, by default. It then
# also ensures the user's `~/.bashrc` and `~/.zshrc` profiles are setup for use with Volta.
2022-11-26 19:27:29 -08:00
2023-01-24 20:36:59 -08:00
{{ includeTemplate "universal/profile-before" }}
{{ includeTemplate "universal/logg-before" }}
Update dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_before_8-install-zx.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_before_5-install-homebrew.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_before_10_install-darwin-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoitemplates/universal/profile, dotfiles/.local/share/chezmoi/home/private_dot_config/shell/exports.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_99_bootstrap-z4h.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_80-bash-completions.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_60-cleanup.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_50-crontab.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_15_install-asdf-packages.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_10_install-aqua-packages.sh.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/archlinux/run_onchange_before_10_install-archlinux-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/centos/run_onchange_before_10-install-centos-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_after_10_configure-macos.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_after_20-ensure-zsh-macos.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/debian/run_onchange_before_10-install-debian-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/fedora/run_onchange_before_10-install-fedora-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/freebsd/run_onchange_before_11-install-freebsd-packages.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/opensuse/run_onchange_before_11-install-opensuse-software.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/ubuntu/run_onchange_before_10_install-ubuntu-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/private_dot_config/tabby/config.yaml.tmpl
Deleted dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_before_1-logging-deps
2022-11-26 19:55:43 -08:00
2023-07-17 10:41:49 -07:00
export VOLTA_HOME=" $ XDG_DATA_HOME /volta"
export PATH=" $ VOLTA_HOME /bin: $ PATH "
2022-11-27 18:11:28 -08:00
### Ensure node is installed
if ! command -v node > /dev/null; then
if command -v brew; then
logg 'Installing `node` via Homebrew'
2023-02-01 09:00:46 -08:00
brew install node || NODE_EXIT_CODE=$?
if [ -n " $ NODE_EXIT_CODE " ]; then
logg warn 'Calling `brew link --overwrite node` because the Node.js installation seems to be misconfigured'
brew link --overwrite node
fi
2022-11-27 18:11:28 -08:00
else
logg '`brew` is unavailable. Cannot use it to perform a system installation of node.'
fi
else
logg '`node` is available'
fi
2023-02-01 08:58:31 -08:00
### Ensure Volta is installed
2022-11-27 18:11:28 -08:00
if ! command -v volta > /dev/null; then
if command -v brew > /dev/null; then
logg 'Installing `volta` via `brew`'
brew install volta
2023-02-01 08:58:31 -08:00
else
logg warn '`brew` needs to be available to install Volta'
fi
else
if ! node --version > /dev/null; then
volta install node@latest
2022-11-27 18:11:28 -08:00
fi
2023-02-01 08:58:31 -08:00
fi
### Setup Volta
if command -v volta > /dev/null; then
2023-02-15 19:24:22 -08:00
### Handle scenario where VOLTA_HOME is not defined yet
2022-11-27 18:11:28 -08:00
if [ -z " $ VOLTA_HOME " ]; then
2023-02-01 08:58:31 -08:00
logg warn 'VOLTA_HOME is not defined'
2023-02-15 19:24:22 -08:00
logg info 'Running `volta setup`'
volta setup
2022-11-27 18:11:28 -08:00
fi
2023-02-15 19:24:22 -08:00
### Source .bashrc
2022-11-27 18:11:28 -08:00
if [ -f " $ HOME /.bashrc" ]; then
. " $ HOME /.bashrc"
else
logg warn 'Could not find `~/.bashrc` to source the results of `volta setup` from'
fi
2023-02-15 19:24:22 -08:00
### Set PATH and install latest Node.js version via Volta
2022-11-27 18:11:28 -08:00
export PATH=" $ VOLTA_HOME /bin: $ PATH "
logg 'Installing `node` via `volta`'
2022-12-24 02:46:21 -08:00
volta install node@latest
2022-11-27 18:11:28 -08:00
else
2023-02-01 08:58:31 -08:00
logg warn '`volta` needs to be installed'
2022-11-27 18:11:28 -08:00
fi
Update dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_before_8-install-zx.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_before_5-install-homebrew.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_before_10_install-darwin-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoitemplates/universal/profile, dotfiles/.local/share/chezmoi/home/private_dot_config/shell/exports.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_99_bootstrap-z4h.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_80-bash-completions.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_60-cleanup.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_50-crontab.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_15_install-asdf-packages.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_after_10_install-aqua-packages.sh.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/archlinux/run_onchange_before_10_install-archlinux-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/centos/run_onchange_before_10-install-centos-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_after_10_configure-macos.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/darwin/run_onchange_after_20-ensure-zsh-macos.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/debian/run_onchange_before_10-install-debian-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/fedora/run_onchange_before_10-install-fedora-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/freebsd/run_onchange_before_11-install-freebsd-packages.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/opensuse/run_onchange_before_11-install-opensuse-software.tmpl, dotfiles/.local/share/chezmoi/home/.chezmoiscripts/ubuntu/run_onchange_before_10_install-ubuntu-dependencies.tmpl, dotfiles/.local/share/chezmoi/home/private_dot_config/tabby/config.yaml.tmpl
Deleted dotfiles/.local/share/chezmoi/home/.chezmoiscripts/_universal/run_onchange_before_1-logging-deps
2022-11-26 19:55:43 -08:00
### Ensure zx is installed
2022-11-26 19:27:29 -08:00
if ! command -v zx > /dev/null; then
if command -v volta > /dev/null; then
logg 'Installing `zx` via `volta`'
volta install zx
else
2022-11-27 18:11:28 -08:00
logg '`volta` is missing'
2022-11-26 19:27:29 -08:00
fi
else
logg '`zx` is already installed'
fi
2023-01-24 20:36:59 -08:00
{{ end -}}