-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodejs.sh
executable file
·117 lines (86 loc) · 2.07 KB
/
nodejs.sh
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
cd "$(dirname "${BASH_SOURCE[0]}")" \
&& . "../utils.sh"
declare -r NVM_DIRECTORY="$HOME/.nvm"
declare -r NVM_GIT_REPO_URL="https://github.com/creationix/nvm.git"
on_start() {
print_node_header
print_info "This script will guide you through Installing NPM config, Global Packages..etc"
print_info "It will not install anything without your direct agreement!"
ask_for_confirmation "Do you want to proceed with installation?"
if ! answer_is_yes; then
exit 1
fi
}
install_node() {
print_in_purple "\n • Installing Node.js\n\n"
if [ `uname` == 'Darwin' ]; then
brew_install "Node" "node"
else
# Linux/Ubuntu
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs build-essential
fi
finish
}
install_nvm() {
# Install `nvm`
print_in_purple "\n • Installing NVM\n\n"
execute \
"git clone --quiet $NVM_GIT_REPO_URL $NVM_DIRECTORY" \
"nvm (install)"
}
update_nvm() {
print_in_purple "\n • Updating NVM\n\n"
execute \
"cd $NVM_DIRECTORY \
&& git fetch --quiet origin \
&& git checkout --quiet \$(git describe --abbrev=0 --tags) \
&& . $NVM_DIRECTORY/nvm.sh" \
"nvm (upgrade)"
}
configure_npm() {
# Ask required parameters
print_in_purple "\n • NPM Configurationt\n\n"
local name=""
local email=""
ask "What is your name: " && printf "\n"
name="$(get_answer)"
ask "What is your email: " && printf "\n"
email="$(get_answer)"
print_success "Author name set as: $name \n"
npm set init.author.name "$name"
print_success "\n Author email set as: $email \n"
npm set init.author.email "$email"
finish
}
install_global_packages() {
print_in_purple "\n • Installing Global Packages\n\n"
# Here you can add any global packages
NPM_PACKAGES=(
"netlify-cli"
"now"
"prettier"
"serve"
"svgo"
"npkill"
"nodemon"
"gatsby-cli"
)
yarn global add "${NPM_PACKAGES[@]}"
unset -v NPM_PACKAGES
finish
}
main() {
on_start
install_node
if [ ! -d "$NVM_DIRECTORY" ]; then
install_nvm
else
update_nvm
fi
configure_npm
install_global_packages
finish
}
main