forked from github/homebrew-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
brew-bootstrap-nodenv-node
executable file
·80 lines (66 loc) · 1.76 KB
/
brew-bootstrap-nodenv-node
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# Installs Node and NPM.
set -e
if [ "$1" = "--debug" ]; then
shift
PRINT_DEBUG="1"
set -x
fi
warn() { echo "$@" >&2; }
abort() { EXPECTED_EXIT="1"; warn "$@"; exit 1; }
abort_for_sh() {
abort 'Error: add `eval "$(nodenv init -)"` to the end of your .bash_profile!'
}
abort_for_zsh() {
abort 'Error: add `eval "$(nodenv init -)"` to the end of your .zshrc!'
}
abort_for_fish() {
abort 'Error: add `status --is-interactive; and . (nodenv init -|psub)` to the end of your .config/fish/config.fish!'
}
abort_with_shell_setup_message() {
case $(basename ${SHELL:-bash}) in
sh|bash)
warn_sh
;;
zsh)
warn_zsh
;;
fish)
warn_fish
;;
# tcsh users are on their own
*)
abort 'Error: you must finish setting up nodenv in your shell; check `nodenv init` for instructions!'
esac
}
cleanup() {
set +e
if [ -n "$EXPECTED_EXIT" ]; then
return
fi
warn "Error: $(basename $0) failed!"
if [ -z "$PRINT_DEBUG" ]; then
warn "For debugging output run:"
warn " $0 --debug"
warn "If you're stuck: file an issue with debugging output at:"
warn " https://github.com/github/homebrew-bootstrap/issues/new"
fi
}
trap "cleanup" EXIT
BASE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
if ! which nodenv &>/dev/null; then
abort "Error: you need to 'brew install nodenv'!"
fi
if ! nodenv version-name &>/dev/null; then
NODE_REQUESTED="$(nodenv local)"
NODE_DEFINITION="$(node-build --definitions | grep "^$NODE_REQUESTED$" || true)"
if [ -z "$NODE_DEFINITION" ]; then
abort "Error: cannot find Node $NODE_DEFINITION definition!"
fi
nodenv install "$NODE_DEFINITION"
fi
if [ "$(nodenv exec node --version)" != "$(node --version)" ]; then
abort_with_shell_setup_message
fi
EXPECTED_EXIT="1"
exit 0