Skip to content

Wraps runsetup in function to prevent early execution with curl #1236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 69 additions & 65 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,53 +51,54 @@ check_npm() {
fi
}

function runsetup {

echo ''
echo 'This will setup parse-server in the current directory'
confirm 'Y' 'Do you want to continue? (Y/n): '
echo ''
echo 'This will setup parse-server in the current directory'
confirm 'Y' 'Do you want to continue? (Y/n): '

check_node
check_npm
check_node
check_npm

echo "Setting up parse-server in $PWD"
echo "Setting up parse-server in $PWD"

if [ -f './package.json' ]; then
echo "\n${RED}package.json exists${NC}"
confirm 'N' "Do you want to continue? \n${RED}this will erase your configuration${NC} (y/N): "
fi
if [ -f './package.json' ]; then
echo "\n${RED}package.json exists${NC}"
confirm 'N' "Do you want to continue? \n${RED}this will erase your configuration${NC} (y/N): "
fi


if [ -f 'config.json' ]; then
echo "\n${RED}config.json exists${NC}"
confirm 'N' "Do you want to continue? \n${RED}this will erase your configuration${NC} (y/N): "
fi
if [ -f 'config.json' ]; then
echo "\n${RED}config.json exists${NC}"
confirm 'N' "Do you want to continue? \n${RED}this will erase your configuration${NC} (y/N): "
fi

APP_NAME=''
i=0
while [ "$APP_NAME" = "" ]
do
[[ $i != 0 ]] && printf "${RED}An application name is required!${NC}\n"
printf 'Enter your Application Name: '
read -r APP_NAME
i=$(($i+1))
done
APP_NAME=''
i=0
while [ "$APP_NAME" = "" ]
do
[[ $i != 0 ]] && printf "${RED}An application name is required!${NC}\n"
printf 'Enter your Application Name: '
read -r APP_NAME
i=$(($i+1))
done

printf 'Enter your appId (leave empty to generate): '
read -r APP_ID
printf 'Enter your appId (leave empty to generate): '
read -r APP_ID

[[ $APP_ID = '' ]] && APP_ID=$(genstring) && printf "\n$APP_ID\n\n"
[[ $APP_ID = '' ]] && APP_ID=$(genstring) && printf "\n$APP_ID\n\n"

printf 'Enter your masterKey (leave empty to generate): '
read -r MASTER_KEY
printf 'Enter your masterKey (leave empty to generate): '
read -r MASTER_KEY

[[ $MASTER_KEY = '' ]] && MASTER_KEY=$(genstring) && printf "\n$MASTER_KEY\n\n"
[[ $MASTER_KEY = '' ]] && MASTER_KEY=$(genstring) && printf "\n$MASTER_KEY\n\n"

printf "Enter your mongodbURI (%s): " $DEFAULT_MONGODB_URI
read -r MONGODB_URI
printf "Enter your mongodbURI (%s): " $DEFAULT_MONGODB_URI
read -r MONGODB_URI

[[ $MONGODB_URI = '' ]] && MONGODB_URI="$DEFAULT_MONGODB_URI"
[[ $MONGODB_URI = '' ]] && MONGODB_URI="$DEFAULT_MONGODB_URI"

cat > ./config.json << EOF
cat > ./config.json << EOF
{
"appId": "$APP_ID",
"masterKey": "$MASTER_KEY",
Expand All @@ -106,11 +107,11 @@ cat > ./config.json << EOF
"mongodbURI": "$MONGODB_URI"
}
EOF
echo "${CHECK} Created config.json"
echo "${CHECK} Created config.json"

# Make a proper npm app name
NPM_APP_NAME=$(echo "$APP_NAME" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
cat > ./package.json << EOF
# Make a proper npm app name
NPM_APP_NAME=$(echo "$APP_NAME" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
cat > ./package.json << EOF
{
"name": "$NPM_APP_NAME",
"scripts": {
Expand All @@ -121,43 +122,46 @@ cat > ./package.json << EOF
}
}
EOF
echo "${CHECK} Created package.json"

if [ -d "./cloud/" ]; then
echo "${CHECK} cloud/ exists"
else
mkdir -p ./cloud
echo "${CHECK} Created cloud/"
fi

if [ -e "./cloud/main.js" ]; then
echo "${CHECK} cloud/main.js exists"
else
echo "${CHECK} Created cloud/main.js"
cat > ./cloud/main.js << EOF
echo "${CHECK} Created package.json"

if [ -d "./cloud/" ]; then
echo "${CHECK} cloud/ exists"
else
mkdir -p ./cloud
echo "${CHECK} Created cloud/"
fi

if [ -e "./cloud/main.js" ]; then
echo "${CHECK} cloud/main.js exists"
else
echo "${CHECK} Created cloud/main.js"
cat > ./cloud/main.js << EOF
// Cloud Code entry point

EOF
fi
fi

if [ -d "./public/" ]; then
echo "${CHECK} public/ exists"
else
mkdir -p ./public
echo "${CHECK} Created public/"
fi
if [ -d "./public/" ]; then
echo "${CHECK} public/ exists"
else
mkdir -p ./public
echo "${CHECK} Created public/"
fi

echo "\n${CHECK} running npm install\n"
echo "\n${CHECK} running npm install\n"

npm install
npm install

CURL_CMD=$(cat << EOF
CURL_CMD=$(cat << EOF
curl -X POST -H 'X-Parse-Application-Id: ${APP_ID}' \\
-H 'Content-Type: application/json' \\
-d '{"foo":"bar"}' http://localhost:1337/parse/classes/TestObject
EOF)

echo "\n${CHECK} Happy Parsing!\n\n"
echo "${CHECK} Make sure you have ${BOLD}mongo${NC} listening on ${BOLD}${MONGODB_URI}${NC}"
echo "${CHECK} start parse-server by running ${BOLD}npm start${NC}"
echo "${CHECK} Test your setup with:\n\n${CURL_CMD}\n"
echo "\n${CHECK} Happy Parsing!\n\n"
echo "${CHECK} Make sure you have ${BOLD}mongo${NC} listening on ${BOLD}${MONGODB_URI}${NC}"
echo "${CHECK} start parse-server by running ${BOLD}npm start${NC}"
echo "${CHECK} Test your setup with:\n\n${CURL_CMD}\n"
}

runsetup