Skip to content

Commit b7a723f

Browse files
committed
Adds bootstrap.sh
1 parent cc6c3f4 commit b7a723f

File tree

1 file changed

+149
-0
lines changed

1 file changed

+149
-0
lines changed

bootstrap.sh

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/bin/sh
2+
RED='\033[0;31m'
3+
GREEN='\033[0;32m'
4+
NC='\033[0m'
5+
CHECK="${GREEN}\xE2\x9C\x93${NC}"
6+
confirm() {
7+
DEFAULT=$1;
8+
shift
9+
printf "$@"
10+
read -r YN
11+
if [ "$YN" = "" ] && [ "$DEFAULT" = 'N' ]; then
12+
exit 1
13+
elif [ "$YN" != "" ] && [ "$YN" != "y" ] && [ "$YN" != "Y" ]; then
14+
echo 'Bye Bye!'
15+
exit 1
16+
fi
17+
}
18+
19+
genstring() {
20+
local l=$1
21+
[ "$l" == "" ] && l=40
22+
LC_ALL=C tr -dc A-Za-z0-9 < /dev/urandom | head -c ${l}
23+
}
24+
25+
check_node() {
26+
node=`which node 2>&1`
27+
ret=$?
28+
29+
if [ $ret -eq 0 ] && [ -x "$node" ]; then
30+
echo "${CHECK} node:" $(node -v)
31+
(exit 0)
32+
else
33+
echo "parse-server cannot be installed without Node.js." >&2
34+
exit 1
35+
fi
36+
}
37+
38+
check_npm() {
39+
npm=`which npm 2>&1`
40+
ret=$?
41+
42+
if [ $ret -eq 0 ] && [ -x "$npm" ]; then
43+
echo "${CHECK} npm:" $(npm -v)
44+
(exit 0)
45+
else
46+
echo "parse-server cannot be installed without npm." >&2
47+
exit 1
48+
fi
49+
}
50+
51+
52+
echo ''
53+
echo 'This will setup parse-server in the current directory'
54+
confirm 'Y' 'Do you want to continue? (Y/n): '
55+
56+
check_node
57+
check_npm
58+
59+
echo "Setting up parse-server in $PWD"
60+
61+
if [ -f './package.json' ]; then
62+
echo "\n${RED}package.json exists${NC}"
63+
confirm 'N' "Do you want to continue? \n${RED}this will erase your configuration${NC} (y/N): "
64+
fi
65+
66+
67+
if [ -f 'config.json' ]; then
68+
echo "\n${RED}config.json exists${NC}"
69+
confirm 'N' "Do you want to continue? \n${RED}this will erase your configuration${NC} (y/N): "
70+
fi
71+
72+
APP_NAME=''
73+
i=0
74+
while [ "$APP_NAME" = "" ]
75+
do
76+
[[ $i != 0 ]] && printf "${RED}An application name is required!${NC}\n"
77+
printf 'Enter your Application Name: '
78+
read -r APP_NAME
79+
i=$(($i+1))
80+
done
81+
82+
printf 'Enter your appId (leave empty to generate): '
83+
read -r APP_ID
84+
85+
[[ $APP_ID = '' ]] && APP_ID=$(genstring) && printf "\n$APP_ID\n\n"
86+
87+
printf 'Enter your masterKey (leave empty to generate): '
88+
read -r MASTER_KEY
89+
90+
[[ $MASTER_KEY = '' ]] && MASTER_KEY=$(genstring) && printf "\n$MASTER_KEY\n\n"
91+
92+
cat > ./config.json << EOF
93+
{
94+
"appId": "$APP_ID",
95+
"masterKey": "$MASTER_KEY",
96+
"appName": "$APP_NAME",
97+
"cloud": "./cloud/main"
98+
}
99+
EOF
100+
echo "${CHECK} Created config.json"
101+
102+
# Make a proper npm app name
103+
NPM_APP_NAME=$(echo "$APP_NAME" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
104+
cat > ./package.json << EOF
105+
{
106+
"name": "$NPM_APP_NAME",
107+
"scripts": {
108+
"start": "parse-server ./config.json"
109+
},
110+
"dependencies": {
111+
"parse-server": "^2.0.0"
112+
}
113+
}
114+
EOF
115+
echo "${CHECK} Created package.json"
116+
117+
if [ -d "./cloud/" ]; then
118+
echo "${CHECK} cloud/ exists"
119+
else
120+
mkdir -p ./cloud
121+
echo "${CHECK} Created cloud/"
122+
fi
123+
124+
if [ -e "./cloud/main.js" ]; then
125+
echo "${CHECK} cloud/main.js exists"
126+
else
127+
echo "${CHECK} Created cloud/main.js"
128+
cat > ./cloud/main.js << EOF
129+
// Cloud Code entry point
130+
131+
EOF
132+
fi
133+
134+
if [ -d "./public/" ]; then
135+
echo "${CHECK} public/ exists"
136+
else
137+
mkdir -p ./public
138+
echo "${CHECK} Created public/"
139+
fi
140+
141+
echo "\n${CHECK} running npm install\n"
142+
143+
npm install
144+
145+
confirm 'Y' '\nDo you want to start the server now? (Y/n): '
146+
147+
echo "\n${CHECK} running npm start\n"
148+
149+
npm start

0 commit comments

Comments
 (0)