# Install node #
##################
+common_node_home="${HOME}/.local/opt/node"
new_node_home="${HOME}/.local/opt/node-v${WEBI_VERSION}"
new_node="${HOME}/.local/opt/node-v${WEBI_VERSION}/bin/node"
+update_node_home() {
+ rm -rf "$common_node_home"
+ ln -s "$new_node_home" "$common_node_home"
+
+ # TODO get better output from pathman / output the path to add as return to webi bootstrap
+ webi_path_add "$common_node_home/bin"
+}
+
+if [ -x "$new_node" ]; then
+ update_node_home
+ echo "switched to node v${WEBI_VERSION} at $new_node_home"
+ exit 0
+fi
+
# Test for existing version
set +e
cur_node="$(command -v node)"
set -e
-if [ -e "$new_node_home/bin/node" ]; then
- # node of some version is already installed
- if [ "v${WEBI_VERSION}" == "$("$new_node_home/bin/node" -v 2>/dev/null)" ]; then
- echo node v${WEBI_VERSION} already installed at $new_node_home
- exit 0
+cur_node_version=""
+if [ -n "$cur_node" ]; then
+ cur_node_version="$("$cur_node" -v 2>/dev/null)"
+ if [ "$cur_node_version" == "v${WEBI_VERSION}" ]; then
+ echo "node v${WEBI_VERSION} already installed at $cur_node"
+ exit 0
+ else
+ if [ "$cur_node" != "$common_node_home/bin/node" ]; then
+ echo "WARN: possible conflict between node v${WEBI_VERSION} and v${cur_node_version} at ${cur_node}"
fi
+ if [ -x "$new_node_home/bin/node" ]; then
+ update_node_home
+ echo "switched to node${WEBI_VERSION} at $new_node_home"
+ exit 0
+ fi
+ fi
fi
-if [ -n "$cur_node" ] && [ "$cur_node" != "$new_node" ]; then
- echo "WARN: possible conflict with node v$WEBI_VERSION at $cur_node"
-fi
+
# Note: this file is `source`d by the true installer and hence will have the webi functions
# Update PATH #
###################
-# TODO get better output from pathman / output the path to add as return to webi bootstrap
-webi_path_add "$new_node_home/bin"
+update_node_home
echo "Installed 'node' and 'npm'"
echo ""