-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Adds bootstrap.sh #1138
Merged
Merged
Adds bootstrap.sh #1138
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
#!/bin/sh | ||
RED='\033[0;31m' | ||
GREEN='\033[0;32m' | ||
NC='\033[0m' | ||
CHECK="${GREEN}\xE2\x9C\x93${NC}" | ||
confirm() { | ||
DEFAULT=$1; | ||
shift | ||
printf "$@" | ||
read -r YN | ||
if [ "$YN" = "" ] && [ "$DEFAULT" = 'N' ]; then | ||
exit 1 | ||
elif [ "$YN" != "" ] && [ "$YN" != "y" ] && [ "$YN" != "Y" ]; then | ||
echo 'Bye Bye!' | ||
exit 1 | ||
fi | ||
} | ||
|
||
genstring() { | ||
local l=$1 | ||
[ "$l" == "" ] && l=40 | ||
LC_ALL=C tr -dc A-Za-z0-9 < /dev/urandom | head -c ${l} | ||
} | ||
|
||
check_node() { | ||
node=`which node 2>&1` | ||
ret=$? | ||
|
||
if [ $ret -eq 0 ] && [ -x "$node" ]; then | ||
echo "${CHECK} node:" $(node -v) | ||
(exit 0) | ||
else | ||
echo "parse-server cannot be installed without Node.js." >&2 | ||
exit 1 | ||
fi | ||
} | ||
|
||
check_npm() { | ||
npm=`which npm 2>&1` | ||
ret=$? | ||
|
||
if [ $ret -eq 0 ] && [ -x "$npm" ]; then | ||
echo "${CHECK} npm:" $(npm -v) | ||
(exit 0) | ||
else | ||
echo "parse-server cannot be installed without npm." >&2 | ||
exit 1 | ||
fi | ||
} | ||
|
||
|
||
echo '' | ||
echo 'This will setup parse-server in the current directory' | ||
confirm 'Y' 'Do you want to continue? (Y/n): ' | ||
|
||
check_node | ||
check_npm | ||
|
||
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 '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 | ||
|
||
printf 'Enter your appId (leave empty to generate): ' | ||
read -r APP_ID | ||
|
||
[[ $APP_ID = '' ]] && APP_ID=$(genstring) && printf "\n$APP_ID\n\n" | ||
|
||
printf 'Enter your masterKey (leave empty to generate): ' | ||
read -r MASTER_KEY | ||
|
||
[[ $MASTER_KEY = '' ]] && MASTER_KEY=$(genstring) && printf "\n$MASTER_KEY\n\n" | ||
|
||
cat > ./config.json << EOF | ||
{ | ||
"appId": "$APP_ID", | ||
"masterKey": "$MASTER_KEY", | ||
"appName": "$APP_NAME", | ||
"cloud": "./cloud/main" | ||
} | ||
EOF | ||
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 | ||
{ | ||
"name": "$NPM_APP_NAME", | ||
"scripts": { | ||
"start": "parse-server ./config.json" | ||
}, | ||
"dependencies": { | ||
"parse-server": "^2.0.0" | ||
} | ||
} | ||
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 | ||
|
||
if [ -d "./public/" ]; then | ||
echo "${CHECK} public/ exists" | ||
else | ||
mkdir -p ./public | ||
echo "${CHECK} Created public/" | ||
fi | ||
|
||
echo "\n${CHECK} running npm install\n" | ||
|
||
npm install | ||
|
||
confirm 'Y' '\nDo you want to start the server now? (Y/n): ' | ||
|
||
echo "\n${CHECK} running npm start\n" | ||
|
||
npm start |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, can you have it echo a curl command.. something like
Here's an example curl command you can use to test the application:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, mongodb is not started, should I add mongodb-runner too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooo... can it ask for a connection string? with default localhost and a note that you should start it separately...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that would work too, I'll remove the auto start