-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-npm-global.sh
executable file
·58 lines (48 loc) · 1.14 KB
/
add-npm-global.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
#! /bin/bash
#
# Author: Nathan Baker <[email protected]>
#
# create hidden directory in user's home
# configure npm to use this directory
#
echo -e "\nChecking system\n"
echo -e -n "Checking for node\t\t\t\t"
if type -P "node" &>/dev/null; then
echo "Yes"
else
echo "No"
echo -e "\nPlease install nodejs\n"
exit 1
fi;
echo -e -n "Checking for npm\t\t\t\t"
if type -P "npm" &>/dev/null; then
echo "Yes"
else
echo "No"
echo -e "\nPlease install nodejs\n"
exit 1
fi;
echo -e -n "Checking for $HOME/.npm-global\t\t"
if [ -d "$HOME/.npm-global" ]; then
echo "Yes - skipping"
else
echo "Created"
mkdir "$HOME/.npm-global"
fi;
echo -e -n "Checking if PATH already has ~/.npm-global/bin\t"
if grep -F ".npm-global" ~/.bashrc; then
echo "Yes - skipping"
else
echo -e "Adding to PATH variable in ~/.profile"
echo -e "\nPATH=\$PATH:~/.npm-global/bin" >> ~/.bashrc
echo -e "Reloading ~/.profile"
source ~/.bashrc
fi;
echo -e "\nSetting npm prefix"
npm config set prefix '~/.npm-global'
echo
echo Done
echo Try installing a global package!
echo
echo Report issues with this script to https://github.com/pcnate/npm-configure/issues
echo