Skip to content

Issue #1691 - Improves installation script #1692

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

Merged
merged 5 commits into from
Jun 28, 2019
Merged
Changes from 3 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
56 changes: 34 additions & 22 deletions initial_setup.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
#!/bin/bash

if [ -d "frog/node_modules" ]; then
echo "Please run git clean -fdx before running initial_setup.sh"
exit 0
fi
shopt -s dotglob

FROG="`pwd`"
YARN_VERSION='1.15.2'
if which yarn && [[ `yarn --version` == $YARN_VERSION ]]; then
echo 'Using pre-installed global Yarn'; YARN=yarn
else
if [ -f "$FROG/node_modules/.bin/yarn" ] && [[ `"$FROG/node_modules/.bin/yarn" --version` == $YARN_VERSION ]]; then
echo 'Using pre-installed local Yarn'; YARN="$FROG/node_modules/.bin/yarn"
else
echo 'Installing Yarn'; npm install yarn@$YARN_VERSION --no-package-lock && YARN="$FROG/node_modules/.bin/yarn"
fi
if ! PYTHON_VERSION=$(python --version);
then
echo "Cannot find Python, please install python 2 and try again"
exit 1
fi
echo "Yarn: $YARN"

"$YARN" install
rm -rf frog/node_modules
ln -s `pwd`/node_modules frog
ln -s frog/babel.config.js .
node linkFiles.js
if python -c 'import sys; print(sys.version_info[0] == 2)' > /dev/null == 'True';
then
YARN_VERSION='1.15.2'
if which yarn && [[ `yarn --version` == $YARN_VERSION ]]; then
echo 'Using pre-installed global Yarn'; YARN=yarn
else
if [ -f "./node_modules/.bin/yarn" ] && [[ `./node_modules/.bin/yarn --version` == $YARN_VERSION ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the script is not run from the correct directory?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go to the root repository

It is mentioned in the instructions for README.md
We could have error handling for that but seems a bit far-fetched idea to me.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, maybe add a quick comment in the file itself to keep this assumption close to the source code

echo 'Using pre-installed local Yarn'; YARN="./node_modules/.bin/yarn"
else
echo 'Installing Yarn'; npm install yarn@$YARN_VERSION --no-package-lock && YARN="./node_modules/.bin/yarn"
fi
fi
echo "Yarn: $YARN"

echo
echo -e "\xE2\x9C\xA8 Finished Initial Setup."
echo -e "\xF0\x9F\xA4\x93 Run ${LBLUE}npm start server ${NC}to begin hacking!"
if ! "$YARN" install; then
echo "Sorry, there seems to be something wrong, please correct the errors and try again"
echo "There was some error installing the required packages, please rectify the errors and try again"
exit 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be a bit more descriptive with our error message. Maybe something along the lines of "Unable to run yarn install successfully. You might not be connected to the internet, or there might be a problem with your FROG folder"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be displayed by yarn itself. This just informs the user that his action wasn't successful.

fi
rm -rf frog/node_modules
ln -s `pwd`/node_modules frog
ln -s frog/babel.config.js .
node linkFiles.js

exit 0
echo
echo -e "\xE2\x9C\xA8 Finished Initial Setup."
echo -e "\xF0\x9F\xA4\x93 Run ${LBLUE}npm start server ${NC}to begin hacking!"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We could move the emojis to constants to help with readability

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could introduce a flag to remove emoji.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear if there is benefit in doing so, this file will normally only be run once

exit 0
else
echo "Cannot find Python 2, Please install Python 2 and try again"
exit 1
fi